$(document).ready(function(){
	$("a.thickbox").lightBox();
	
	$('#datepicker').datepicker({ dateFormat: 'dd-mm-yy', dayNamesMin: ['N', 'PN', 'WT', 'ŚR', 'CZ', 'PT', 'SO'], dayNames: ['Niedziela', 'Poniedziałek', 'Wtorek', 'Środa', 'Czwartek', 'Piątek', 'Sobota'], monthNames: ['Styczeń', 'Luty', 'Marzec', 'Kwiecień', 'Maj', 'Czerwiec', 'Lipiec', 'Sierpień', 'Wrzesień', 'Październik', 'Listopad', 'Grudzień'], firstDay: 1, yearRange: '1900:2020', inline: true });
	
	// slideshow init with speed [ms]
	slideshowInit(15000);
	
});

function slideshowInit(speed){
	// create links referring to each slide basing on the content of the #screens div
	$("#screens").prepend("<div id=\"scr_nav\"><div class=\"progress\"></div></div>");
	for(var i=0; i < $("#screens .scr").length; i++){
		$("#scr_nav").append("<a href=\"#\">"+(i+1)+"</a>");
	}
	// linking the on-click action
	$("#scr_nav a").click(function(e){
		e.preventDefault();
		if($("#scr_nav a").index($(this)) != $("#scr_nav a").index($(".sel"))) slideshowJump($("#scr_nav a").index($(this)),speed);
	});
	slideshowPlay(speed);
}

function slideshowPlay(speed){
	if($("#scr_nav a.sel").length == 0){
		// start - select first slide
		$("#scr_nav a:first").addClass("sel");
	} else if($("#scr_nav a").index($(".sel")) == $("#scr_nav a").length-1){
		// loop back to the first slide
		$("#scr_nav a.sel").removeClass("sel");
		$("#scr_nav a:first").addClass("sel");
		$("#screens div.scr").fadeOut("200");
		$("#screens div.scr").eq($("#scr_nav a").index($(".sel"))).fadeIn("200");
	} else {
		// select next slide
		$("#scr_nav a.sel").removeClass("sel").next().addClass("sel");
		$("#screens div.scr").fadeOut("200");
		$("#screens div.scr").eq($("#scr_nav a").index($(".sel"))).fadeIn("200");
	}
	// start the progress bar
	$("#scr_nav .progress").css("width","0px");
	$("#scr_nav .progress").animate({width: "656px"},speed,function(){slideshowPlay(speed);});
}

function slideshowJump(id,speed){
	// reset the progress bar
	$("#scr_nav .progress").stop(true,false);
	$("#scr_nav .progress").css("width","0px");
	$("#scr_nav .progress").animate({width: "656px"},speed,function(){slideshowPlay(speed);});
	// highlight adequate link
	$("#scr_nav a.sel").removeClass("sel");
	$("#scr_nav a").eq(id).addClass("sel");
	// change slide
	$("#screens div.scr").fadeOut("200");
	$("#screens div.scr").eq(id).fadeIn("200");
}


// ####### FLASH BOXES INIT ########
var flashvars = {};
var params = {menu: "false", wmode: "transparent"};
var attributes = {};
swfobject.embedSWF("/template/gfx/boxes.swf", "flashBoxes", "940", "220", "9.0.0", "/template/gfx/expressInstall.swf", flashvars, params, attributes);
swfobject.embedSWF("/template/gfx/mapka.swf", "flashMap", "500", "480", "9.0.0", "/template/gfx/expressInstall.swf", flashvars, params, attributes);
