jQuery(function() {
  
  // Check out http://api.jquery.com/
  
  // Expects 'href' attribute of each 'a' to point to large version of image
	var lightBoxConfig = {
    imageLoading: '/images/lightbox/ico-loading.gif',
    imageBtnClose: '/images/lightbox/btn-close.gif',
    imageBtnPrev: '/images/lightbox/btn-prev.gif',
    imageBtnNext: '/images/lightbox/btn-next.gif'
  };
	var lightBoxGroups = []
	$('a.lightbox[rel]').each(function(){
		if($.inArray($(this).attr('rel'), lightBoxGroups) < 0){
			lightBoxGroups.push($(this).attr('rel'));
		}
	});
	for(i=0;i<lightBoxGroups.length;i++){
		$('a.lightbox[rel='+ lightBoxGroups[i] +']').lightBox(lightBoxConfig);
	}
	$('a.lightbox:not([rel])').lightBox(lightBoxConfig);
  
  // Expects container with images
  $('.cycle').cycle({
    timeout: 3000,
    speed: 3000,
    delay: 0
  });
  
  // Open external links in new tab
  $('a[href^="http://"]').attr('target', 'blank');

	// Locale switcher
	$('#language .switch').hide();
	$('#language').hover(function(){
		$('#language .switch').show();
	}, function(){
		$('#language .switch').hide();
	});
	
	// Background image
 if($('#home').size() > 0){
   $('#home #wrapper, #home #footer').hide();
   $('#home').find('body').append('<div id="logo-animation"><img src="/images/layout/franzbogen-logo.png"></div>');
   $('#home').find('body').append('<div id="background-image"><img src="/images/layout/T610-Alligator-gross.jpg"></div>');
   setTimeout('animateBackground()', 2000);
 }
 
});
function animateBackground(){
 $('#background-image, #logo-animation').fadeOut(1500, function(){
   $('#wrapper, #footer').fadeIn(1500);
 });
}

var menu = "#left";
      var menuYloc = null;

      $(document).ready(function(){

              var containerTop = $("#left").position().top;
              // var containerLeft = $("#left").position().left;
              var containerHeight = $("#wrapper").innerHeight();
              var menuHeight = $(menu).innerHeight();

              //Position the menu at the top-left of the container div
              // $(menu).css('top', containerTop).css('left', containerLeft);
              // 
              // menuYloc = parseInt($(menu).css("top").substring(0,$(menu).css("top").indexOf("px")))

              $(window).scroll(function () {

                      //If the menu is within the container then move it down
                      if($(document).scrollTop() > containerTop && $(document).scrollTop() < (containerTop + containerHeight - menuHeight))
                      {
                              offset = $(document).scrollTop()+"px";
                              $(menu).animate({top:offset},{duration:1000,queue:false});
                      }
    
              });
      });
