var over = false;
var current = null;
var go = true;
var current_little_hover = null;
var previous_open = null;
$(document).ready(function(){
	$("#fader").css("opacity",0);$("#fader").show();
	$(".open").css("opacity",0);$(".open").show();
	$(".little_hover").css("opacity",0);$(".little_hover").show();
	current_little_hover = $(".little_hover").first();
	previous_open = $("#buttons .wrap").first();
	if( slideshow == true ) {
		$('#slideshow').trigger('toggle_slideshow');
	}
	$("#buttons .wrap").hover(
		function() {
			over = true;
			var id = $(this).attr("id");
			var i = id.replace('wrap_','');
			current = i;
			checkCurrent($(this),i);
		},
		function() {
			over = false;
			current = null;
			$(this).children('.open').animate({opacity:0},500);
			checkFader();
		}
	);
	$("#buttons li li a").hover(
		function()
		{
			current_little_hover.stop(true,false);
			current_little_hover.animate({opacity:0},250);
			next_little_hover = $(this).prev(".little_hover");
			if( ( next_little_hover.attr("id") != current_little_hover.attr("id") ) || go == true ) {
				next_little_hover.animate({opacity:0.6},550);
				current_little_hover = next_little_hover;
				go = false;
			} else {
				go = true;
			}
		}
	);
});
//Fades the Fader out if the mouse left the area
function checkFader() {
	setTimeout(function(){
		if(!over) {
			$("#fader").animate({opacity:0},200);
		}
	},300);
}
function checkCurrent(element,i) {
	setTimeout(function(){
		element.stop(true,false);
		if(current == i && over) {
			$("#fader").animate({'left':current*width+"px",opacity:0.55},{
				duration: 250,
				easing: 'easeOutQuart',
				complete: function() {
					previous_open.stop(true,false);
					var id = element.attr("id");
					var i = id.replace('wrap_','');
					if( current == i ) {
						element.children('.open').animate({opacity:1},200);
					}
					previous_open = element;
				}
			});
		}
	},550);
}

