/*
 *                                                                                            	  
 *	Code By İsmail Perim                                                 
 *	http://www.ismailperim.net
 *	<ismailperim@gmail.com>
 *	
 * 
 *            bir div oluşturulup id verilir, içinede diğer divler eklenir.
 *	          var s = new Slider(türetilen nese ismi, div id, genişlik, yükseklik,süre (MS));
 *	          var s = new Slider("s","Slider",165,150,8000);
 *            s.Yukle();
 *            s.Oto();
 *
 *								
 */
function Slider(_nesneAdi,_sliderID,_kutuUzunluk,_kutuYukseklik,_sure)
{
	this.KutuUzunluk = _kutuUzunluk;
	this.KutuYukseklik = _kutuYukseklik;
	this.KutuSayi = 0 ;
	this.SliderID = _sliderID;
	this.Say = 0;
	this.Interval = 0;
	this.IntervalOto = 0;
	this.NesneAdi =  _nesneAdi;
	this.Simdiki = 0;
	this.NeKadar = 0;
	this.Sure = _sure;
	this.Islem = false;
	this.Tekrar = false;
	this.Over = true;
	// Fonksiyonlar
	
	this.Yukle = function (){
		
		document.getElementById(this.SliderID).style.width = this.KutuUzunluk.toString() + "px";
		document.getElementById(this.SliderID).style.height = this.KutuYukseklik.toString() + "px";
		document.getElementById(this.SliderID).style.overflow = "hidden";
		
		var icKutular = document.getElementById(this.SliderID).getElementsByTagName("DIV");
		this.KutuSayi = icKutular.length;
		
		var tablo =  document.createElement("TABLE");
		tablo.cellPadding = 0;
		tablo.cellSpacing = 0;
		tablo.style.width = (this.KutuSayi * this.KutuUzunluk).toString() + "px";
		tablo.style.height = (this.KutuYukseklik).toString() + "px";
		
		var tbody = document.createElement("TBODY");
		var satir = document.createElement("TR");		
		
		var sutun;
		for(i = 0;i<this.KutuSayi;i++)
		{
			sutun = document.createElement("TD");
			sutun.style.textAlign = "center";
			sutun.style.width = this.KutuUzunluk.toString() + "px"; 
			sutun.innerHTML = icKutular[i].innerHTML;	
			icKutular[i].style.display = "none";
			satir.appendChild(sutun);
		}
		
		tbody.appendChild(satir);
		tablo.appendChild(tbody);
		document.getElementById(this.SliderID).appendChild(tablo);
		
		document.getElementById(this.SliderID).scrollLeft = 0;		
		//alert(document.getElementById(this.SliderID).innerHTML);
		
	}
	
	this.Kaydir = function (gel) {
		if(!this.Islem)
		{
			if(gel>this.Simdiki)
			{
				this.NeKadar = (gel-this.Simdiki)*this.KutuUzunluk;
				this.Interval = setInterval(this.NesneAdi+".KaydirSaga("+gel+")",1);
				this.Simdiki = gel;
			}
			else
			{
				this.NeKadar = (this.Simdiki-gel)*this.KutuUzunluk;
				this.Interval = setInterval(this.NesneAdi+".KaydirSola("+gel+")",1);
				this.Simdiki = gel;

			}
		}	
	}
	
	this.KaydirSaga = function (gel){
		
		if(this.Say<this.NeKadar)
		{
			this.Islem = true;
			this.Say += 3;
			document.getElementById(this.SliderID).scrollLeft += 3;
		}
		else
		{
			this.Say = 0;
			this.NeKadar = 0;
			clearInterval(this.Interval);
			this.Islem = false;
			if(this.Tekrar)
			{
				this.Tekrar = false;
				this.Oto();
			}
		}
	}	

	this.KaydirSola = function (gel){
		
		if(this.Say<this.NeKadar)
		{
			this.Islem = true;
			this.Say += 6;
			document.getElementById(this.SliderID).scrollLeft -= 6;
		}
		else
		{
			this.Say = 0;
			this.NeKadar = 0;
			//			document.getElementById(this.SliderID).scrollLeft = 0;
			//			this.Simdiki = 0;
			clearInterval(this.Interval);
			this.Islem = false;
			if(this.Tekrar)
			{
				this.Tekrar = false;
				this.Oto();
			}			
		}	
	}
	
	this.Oto = function () {
	
		this.IntervalOto = setInterval(this.NesneAdi+".OtoKaynak()",eval(this.Sure));
	
	
	}

	this.OtoKaynak = function () {

	    if (this.Over) {
	        if (this.Simdiki < this.KutuSayi - 1) {

	            this.Kaydir(eval(this.Simdiki) + 1);

	        }
	        else {
	            this.Kaydir(0);
	        }
	    }

	}
	
	this.Sonraki = function () {
		if(!this.Islem)
		{
			this.Tekrar = true;
			this.Kaydir(eval(this.Simdiki)+1);
			clearInterval(this.IntervalOto);
		}	
	}
	
	this.Onceki = function () {
		if(!this.Islem)
		{
			this.Tekrar = true;
			this.Kaydir(eval(this.Simdiki)-1);
			clearInterval(this.IntervalOto);
		}	
	}
	
	
	// Fonksiyonlar ...
}


