// topnavi
var naviTeaserRelation = "";
function executeNaviTeaserHide(){
  $('#naviTeaser').slideUp('fast');
  naviTeaserRelation = "";
}

// Bildrefektion bei Teasern
$(function($) {
  $("img.reflect").reflect({
    height:0.17,
    opacity:0.33
  });
});

// Teaser-Karusell 
$(function(){
  var carouselLength = $('div.carousel .carousel_item').length;
  if (carouselLength > 4) {
    $("div.carousel").carousel({
      dispItems: 4,
      animSpeed: "slow"
    });
  }
});


$(document).ready(function(){
	
  var homepageImageFlow = new ImageFlow();
  homepageImageFlow.init({
    ImageFlowID: 'ImageFlow',
    aspectRatio: 4.1,
    buttons: true,
    imageFocusMax: 8,
    opacity: true,
    opacityArray: [10, 8, 7, 6, 5, 4],
    percentLandscape: 70,
    reflections: false,
    scrollbarP: 0.9,
    startID: Math.round(jQuery('#ImageFlow img').length / 2),
    startAnimation: true,
    xStep: 60
  });
        
  //tooltip bei bildern imageFlow
  $('#ImageFlow img').cluetip({
    splitTitle: '|',
    width: 160,
    dropShadowSteps: 3,
    positionBy: 'mouse',
    topOffset: 5,
    leftOffset: 5
  });
			   
								
  // metanavi
  $("ul#metatop li:last").css('border-style','none');
  $("#metabottom ul li:last").css('border-style','none')
	
  // teaser events
  $("ul.list li:first").css('border-top-style','none');
  $("ul.list li:last").css('border-bottom-style','none');
	
		
  // fahert sprachen aus/ein
  $('ul#metatop li.lang').mouseenter(function () {
    if ($("ul#lang").is(":hidden")) {
      $("ul#lang").slideDown("normal");
    }
  });
  $('ul#metatop li.lang').mouseleave(function () {
    if ($("ul#lang").is(":visible")) {
      $("ul#lang").slideUp("fast");
    }
  });
  
  
  //zielgruppenzugang
  $("#slider a.close, #slider .panel p.open, #slider .panel.open").live('click', function(){
    $("#slider a.opener").hide();
    $("#slider div.content_wrapper").fadeOut('slow');
    $("#slider .panel a").show();
    $("#slider .party_content img").animate({
      left:"0"
    }, 1000 );
  });
  $("#slider a.opener").click(function(){
    $("#slider a.opener").hide();
    $("#slider .panel a").hide();
  });
  $("#slider .panel a, #slider .panel p.closed, #slider .panel.closed").live('click', function(){
    $("#slider div.content_wrapper").fadeIn('slow');
  });
	
  // container 1
  if (!$('#first_party').hasClass('external')) {
    $("#first_party p a, #first_party .panel p.closed, #first_party .panel.closed").live('click', function(){
      $('#first_party .panel p.closed, #first_party .panel.closed').removeClass('closed').addClass('open');
      $("#first_party").animate({
        width:"761px"
      }, 1000 );
      $("#first_party p a").hide();
      $("#sec_party").animate({
        width:"98px"
      }, 1000 );
      $("#sec_party .panel").hide();
      $("#sec_party a.opener").show();
      $("#sec_party a.opener").removeClass('right');
      $("#sec_party a.opener").addClass('left');
      $("#sec_party img").animate({
        left:"-180px"
      }, 1000 );
      $("#third_party").animate({
        width:"98px"
      }, 1000 );
      $("#third_party .panel").hide();
      $("#third_party a.opener").show();
      $("#third_party img").animate({
        left:"-130px"
      }, 1000 );
    });
    $("#first_party a.close, #first_party .panel p.open, #first_party .panel.open").live('click', function(){
      $('#first_party .panel p.open, #first_party .panel.open').removeClass('open').addClass('closed');
      $("#first_party").animate({
        width:"319px"
      }, 1000 );
      $("#first_party p a").show();
      $("#sec_party").animate({
        width:"319px"
      }, 1000 );
      $("#sec_party .panel").show();
      $("#third_party").animate({
        width:"319px"
      }, 1000 );
      $("#third_party .panel").show();
    });
    $("#first_party a.opener").click(function(){
      $("#first_party").animate({
        width:"761px"
      }, 1000 );
      $("#first_party .panel").show();
      $("#first_party .party_content img").animate({
        left:"0"
      }, 1000 );
      $("#first_party div.content_wrapper").fadeIn('slow');
      $("#sec_party").animate({
        width:"98px"
      }, 1000 );
      $("#sec_party .panel").hide();
      $("#sec_party a.opener").show();
      $("#sec_party a.opener").removeClass('right');
      $("#sec_party a.opener").addClass('left');
      $("#sec_party img").animate({
        left:"-180px"
      }, 1000 );
      $("#sec_party div.content_wrapper").fadeOut('fast');
      $("#third_party").animate({
        width:"98px"
      }, 1000 );
      $("#third_party .panel").hide();
      $("#third_party a.opener").show();
      $("#third_party img").animate({
        left:"-130px"
      }, 1000 );
      $("#third_party div.content_wrapper").fadeOut('fast');
    });
  } else {
    $("#first_party .panel").click(function(){
      window.location = $('#first_party .panel a').attr('href');
    });
  }
	
  // container 2
  if (!$('#sec_party').hasClass('external')) {
    $("#sec_party p a, #sec_party .panel p.closed, #sec_party .panel.closed").live('click', function(){
      $('#sec_party .panel p.closed, #sec_party .panel.closed').removeClass('closed').addClass('open');
      $("#first_party").animate({
        width:"98px"
      }, 1000 );
      $("#first_party .panel").hide();
      $("#first_party a.opener").show();
      $("#first_party img").animate({
        left:"-120px"
      }, 1000 );
      $("#sec_party").animate({
        width:"761px"
      }, 1000 );
      $("#sec_party p a").hide();
      $("#third_party").animate({
        width:"98px"
      }, 1000 );
      $("#third_party .panel").hide();
      $("#third_party a.opener").show();
      $("#third_party img").animate({
        left:"-130px"
      }, 1000 );
    });
    $("#sec_party a.close, #sec_party .panel p.open, #sec_party .panel.open").live('click', function(){
      $('#sec_party .panel p.open, #sec_party .panel.open').removeClass('open').addClass('closed');
      $("#first_party").animate({
        width:"319px"
      }, 1000 );
      $("#first_party .panel").show();
      $("#sec_party").animate({
        width:"319px"
      }, 1000 );
      $("#sec_party p a").show();
      $("#third_party").animate({
        width:"319px"
      }, 1000 );
      $("#third_party .panel").show();
    });
    $("#sec_party a.opener").click(function(){
      $("#first_party").animate({
        width:"98px"
      }, 1000 );
      $("#first_party .panel").hide();
      $("#first_party a.opener").show();
      $("#first_party img").animate({
        left:"-120px"
      }, 1000 );
      $("#first_party div.content_wrapper").fadeOut('fast');
      $("#sec_party").animate({
        width:"761px"
      }, 1000 );
      $("#sec_party .panel").show();
      $("#sec_party .party_content img").animate({
        left:"0"
      }, 1000 );
      $("#sec_party div.content_wrapper").fadeIn('slow');
      $("#third_party").animate({
        width:"98px"
      }, 1000 );
      $("#third_party .panel").hide();
      $("#third_party a.opener").show();
      $("#third_party img").animate({
        left:"-130px"
      }, 1000 );
      $("#third_party div.content_wrapper").fadeOut('fast');
    });
  } else {
    $("#sec_party .panel").click(function(){
      window.location = $('#sec_party .panel a').attr('href');
    });
  }
	
  // container 3
  if (!$('#third_party').hasClass('external')) {
    $("#third_party p a, #third_party .panel p.closed, #third_party .panel.closed").live('click', function(){
      $('#third_party .panel p.closed, #third_party .panel.closed').removeClass('closed').addClass('open');
      $("#first_party").animate({
        width:"98px"
      }, 1000 );
      $("#first_party .panel").hide();
      $("#first_party a.opener").show();
      $("#first_party img").animate({
        left:"-120px"
      }, 1000 );
      $("#sec_party").animate({
        width:"98px"
      }, 1000 );
      $("#sec_party .panel").hide();
      $("#sec_party a.opener").show();
      $("#sec_party a.opener").removeClass('left');
      $("#sec_party a.opener").addClass('right');
      $("#sec_party img").animate({
        left:"-180px"
      }, 1000 );
      $("#third_party").animate({
        width:"761px"
      }, 1000 );
      $("#third_party p a").hide();
    });
    $("#third_party a.close, #third_party .panel p.open, #third_party .panel.open").live('click', function(){
      $('#third_party .panel p.open, #third_party .panel.open').removeClass('open').addClass('closed');
      $("#first_party").animate({
        width:"319px"
      }, 1000 );
      $("#first_party .panel").show();
      $("#sec_party").animate({
        width:"319px"
      }, 1000 );
      $("#sec_party .panel").show();
      $("#third_party").animate({
        width:"319px"
      }, 1000 );
      $("#sec_party p a").show();
    });
    $("#third_party a.opener").click(function(){
      $("#first_party").animate({
        width:"98px"
      }, 1000 );
      $("#first_party .panel").hide();
      $("#first_party a.opener").show();
      $("#first_party img").animate({
        left:"-120px"
      }, 1000 );
      $("#first_party div.content_wrapper").fadeOut('fast');
      $("#sec_party").animate({
        width:"98px"
      }, 1000 );
      $("#sec_party .panel").hide();
      $("#sec_party a.opener").show();
      $("#sec_party a.opener").removeClass('left');
      $("#sec_party a.opener").addClass('right');
      $("#sec_party img").animate({
        left:"-180px"
      }, 1000 );
      $("#sec_party div.content_wrapper").fadeOut('fast');
      $("#third_party").animate({
        width:"761px"
      }, 1000 );
      $("#third_party .panel").show();
      $("#third_party .party_content img").animate({
        left:"0"
      }, 1000 );
      $("#third_party div.content_wrapper").fadeIn('slow');
    });
  } else {
    $("#third_party .panel").click(function(){
      window.location = $('#third_party .panel a').attr('href');
    });
  }
	

	
  /* listeneintraege bei zielgruppen ausfahren */
  $("div.list_item").mouseenter(function(){
    $(this).parent().children('div:first').removeClass('expand').addClass('default');
    $(this).removeClass("default").addClass("expand");
  });
  $("div.list_item").mouseleave(function(){
    $(this).removeClass("expand").addClass("default");
  });
  $("div.content_list").mouseleave(function(){
    $("div:first",this).removeClass("default").addClass("expand");
  });
	

  $("#main_teaser .teaser:first").css('margin-right','0px');
	
	
  // service-teaser
  $("#service div.service-teaser:last").css('margin-right','0px')
	
	
  //$("#service div.service-teaser .low").toggle(
  //  function () {
  //    $(this).parent().children('div:last').animate(  { top:"152px" }, 500  );
  //  },
  // function () {
  //    $(this).parent().children('div:last').animate(  { top:"335px" }, 500  );
  //  }
  //);
	
	
  //$("#service div.service-teaser .high").toggle(
  // function () {
  //    $(this).parent().children('div:last').animate(  { top:"0" }, 500  );
  //  },
  //  function () {
  //    $(this).parent().children('div:last').animate(  { top:"335px" }, 500  );
  //  }
  //);

  var openedTeasers = new Object();
  openedTeasers['facebook'] = 0;
  openedTeasers['twitter'] = 0;
  openedTeasers['flickr'] = 0;
  openedTeasers['news'] = 0;
  openedTeasers['youtube'] = 0;

  // oeffnet service-teaser
  $("#service div.service-teaser .low").click(function() {
    var that = $(this).parent().children('div:last');
    var className = $(this).children('h3').attr('class');

    openServiceTeaser(that, className, '192px');
  });
  $("#service div.service-teaser .high").click(function() {
    var that = $(this).parent().children('div:last');
    var className = $(this).children('h3').attr('class');

    openServiceTeaser(that, className, '0');
  });

  // schliesst service-teaser bei click auf schließen button
  $("#service div.service-teaser div.content a.close").click(function() {
    var that = $(this).parent();
    var className = that.attr('id');

    closeServiceTeaser(that, className);
  });

  /**
   *Opens the service teaser
 * @param {jQuery} container the container to open
 * @param {String} className the name of the teaser (facebook, twitter, ...)
 * @param {String} top distance from the top ('0' for high teasers, '192px' for low)
   */
  openServiceTeaser = function (container, className, top) {
    container.animate({
      top: top
    }, 500);
    if (className == 'facebook' || className == 'twitter' || className == 'news') {
      $('#tagcloud, #footermap').fadeOut();
      if(className == 'news') $('#partner').fadeOut();
      
      if(className == 'facebook') {
        container.find('iframe').attr('src',facebookUrl);
      }
    }
    openedTeasers[className] = 1;
    ET_Event.eventStart('ServiceTeaser', className, 'open', '');
  }

  /**
 * Closes the service teaser
 * @param {jQuery} container the container to close
 * @param {String} className the name of the teaser (facebook, twitter, ...)
 */
  closeServiceTeaser = function (container, className) {
    container.animate({
      top: '435px'
    }, 500);
    openedTeasers[className] = 0;

    if (className == 'facebook' || className == 'twitter' || className == 'news') {
      if (openedTeasers['facebook'] == 0 && openedTeasers['twitter'] == 0 && openedTeasers['news'] == 0) {
        $('#tagcloud, #footermap').fadeIn();
        if(className == 'news') $('#partner').fadeIn();
      }
    }
    ET_Event.eventStart('ServiceTeaser', className, 'close', '');
  }

  // bildergalerie
  $("a.html").colorbox({
    transition:"elastic",
    width:"560px",
    height:"605px"
  });
});
