//function $(id) {return document.getElementById(id);}

function TopScroller() {
	//this.element = new Object();
	this.slots =  new Array();
//	this.slot0=null;
//	this.slot1=null;
//	this.slot2=null;
	this.count=0;
	this.current=0;
	this.time=5;
	this.ttick=0;
	this.play=true;
	this.ii=0;
	
	this.addElement = function(nazwa,kolekcja,tresc,thumb,link,cena1,cena2,idz) {
		el = new Object();
		el.nazwa=nazwa;
		el.kolekcja=kolekcja
		el.tresc=tresc;
		el.thumb=thumb;
		el.link=link;
		el.cena1=cena1;
		el.cena2=cena2;
		el.link1=idz;
		this.slots[this.count]=el;
		this.count++;		
	}
	
	this.scrollRight = function() {
//		if (this.ii<5) {
//			this.ii++;
//		} else this.ii=0;
//		this.ret=true;
//		if (this.current>1) {
//			this.ret=false;
//			return;
//		}
//		this.current++;

		if (this.ii>this.count) this.ii=0;
		else this.ii+=1;
		
		//this.refresh();
		//return true;
	}
	
	this.scrollLeft = function() {	
		if (this.current<1) return;
		this.current--;
//		this.slot0=this.slots[this.current];
//		this.slot1=this.slots[this.current+1];
//		this.slot2=this.slots[this.current+2];
		
		this.refresh();
	}
	
	this.unmarkAll = function (pre) {
		for (i=1;i<6;i++)
			if ($(pre+i)) $(pre+i).src = "img/"+i+"_szar.gif";
	}
	this.markN=function(pre,n) {
		$(pre+n).src="img/"+n+".gif";
	}
	
	this.action = function (from) {
		idslot = from.id;
		
		slot = idslot.substr(1);
		slot=slot-1;
		//alert(slot);
		this.unmarkAll("t");
		this.markN("t",slot+1);
		obj = this.slots[slot];
		$("t_tytul").innerHTML=obj.nazwa;
		$("t_tresc").innerHTML=obj.tresc;
		$("t_img").src=obj.thumb;
		$("t_link").href=obj.link;
		$("t_link1").href=obj.link1;
		$("t_cena1").innerHTML=obj.cena1;
		$("t_cena2").innerHTML=obj.cena2;
	}
	
	
	this.pauseTimer = function () {
		this.play=false;
	}
	this.startTimer = function () {
		this.play=true;
	}
	this.tick = function() {
		if (this.play) {
			obj=new Object()
			this.ttick++;
			if (this.ttick==this.time) {
				this.ttick=0;
				//alert(this.ii+" <=> "+this.count);
				if (this.ii>=this.count-1) this.ii=0;
				else this.ii+=1;			
				obj.id="t"+(this.ii+1);
				this.action(obj);
			}
		}
		
	}
	
}
