var imageElements;
var imageElementsCount;
var imageCounter = 0;
var firstCall = true;
var allowed = true;

function rotateImage() {
	for (i=imageCounter;i<imageElementsCount;i++) {
		// FADE CURRENT ELEMENT OUT
		if(allowed) {
			if(!firstCall)
			{
				$(imageElements[i]).fadeOut(2000);
			
				if (i+1 == imageElementsCount)
					imageCounter = 0;
				else
					imageCounter = i + 1;
			}
			
			// FADE NEXT ELEMENT IN
			$(imageElements[imageCounter]).fadeIn(2000);
			imageTimeout = window.setTimeout("rotateImage()", 6000);
			firstCall = false;	
			break;
		}
	}
}

function animate() {
	var left = $("#news ul").width() + "px";
	$("#news ul").css("left", "649px");
	$("#news ul").animate(
		{left: "-" + left}, 
		50000, 
		"linear", 
		function(){animate();} 
	);
}
$(document).ready(function() {
	// init
	$(window).load(function () {
		var left = $("#news ul").width() + "px";
		animate();		
	});
	
	$("div.popup").hide();
	$("li.popup").hover(
	    function () {
	    	$(this).addClass('active');
            $(".active div.popup").show();
        }, 
        function () {
            $(".active div.popup").hide();
	    	$(this).removeClass('active');
        }
    );

	if($.cookie('player_after')) {
		$("#player").hide();
		$("#player-after").show();
		$("#player-after").cycle({ 
		    speed:  500
		});
	}

	$("#player .play").hover(
		function () {
			$("#player").css("background-position", "0px -87px");
		},
		function () {
			$("#player").css("background-position", "0px 0px");
		}
	);
	$("#player").click(function() {
		winRef = window.open("/player", "Player", "menubar=no,toolbar=no,location=no,resizable=no,Height=67,Width=375,left=" + ($(window).width() - 375) + ",top=0");
		$.cookie('player_after', true, {path: '/'});
		$("#player").hide();
		$("#player-after").show();
		$("#player-after").cycle({ 
		    speed:  500
		});
	});
});
