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(tytul,tresc,img,thumb,link) {
		el = new Object();
		el.tytul=tytul;
		el.tresc=tresc;
		el.img=img;
		el.thumb=thumb;
		el.link=link;
		this.slots[this.count]=el;
		this.count++;		
	}
	
	this.init = function() {
		this.slot0=this.slots[0];
		this.slot1=this.slots[1];
		this.slot2=this.slots[2];
		this.current=0;
	}
	
	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++;
		this.slot0=this.slots[this.current];
		this.slot1=this.slots[this.current+1];
		this.slot2=this.slots[this.current+2];
		
		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.action = function (slot) {
		if (slot==0) {
			$("aktualnosc_duza_img").src = this.slot0.img;
			//$("top_tytul").innerHTML = this.slot0.tytul;
			$("top_link2").innerHTML = this.slot0.tytul;
			//$("top_tresc").innerHTML = this.slot0.tresc;
			$("top_link1").innerHTML = this.slot0.tresc;
			$("top_link").href = this.slot0.link;
			$("top_link1").href = this.slot0.link;
			$("top_link2").href = this.slot0.link;
		}
		if (slot==1) {
			$("aktualnosc_duza_img").src = this.slot1.img;
			//$("top_tytul").innerHTML = this.slot1.tytul;
			$("top_link2").innerHTML = this.slot1.tytul;
			//$("top_tresc").innerHTML = this.slot1.tresc;
			$("top_link1").innerHTML = this.slot1.tresc;
			$("top_link").href = this.slot1.link;
			$("top_link1").href = this.slot1.link;
			$("top_link2").href = this.slot1.link;
		}
		if (slot==2) {
			$("aktualnosc_duza_img").src = this.slot2.img;
			//$("top_tytul").innerHTML = this.slot2.tytul;
			$("top_link2").innerHTML = this.slot2.tytul;
			//$("top_tresc").innerHTML = this.slot2.tresc;
			$("top_link1").innerHTML = this.slot2.tresc;
			$("top_link").href = this.slot2.link;
			$("top_link1").href = this.slot2.link;
			$("top_link2").href = this.slot2.link;
		}
	}
	
	this.refresh = function() {
		$("slot0").src=this.slot0.thumb;
		$("slot1").src=this.slot1.thumb;
		$("slot2").src=this.slot2.thumb;
	}
	
	this.pauseTimer = function () {
		this.play=false;
	}
	this.startTimer = function () {
		this.play=true;
	}
	this.tick = function() {
		if (this.play) {
			this.ttick++;
			if (this.ttick==this.time) {
				this.ttick=0;
				//this.scrollRight();
				if (this.ii<2) this.ii++;
				else {
					this.scrollRight();
					if (!this.ret){
						this.ii=0;
						this.init();
						this.refresh();
					}
				}
				this.action(this.ii);
			}
		}
		
	}
	
}
