// Menu
var menuAnimationDuration = 600;
function menuGetCloudLeft(li){
	if(li.size()<1)
		return 0;
	var left=0.5*li.width()-63;
	li.prevAll('li').each(function(){
		left+=$(this).width();
	});
	return left;
}
function menuMoveCloudTo(li,easing){
	var left=menuGetCloudLeft(li);
	$('#menu').stop(true).animate({backgroundPosition:''+left+'px 0px'},menuAnimationDuration,easing,function(){
		var link = li.find('a');
		if(!link.hasClass('active'))
			link.stop(true).animate({color:'#b93112'},menuAnimationDuration);
	});
}
$(function(){
	var left=menuGetCloudLeft($('#menu li:has(a.active)'));
	$('#menu').css({backgroundPosition: ''+left+'px 0px'});
	$('#menu li').hover(
		function(){
			menuMoveCloudTo($(this),'swing');
		},
		function(){
			menuMoveCloudTo($('#menu li:has(a.active)'),'swing');
			var link = $(this).find('a');
			if(!link.hasClass('active'))
				link.stop(true).animate({color:'#fff'},menuAnimationDuration);
		});
	$('#menu li a').click(function(){
		$('#menu li').unbind('mouseenter mouseleave');
	});
});
// Slideshow
var slideshowIndex=0;
var slideshowCount=0;
function slideshowGoto(index){
	var left = -index*541;
	$('#slideshow .caption .fader').fadeOut(400,function(){
		$('#slideshow .caption .fader').html($('#slideshow .hidden-caption').eq(index).html()) ;
	});
	$('#slideshow .images').stop(true).animate({marginLeft:left+'px'},600,'swing',function(){
		$('#slideshow .caption .fader').fadeIn(400);
	});
	$('#slideshow .navigation a').removeClass('active');
	$('#slideshow .navigation a[href="'+index+'"]').addClass('active');
}
$(function(){
	slideshowCount=$('#slideshow .images img').size();
	$('.controls.left').click(function(){
		slideshowIndex--;
		if(slideshowIndex<0)
			slideshowIndex=slideshowCount-1;
		slideshowGoto(slideshowIndex);
		return false;
	});
	$('.controls.right').click(function(){
		slideshowIndex++;
		if(slideshowIndex>slideshowCount-1)
			slideshowIndex=0;
		slideshowGoto(slideshowIndex);
		return false;
	});
	var index=0;
	$('#slideshow .navigation a').each(function(){
		$(this).attr('href',index++);
		$(this).click(function(){
			slideshowIndex=parseInt($(this).attr('href'));
			slideshowGoto(slideshowIndex);
			return false;
		});
	});
	$('#slideshow .frame')
		.hover(
			function(e){
				if($(e.relatedTarget).closest('.frame').size()<1)
					$('#slideshow .caption').stop(true).animate({top:'200px'},200,'swing');
			},
			function(e){
				if($(e.relatedTarget).closest('.frame').size()<1)
					$('#slideshow .caption').stop(true).animate({top:'258px'},200,'swing');
			})
		.click(function(){
			window.location = $(this).find('.caption a').attr('href') ;
		});
	/*$('#slideshow .controls').mouseover(function(e){
		e.stopPropagation();
		e.stopImmediatePropagation();
	});*/
});
//Footer
var footerStartHeight=45;
var footerStartPageY=0;
$(function(){
	$('#footer').get(0).ondragstart=function(){return false;}; // fix IE
	$('#footer-dragger')
		.click(function(){
			return false;
		})
		.mousedown(function(e){
			footerStartPageY=e.pageY;
			footerStartHeight=$('#footer').height();
			$(document).bind('mousemove',function(e){
				var height=footerStartHeight+footerStartPageY-e.pageY;
				if(height<45)
					height=45;
				else if(height>190)
					height=190;
				$('#footer').css({height:height+'px',marginTop:-height+'px'});
			});
			$(document).bind('mouseup',function(e){
				$(document).unbind('mousemove');
				$(document).unbind('mouseup');
			});
			return false;
		});
});
//Honeypot
$(function(){
    $('#honey').val('honey');
});
