var Scrolling = {

	elementy:new Object(),
	
	/*	inicjowanie elementu do przewijania
		opcjaFormat = 1 text, 2 - obrazek 
		opcjaPauza = true element stoi, false element dziala
		szer potrzebna tylko dla tekstu
	*/		
	InicjujPozycje : function(id,szer,predkosc,opcjaPauza,opcjaFormat,odswiezanie) {
		this.elementy[id]=new Object();
		this.elementy[id]["szer"]=szer;	
		this.elementy[id]["predkosc"]=predkosc;	
		this.elementy[id]["opcjaPauza"]=opcjaPauza;	
		this.elementy[id]["opcjaFormat"]=opcjaFormat;	
		this.elementy[id]["odswiezanie"]=odswiezanie;	
		this.elementy[id]["czasID"]="";	
	},


	
	/* rozpoczecie przewijania elementu o konkretnym id */
	UruchomElement : function(id) {

		if(document.getElementById(id)) {
			
			if(this.elementy[id]["opcjaFormat"]==1) {
				var pusty = "<img src=pusty.gif width="+this.elementy[id]["szer"]+" height=0>";									
				var szerokoscTabeli="50%";
				var nowrap="nowrap";
			}
			else {
				var pusty="";
				szerokoscTabeli = this.elementy[id]["szer"]*(Math.ceil(document.body.clientWidth/this.elementy[id]["szer"])+1);
				var nowrap="";
			}				
			
			scrolling_body_oryg = document.getElementById(id).innerHTML;								

			document.getElementById(id).innerHTML = "<TABLE width='"+szerokoscTabeli+"' cellspacing='0' cellpadding='0'><TR><TD "+nowrap+">"+pusty+"<SPAN id='scrolling_body_"+id+"' width='100%'>&nbsp;</SPAN>"+pusty+"</TD></TR></TABLE>";										
			
			if(this.elementy[id]["opcjaFormat"]==1) {
				KomunikatTresc="";
				for(var i=0; i<50 ; i++) KomunikatTresc += scrolling_body_oryg;
				scrolling_body_oryg = KomunikatTresc;
			}

			document.getElementById("scrolling_body_"+id).innerHTML = scrolling_body_oryg;
			document.getElementById(id).style.display="block";									
			document.getElementById(id).scrollLeft = 0;			
						
			this.Przesuwanie(id);							
		}		
	},	
	
	
	/* przesuwanie wybranego elementu */
	Przesuwanie : function (id) {		
		
		if(document.getElementById(id)) {				
			
			this.elementy[id]["czasID"] = clearTimeout(this.elementy[id]["czasID"]);

			if(!this.elementy[id]["opcjaPauza"]) {				
				document.getElementById(id).scrollLeft += this.elementy[id]["predkosc"] * 1;			
			}			

			if(document.getElementById(id).scrollLeft >= document.getElementById(id).scrollWidth - document.getElementById(id).offsetWidth) {				
				document.getElementById(id).scrollLeft = 0;					
			}
			
			this.elementy[id]["czasID"] = setTimeout('Scrolling.Przesuwanie(\''+id+'\')', this.elementy[id]["odswiezanie"]);
		}		
	},


	Wstrzymaj : function (id) {
		this.elementy[id]["opcjaPauza"]=true;
	},

	Wznow : function (id) {
		this.elementy[id]["opcjaPauza"]=false;
	}


}
