var slideshow_cur=-1;
	var slideshow_loaded=0;
	var slideshow_timeout;
	
	$(document).ready(function() {
		if($("#prawy_zdjecie").length>0)
		{
			$("#prawy_zdjecie").append('<div id="baner"></div><div id="baner_loading"></div>');
			
			for(i=0; i<slideshow_data.length; i++)
			{
				var img = new Image();
				$(img).hide();
				$(img).load(function () {
					slideshow_loaded=slideshow_loaded+1;
					
					if(slideshow_loaded==slideshow_data.length) { slideShowBegin(); }
				});
				$(img).error(function() { alert('blad'); });
				$(img).attr("src",slideshow_data[i].image);
				$("#baner").append(img);
				
				//var a=$('<a href="#"></a>');
				//$(a).html((i+1)).addClass("kulka_off").attr("rel",i).click(function() { slideShowPhoto($(this).attr("rel")); return false; });
				
				//$("#baner_navi").append(a);
			}
		}
	});
	function slideShowBegin()
	{
		$("#baner_loading").fadeOut("fast", function() { 
			slideShowPhoto(Math.floor(Math.random()*(slideshow_data.length)));
		});
	}
	
	function slideShowNext()
	{
		els=$("#baner img");
		if(slideshow_cur+1>=els.length) { newphoto=0; }
		else { newphoto=(slideshow_cur+1); }
		slideShowPhoto(newphoto);
	}
	
	function slideShowPhoto(newphoto)
	{
		clearTimeout(slideshow_timeout);	//just in case ;)
		els=$("#baner img");
		if(slideshow_cur>=0) { $(els[slideshow_cur]).fadeOut(); }
		slideshow_cur=newphoto;
		$(els[slideshow_cur]).fadeIn();
		
		//$("#baner_navi a").removeClass("kulka_on").addClass("kulka_off");
		//els2=$("#baner_navi a"); 
		//$(els2[slideshow_cur]).removeClass("kulka_off").addClass("kulka_on");
		
		slideshow_timeout=setTimeout("slideShowNext()",5000);
	
	}
