function CM_slider()
{
	// Lütfen izinsiz kullanmayınız.

	this.recordCount = 0;

	this.elm = null;
	this.elmActive = null;
	this.elmTotal = null;
	this.class_name = 'CM_slider_item';

	this.current = 0;
	this.direction = -1;

	this.stepItemCount = 1;
	this.itemWidth = 0;
	this.visibleCount = 0;
	this.firstSlide =true;

	this.stepTime = 30;
	this.stepCount = 10;
	this.stepAmount = 0;
	this.stepIndex = 0;
	this.totalWidth = 0;
	this.lastestLeft = 0;
	this._automaticStepTime = 5000;
	this._automaticTimer = null;
	this.name = 'CMSLIDER';
	this.goStatus = true;

	this.timerIndex = null;

	this._start = _start;
	this._action = _action;
	this._clear = _clear;
	this._go = _go;
	this.go = go;
	this._automatic = _automatic;
	this._clearAutomaticTimer = _clearAutomaticTimer;
	this._checkStatus = _checkStatus;

	function _start()
	{
		if(!this.elm)
			return false;

		tmp = this.elm.getElementsByTagName('div');

		for(i = 0; i<tmp.length; i++)
		{
			if(tmp[i].className == this.class_name)
			{
				this.recordCount += 1;
				this.itemWidth = tmp[i].offsetWidth;
			}
		}

		this.visibleCount = parseInt(this.elm.offsetWidth / this.itemWidth) * 1;

		this.totalWidth = this.itemWidth * this.recordCount;

		this.stepAmount = parseInt(this.itemWidth / this.stepCount);

		this.lastestLeft = document.getElementById(this.class_name + "_" + (this.recordCount - 1)).offsetLeft;

		this.showElmTotal();

		this.showElmActive();
	}

	this.showElmTotal = function()
	{
		if(this.elmTotal)
		{
			this.elmTotal.innerHTML = this.recordCount;
		}
	}

	this.showElmActive = function()
	{
		if(this.elmActive)
		{
			tmp = this.current * -1 + this.stepItemCount;
			if(tmp > this.recordCount)
				tmp = this.recordCount;

			this.elmActive.innerHTML = tmp;
		}
	}

	function _action()
	{
		if(!this.recordCount)
			return false;
		else if (this.visibleCount >= this.recordCount)
			return false;

		this._automatic();
	}

	function _go()
	{

		this.stepIndex++;

		if(this.stepIndex == this.stepCount)
		{
			_step = this.itemWidth - (this.stepCount * this.stepAmount) + this.stepAmount;
		}
		else
		{
			_step = this.stepAmount;
		}

		_step = _step * this.stepItemCount;

		for(i=0; i<this.recordCount; i++)
		{
			tmp = document.getElementById(this.class_name + "_" + i).offsetLeft + _step * this.direction;
			if(tmp > this.lastestLeft)
			{
				tmp = _step - this.itemWidth;
			}

			document.getElementById(this.class_name + "_" + i).style.left = tmp + "px";
		}

		if(this.stepIndex == this.stepCount)
		{
			this._clear();
		}
		else
		{
			this.timerIndex = setTimeout(this.name + "._go();", this.stepTime);
		}

		this.showElmActive();
	}

	function go(direction, automatic)
	{
		if(!this.goStatus)
			return;

		/*if(this.current * direction + this.stepItemCount >= this.recordCount)
		{
			return false;
		}*/

		if(!automatic)
			this._clearAutomaticTimer();

		if(this.current + direction > 0)
			return false;

		if((this.recordCount - this.visibleCount) < Math.abs(this.current + direction))
			return false;

		this.goStatus = false;

		this.direction = direction;
		this.current += direction * this.stepItemCount;
		this._go();
	}

	function _clear()
	{
		this.stepIndex = 0;

		if(this.timerIndex != null)
			clearTimeout(this.timerIndex);
		this.timerIndex = null;

		this.goStatus = true;
	}

	function _clearAutomaticTimer()
	{
		if (this._automaticTimer != null)
			clearTimeout(this._automaticTimer);
		this._automaticTimer = null;		
	}

	function _automatic()
	{
		if(this.firstSlide)
		{
			var temp = setTimeout("this.go(this.direction, 1)", this._automaticStepTime);
			clearTimeout(temp);
			this.firstSlide = false;
		}
		else
		{
			this._checkStatus();
			this.go(this.direction, 1);
		}

		this._automaticTimer = setTimeout(this.name + "._automatic();", this._automaticStepTime);
	}

	function _checkStatus()
	{
		var index = this.recordCount - this.visibleCount;

		if(this.current == -(index) )
			this.direction = 1;
		else if(this.current== 0)
			this.direction = -1;	
	}
}
