$(function(){
//CLOSE!
jQuery("#search .field").blur(function(){
if(jQuery(this).val() == ''){
    jQuery(this).removeClass("active");
}else{
    jQuery(this).addClass("active");
}
});

$("a.popout").click(function(event){
	event.preventDefault();
	popout = window.open(this.href, "Popout", "menubar=no,location=no,resizable=yes,scrollbars=no,status=no,top=10,left=10,width=750,height=450");
	popout.focus();
});
/*
function goToNext(next){
	next = parseInt(next);
	jQuery(".x-recommendation").each(function(){
		if(jQuery(this).css('zIndex') == 3){
			current = this;
		}
	});
	if(jQuery("#x-pagination a.current").attr("href").match(/\d+/)[0]-1 != next){
		jQuery(current).css({zIndex:"2"});
		
		jQuery(".x-recommendation").eq(next).css({zIndex:"3"}).animate({opacity:1}, 700, function(){
			jQuery(current).css({opacity:"0"});
		});
		
		jQuery("#x-pagination a").removeClass("current");
		jQuery("#x-pagination a[href=#"+(next+1)+"]").addClass("current");	
	}
}
var currentSuggestion = 0;
var suggestionsOn = 1;
var timing;

if(!jQuery(".x-recommendation").length){
	suggestionsOn = 0;
}

var suggestionLoop = window.setInterval(function(){
	if(suggestionsOn == 1){
		currentSuggestion++;
		if(currentSuggestion == jQuery(".x-recommendation").length){
			currentSuggestion = 0;
		}
		goToNext(currentSuggestion);
	}	
}, 5000);
$("#x-pagination a").click(function(event){
	event.preventDefault();

	if($(this).attr("href") == "#next"){
		next = jQuery("#x-pagination a.current").attr("href").match(/\d+/)[0];
		if(!jQuery(".x-recommendation").eq(next).length){
			next = 0;
		}
	}else if($(this).attr("href") == "#prev"){
		next = jQuery("#x-pagination a.current").attr("href").match(/\d+/)[0] - 2;
		if(next < 0){
			next = jQuery(".x-recommendation").length - 1;
		}
	}else{
		next = ($(this).attr("href").match(/\d+/)[0] - 1);
	}

	suggestionsOn = 0;
	goToNext(next);
	currentSuggestion = next;
	window.clearTimeout(timing);
	timing = window.setTimeout(function(){
		suggestionsOn = 1;
	}, 6000);
});
*/
	/*
/*
function toggleSuggestion(current){
	next = current+1;
	if(next == jQuery(".x-recommendation").length){
		next = 0;
	}
	$("#x-pagination a").removeClass("current");
	$("#x-pagination a[href=#"+(next+1)+"]").addClass("current");
	jQuery(".x-recommendation").eq(current).css({zIndex:"2"});
	if($.support.opacity){
		jQuery(".x-recommendation").eq(next).css({zIndex:"3"}).animate({opacity:1}, 700, function(){
			jQuery(".x-recommendation").eq(current).css({opacity:"0"});
		});
	}else{
		jQuery(".x-recommendation").eq(next).css({zIndex:"3"}).slideDown(700, function(){
			jQuery(".x-recommendation").eq(current).slideUp();
		});
	}
	
}
var currentSuggestion = 0;
var suggestionsOn = 1;

var suggestionLoop = window.setInterval(function(){
	if(suggestionsOn == 1){
		toggleSuggestion(currentSuggestion);
		currentSuggestion++;
		if(currentSuggestion == jQuery(".x-recommendation").length){
			currentSuggestion = 0;
		}
	}	
}, 5000);
	*/
	/*
jQuery(".x-recommendation, #x-pagination a").hover(function(){
	suggestionsOn = 0;
}, function(){
	suggestionsOn = 1;
});
*/

$(".playersize").click(function(event){
	event.preventDefault();
	
	if($(this).hasClass("big")){
		$(".player").removeClass('player-normal player-small').addClass('player-big');
	}else if($(this).hasClass("normal")){
		$(".player").removeClass('player-big player-small').addClass('player-normal');
	}else if($(this).hasClass("small")){
		$(".player").removeClass('player-normal player-big').addClass('player-small');
	}
});



/*

var suggestionLoop = window.setInterval(function(){
	goToNext(currentSuggestion);
}	
}, 5000);
*/


});

//$("#y-rightmenu a.active").prevAll().length
$("#y-rightmenu a").click(function(event){
	event.preventDefault();
	
	var prev = $("#y-rightmenu a.active").prevAll().length;
	var clicked = $(this).prevAll().length;
	
	if(prev != clicked){
		goToRecomendation(clicked);
	}
	userAction = 1;
});

var userAction = 0;
var suggestionTimer = window.setInterval(function(){
	if(userAction == 0){
		goToRecomendation(1,1);
	}else{
		userAction = 0;
	}
}, 4500);

function goToRecomendation(x, next){
	if(!$(':animated').length){
		if(next != undefined){
			if(!$(".y-recomendation.active").next().is("#y-rightmenu")){
				$(".y-recomendation.active").toggleClass('active').animate({'left':'-720px'},400, function(){
						$(this).css({'opacity':0,'z-index':2,'left':0});
						$(".y-recomendation.active").css({'opacity':1,'z-index':3});
					}).next().toggleClass('active').css({'opacity':1,'z-index':2});
				
				$("#y-rightmenu a.active").toggleClass('active').next().toggleClass('active');
			}else{
				$(".y-recomendation.active").toggleClass('active').animate({'left':'-720px'},400, function(){
						$(this).css({'opacity':0,'z-index':2,'left':0});
						$(".y-recomendation:first").eq(x).css({'z-index':4});
					});
				$(".y-recomendation:first").css({'opacity':1,'z-index':3}).toggleClass('active');
				$("#y-rightmenu a:first,#y-rightmenu a:last").toggleClass('active');
			}
			
		}else{
			$(".y-recomendation.active").toggleClass('active').animate({'left':'-720px'},400, function(){
				$(this).css({'opacity':0,'z-index':2,'left':0});
				$(".y-recomendation").eq(x).css({'z-index':4});
			});
			$(".y-recomendation").eq(x).css({'opacity':1,'z-index':2}).toggleClass('active');
			$("#y-rightmenu a.active").toggleClass('active');
			$("#y-rightmenu a").eq(x).toggleClass('active');
		
		}
	}
	return false;
}
