
var stary = 0;
var zmiana = 0;
var nowy_ID = 0;
var ilosc_zdjec = 0;
var id_wyswietlanego = 0;                     
var fadingObjectID = new Object();
var fadingTimerID = new Object();


			function startIT(ile)
			{			
				ilosc_zdjec = ile;
				szer = screen.width;
				wys = screen.height;
				if(szer > 800)
				{
					szer = (szer - 800)/2 - 20;
					wys = (wys - 640)/2 - 130;
					document.getElementById('page').style.left = szer+'px';
					document.getElementById('ust').style.left = szer+'px';
					document.getElementById('ust').style.height = wys+'px';
				}
				document.getElementById('zaslona').style.visibility = 'hidden';
				setTimeout("go()", 2000);
			}
			
			function go()
			{
				zm = stary+1;
				if(zm > ilosc_zdjec) zm = 0;
				start_ch(zm);
				setTimeout("go()", 3000);
			}
			
			function ftvis(id)
			{
				document.getElementById('dt'+id).style.visibility = 'visible';
			}

			function fthid(id)
			{
				document.getElementById('dt'+id).style.visibility = 'hidden';	
			}

			function positionIT(ile)
			{
				ilosc_zdjec = ile;
				szer = screen.width;
				wys = screen.height;
				if(szer > 800)
				{
					szer = (szer - 800)/2 - 20;
					wys = (wys - 640)/2 - 130;
					document.getElementById('page').style.left = szer+'px';
					document.getElementById('ust').style.left = szer+'px';
					document.getElementById('ust').style.height = wys+'px';
				}
				document.getElementById('zaslona').style.visibility = 'hidden';
				zm = 12;
				if(12 > ilosc_zdjec)
					zm = ilosc_zdjec;
				wyswietl(id_wyswietlanego,zm);
			}
			
			function przewijanie(kier)
			{
			/* kierunek 1 oznacza w prawo, 2 w lewo, 3 pokazanie ostatnich 12, 4 pierwszych 12*/
			ukryj(id_wyswietlanego);
			start = id_wyswietlanego;
			end = 0;
				if(kier == 1)
				{
					start +=12;
					end = start + 12;
					if(end > ilosc_zdjec)
					{
						end = ilosc_zdjec;
						start = ilosc_zdjec - 11;
						if(start < 0) start = 0;
					}					
				}
				else if (kier == 2)
				{
					start -=12;
					end = start + 12;
					if(start < 0)
					{
						start = 0;
						end = 12;
						if(end > ilosc_zdjec) end = ilosc_zdjec;					
					}	
				}
				else if (kier == 3)
				{
					end = ilosc_zdjec;
					start = ilosc_zdjec - 11;
				}
				else
				{
					end = 12;
					start = 0;
				}
			id_wyswietlanego = start;
			wyswietl(start, end);			
			}
			
			
			function ukryj(start)
			{
				zm = start + 12;
				if(start + 12 > ilosc_zdjec)
					zm = ilosc_zdjec + 1;
				for(var i = start; i < zm; i++)
				{
					stri = 'thumb'+i.toString(10);		
					/*document.getElementById(stri).style.opacity = 0;*/			
					document.getElementById(stri).style.visibility = 'hidden';			
				}
			}
			
			function wyswietl(start, stop)
			{
				for(var i = start; i < (stop+1); i++)
				{
					var stri = 'thumb'+i.toString(10);					
					document.getElementById(stri).style.visibility = 'visible'; 
					document.getElementById(stri).style.left = (92+(i - start)*50)+'px'; 
					/*fade(document.getElementById(stri),45,60,20);*/
				}
			}
			
			
			function start_ch(id)
			{
			var stzdj = 'zd'+stary;
			fade(document.getElementById(stzdj),0,30,30);
			zmiana = 1;
			nowy_ID = id;
			}
			
			function start_change(id)
			{
			var stzdj = 'zd'+stary;
			fade(document.getElementById(stzdj),0,60,30);
			zmiana = 1;
			nowy_ID = id;
			}
			
			function end_change(id)
			{
			var nwzdj = 'zd'+id;	
			var sta = 'wr'+stary;			
			var str = 'wr'+id;			
			stary = id;
			document.getElementById(sta).style.visibility = 'hidden';
			document.getElementById(str).style.visibility = 'visible'; 			 
			fade(document.getElementById(nwzdj),100,60,30);	
			}
      
      
      
      
			function fade(object, destOp, rate, delta){
			   			
			clearTimeout(fadingTimerID[object.sourceIndex]);
			     
			tmp_destOp = destOp/100;			
			tmp_delta = delta/100;			
			        
			    
			    taki = parseFloat(object.style.opacity);
			    
					diff = tmp_destOp-taki;				
				    direction = 1;
				    if (taki > tmp_destOp){
				        direction = -1;
				    }
				    tmp_delta=Math.min(direction*diff,tmp_delta);
				    object.style.opacity = taki + (direction*tmp_delta);
				    if (object.style.opacity != tmp_destOp){
						delta = tmp_delta*100;
				        fadingObjectID[object.sourceIndex]=object;
				        fadingTimerID[object.sourceIndex]=setTimeout("fade(fadingObjectID["+object.sourceIndex+"],"+destOp+","+rate+","+delta+")",rate);
					}
					else
					{
						if(zmiana == 1)
						{
							end_change(nowy_ID);
							zmiana = 0;
						}
					}
		}		
		
    	function lewo()
    	{
    		tymcz = stary - 1;    		
    		if(tymcz < 0)
    		{
    			tymcz = ilosc_zdjec;
   			}
    		start_change(tymcz);
    		if(tymcz < id_wyswietlanego)
    		{
    			przewijanie(2);
   			}
   			else
   			{
   				if(tymcz > id_wyswietlanego+11)
    			{
   				przewijanie(3);
   				}
   			}
    	}
    	
    	function prawo()
    	{
    		tymcz = stary + 1;    		
    		if(tymcz > ilosc_zdjec)
    		{
    			tymcz = 0;    			
   			}
    		start_change(tymcz);
    		
    		if(tymcz < id_wyswietlanego)
    		{
    			przewijanie(4);
   			}
   			else
   			{
   				if(tymcz > id_wyswietlanego+11)
    			{
   				przewijanie(1);
   				}
   			}
    	}
