$(document).ready(function() {
	$("#closable-box .scrollable").scrollable({
		size: 1,
		loop: true
	}).autoscroll({
		autoplay: true,
		interval: 10000
	}).navigator();

	var api = $("#recomended-photos .scrollable").scrollable({
		size: 1,
		loop: true, 
		onBeforeSeek: function(){
			if($("#recomended-photos").hasClass('hover') && !$("#recomended-photos .navi").hasClass('hover')){
				return false;
			}else{
				return true;
			}
		}
	}).navigator({
		           
	}).autoscroll({
		autoplay: true,
		autopause: true,
		interval: 10000,
		api: true
	});
	$("#recomended-photos").hover(
		function () { $(this).addClass("hover"); },
		function () { $(this).removeClass("hover"); }
	);
	$("#recomended-photos .navi").hover(
		function () { $(this).addClass("hover"); },
		function () { $(this).removeClass("hover"); }
	);
	                   
	$("#pause-scroller").unbind('click').toggle(function() {
		$(this).attr("title", "Wznów").attr("alt", "Wznów");
		api.pause();
	}, function() {
		$(this).attr("title", "Zatrzymaj").attr("alt", "Zatrzymaj");
		api.play();
	});
          
	$("#close-window").click(function() {
		var exdate = new Date();
		exdate.setDate(exdate.getDate() + 5000);
		
		setCookie('close_tips', '1', exdate);
		$("#closable-box").slideUp("normal", function() {
			$(this).remove();
		})
	});
	
	var contestsItems = $("#contests .item").length;
	$("#contests .current").text(1);
	$("#contests .total").text(contestsItems);
	$("#contests .items").css("width", (295 * contestsItems));

        //wrapper stworzony po to żeby maska się poprawnie wyświetlala
	$('#contest div.scrollable').wrap('<div id="contest-wrapper" />');
        $('#contest .buttons.right').appendTo('#contest-wrapper');
        var contestCount = $('<div/>', {
            id: 'contest-count-box',
            "class": "brown",
            html: 'Konkurs&nbsp;<span id="contest-index"></span>&nbsp;z&nbsp;<span id="contest-count"></span>'
         });
         $(contestCount).appendTo("#contest-wrapper");

	$("#contest #contest-wrapper div.scrollable").scrollable({
		size: 1, 
		loop: true,
                onSeek: printContestPages
	}).circular().autoscroll({
		autoplay: true,
		autopause: false,
		interval: 10000
	});
        
	printContestPages();    //wywolanie inicjalne
	/*$("#contests .scrollable").scrollable({
		size: 1,
		loop: true,  
		onSeek: function(event, i) {
			$("#contests .current").text((i + 1));
		}
	});*/

        
});

function printContestPages()
{
    var el = $("#contest #contest-wrapper div.scrollable").scrollable();
    if($("#contest #contest-wrapper div.scrollable").length){
	    var pi = el.getPageIndex();
	    var sizes = el.getSize() - 2;   //sa jakies cloned i dlatego -2
	
	    $("#contest-count-box #contest-index").html(pi+1);
	    $("#contest-count-box #contest-count").html(sizes);
    }
}
