jQuery(document).ready(function() {
 	$("#back-top").hide();

	$(function () {
		$(window).scroll(function () {
			if ($(this).scrollTop() > 500) {
				$('#back-top').fadeIn();
			} else {
				$('#back-top').fadeOut();
			}
		});
		
		$('#back-top a').click(function () {
			$('body,html').animate({
				scrollTop: 0
			}, 800);
			return false;
		});

  });
	
var isIE = navigator.userAgent.toLowerCase().indexOf('msie') != -1;
if(isIE == true){
$( "h1.c_title_index").FontEffect(
										{ shadow:true, 
										  shadowColor:"#666666", 
										  shadowOffsetTop:1, 
										  shadowOffsetLeft:1,
										  shadowOpacity:0.09,
										  shadowBlur:2
										});

$( "h1.top_slogan").FontEffect(
										{ shadow:true, 
										  shadowColor:"#666666", 
										  shadowOffsetTop:1, 
										  shadowOffsetLeft:1,
										  shadowOpacity:0.09,
										  shadowBlur:2
										});
}

$(" table.ct_table2 tr:even td").addClass("odd");

if($.browser.msie && $.browser.version=="6.0") {var ie6 = true;}

$(".si_area_container5 div.si_area_box").mouseenter(function() {
	if(ie6) $(this).prev().css({'display':'block'});
	$(this).addClass("active").stop(true).animate({
    right:'212px'
  });
});

$(".si_area_container5 div.si_area_box").mouseleave(function() {
	$(this).stop(true).animate({
    right:'13px'
  }, 700, function() {
		$(this).removeClass("active");
		if(ie6) $(this).prev().css({'display':'none'});
	});	
});

$("li.sn_item_1").each(function() {
	if($(this).find("span").text() == "Übersicht") {
  $(this).addClass("sn_backlink");
  }
	if($(this).find("ul").length) {
	  $(this).addClass("has_subitems");
	}
});

function fitElements() {
	var viewportWidth = $(window).width();

	$("ul.sn_main_nav li.sn_item_0").mouseenter(
		function() {
		$(this).find("css3-container:first").css({'top':'49px'});
		 if(($(this).attr("id") == "sn_item_5") || ($(this).attr("id") == "sn_item_6")) {
						var offset = $(this).offset();
						var diff=viewportWidth - offset.left;
						if(diff < 250){
							$(this).find("css3-container:first").css({'left':'-150px'});
							$(this).find("ul.sn_level_0").css({'left':'-150px'});
						}
						else {
							$(this).find("css3-container:first").css({'left':'0px'});
							$(this).find("ul.sn_level_0").css({'left':'0px'});  	
						}
			 }
			$(this).find("ul:first").show();
		}
	);
	

	$("ul.sn_main_nav li.sn_item_0").mouseleave(
		function() {
			$(this).find("ul:first").hide();
		}
	);

	$("ul.sn_main_nav li.sn_item_1").mouseenter(
		function() {
		if($(this).attr("class") == "sn_item_1 has_subitems") {
			 $(this).find("css3-container:first").css({'top':'-15px','left':'243px'});
			 if(($(this).parents("li.sn_item_0").attr("id") == "sn_item_5") || ($(this).parents("li.sn_item_0").attr("id") == "sn_item_6")) {
							var offset = $(this).offset();
							var diff=viewportWidth - offset.left;
							if(diff < 520){
								$(this).find("css3-container:first").css({'top':'-15px','left':'-244px'});
								$(this).find("ul.sn_level_1").css({'left':'-244px'});
							}
							else {
								$(this).find("ul.sn_level_1").css({'left':'243px'});
							}
		  	 
		    }	 
		     $(this).find("ul:first").show();
		}
		}
	);	


	$("ul.sn_main_nav li.sn_item_1").mouseleave(
		function() {
			$(this).find("ul:first").hide();
		}
	);	

	if(viewportWidth < 1300) {
	  $("#back-top").css('right','0px');
	} else {
	  $("#back-top").css('right','80px');
	}
}

fitElements();

$(window).resize(function() {
	fitElements();
});


function replace_gsbox() {
  var viewportWidth = $(window).width();
	var viewportHeight = $(window).height();
	
	
	if(viewportHeight < 680) {
		
      $("div.si_area_container5").css({'position':'absolute'});
	}
	if(viewportHeight >= 680) {
      $("div.si_area_container5").css({'position':'fixed'});
	}
	 
  	if(viewportWidth < 1120) { 
			$("h1.top_slogan").css('margin-right','53px');
	    if(c_contenttype == 0) {
	      $("div.si_area_container2").css({'left':'-33px'});
          //$("div.si_area_container5").prev().css({'top':'205px'});
          $("div.si_area_container5").css({'top':'95px'});
					$("div.si_area_container5").prev("css3-container").css({'top':'95px'});
		  if(viewportHeight >= 680) {
		
            $("div.si_area_container5").css({'position':'absolute'});
	      }
		  
	    }
	    else
	    {
		   if(viewportHeight < 680) {
		
            $("div.si_area_container5").css({'position':'absolute'});
			$("div.si_area_container5").css({'top':'75px'});
          }
		  $("div.si_area_container5").css({'top':'75px'});
				if($("div.c_ct_container").find("div.ip_level1").length || $("div.c_ct_container").find("div.ip_level2").length) {
					  $("div.si_area_container5").css({'top':'450px'});
				}
	    }
	  
	  } 
  	else {
	     $("h1.top_slogan").css('margin-right','0px');
		 if(c_contenttype == 0) {
           $("div.si_area_container2").css({'left':'0px'});
           $("div.si_area_container5").css({'top':'365px'});
		   
		  
	        if(viewportHeight >= 680) {
			         $("div.si_area_container5").css({'position':'fixed'});
	        }
		 }
		 else
		 {
		   $("div.si_area_container5").css({'top':'365px'});
	       $("div.bodyframe").css({'margin-top':'0px'}); 
	       $("div.top_slogan").css({'top':'216px'});
		   
          if(viewportHeight < 680) {
		
            $("div.si_area_container5").css({'position':'absolute'});
          }
	      if(viewportHeight >= 680) {
            $("div.si_area_container5").css({'position':'fixed'});
	      }
		   
		}
		 
	  }
}

if(!ie6) {
  replace_gsbox();
}



$(window).resize(function() {
		if(!ie6) {
		replace_gsbox();
		}
});



$("div.nlevel0 .nlevel0_item a.nl0_inactive").hover(
  function(){$(this).find("div").stop(true,true).fadeIn(300);},
  function(){$(this).find("div").stop(true,true).fadeOut(300);}
);

var str = 'sn_item_a';
for (var i = 0; i < c_site_imagenav_active_selection.length; i++) {
    str += '_' + c_site_imagenav_active_selection[i];
    jQuery('a#' + str).addClass('sn_item_active');
}

/*var viewportWidth = $(window).width();
if(viewportWidth < 1050) {
	$("div.top_bg").addClass("top_bg_s");
	}*/
});

jQuery(window).load(function() {
  var ai1_offset = $(".ai1").offset();
	var ai1 = $(".ai1").height()+ai1_offset.top-348;
	var bodyframe = $("div.bodyframe").height();
	if(ai1 > 1200){
	  $("div.bodyframe").css({'min-height':ai1, 'height':ai1});
	}

for (var i = 1; i <= c_site_imagenav_level; i++)
{
  var visibleItems = c_site_imagenav_visible_items[i];
  var carouselNavDivs = jQuery('.jq_in'+i+'_carousel').find('li').length;
  var centerPosition = Math.round(c_site_imagenav_active_selection[i] - 1 - (visibleItems / 2)) - 1;
  if ((centerPosition < 0) || carouselNavDivs <= visibleItems ||
      (c_site_imagenav_active_selection[i] <= visibleItems))
  {
    centerPosition = 0;
  }
  
  if (centerPosition > (carouselNavDivs - visibleItems)) {
    centerPosition = carouselNavDivs - visibleItems;
  }
  
   if (centerPosition < 0) {
    centerPosition = 0; 
  }

  var carouselClass = '.jq_in' + i + '_carousel';
  
  jQuery(carouselClass).jCarouselLite({
    btnNext: carouselClass + "_next",
    btnPrev: carouselClass + "_prev",
    circular: false,
    mouseWheel: true,
    scroll: c_site_imagenav_scroll_items[i],
    visible: visibleItems,
    start: centerPosition
  });
  if (carouselNavDivs > visibleItems)
  {
    if (c_site_imagenav_active_selection[i] > visibleItems) {
      jQuery(".jq_in"+i+"_carousel_prev").removeClass('disabled');
    }
    if (centerPosition < (carouselNavDivs - visibleItems)) {
      jQuery(".jq_in"+i+"_carousel_next").removeClass('disabled');
    }
  }  
}


});


function animateNavLevels(action, args)
{
  if (!args || !(args instanceof Array)) {
    return 0;
  }
  
  if (action == 'hide')
  {
    for (var i = 0; i < args.length; i++ ) {
      jQuery('.jq_nlevel' + args[i]).hide();
    }
  }
  else if (action == 'move')
  {
    var activeLevel = args[0] + 1;
    jQuery('.jq_nlevel' + activeLevel).hide();
    jQuery('.jq_nlevel' + activeLevel).slideDown('slow');
    args.reverse();
    for (var i = 0; i < args.length; i++ ) {
      jQuery('.jq_nlevel' + args[i]).slideUp('slow');
    }
  }
  else if (action == 'toggle')
  {
    var activeLevel = args[0] + 1;
    jQuery('.jq_nlevel' + activeLevel).slideToggle('slow');
    args.reverse();
    for (var i = 0; i < args.length; i++ ) {
      jQuery('.jq_nlevel' + args[i]).slideToggle('slow');
    }
  }
}
