var Slider = function(id,currentNo,viewCount,movingSize,repeatTime) {
	this.container = document.getElementById(id);
	this.container.mouseover = false;
	this.itv = '';
	this.leftButton = getClassInTag(this.container, "span", "leftButton")[0];
	this.rightButton = getClassInTag(this.container, "span", "rightButton")[0];
	this.listObject = getClassInTag(this.container, "ul", "list")[0];
	this.itemObjects = getClassInTag(this.container, "li", "item");
	this.maxNo = this.itemObjects.length;
	this.currentNo = currentNo;
	this.viewCount = viewCount;
	this.movingSize = movingSize;
	this.repeatTime = repeatTime;

	this.init();
}

Slider.prototype = {
	init : function() {
		var Object = this;
		if (this.maxNo > this.viewCount)
		{	
			this.buttonSetting();
			//this.cloneObjects();
			//this.container.onmouseover = function() { this.mouseover = true; if(Object.itv) clearInterval(Object.itv); }
			//this.container.onmouseout = function() { this.mouseover = false; Object.itv = setInterval( function() { Object.rightButtonClick(); }, Object.repeatTime); }
			//this.itv = setInterval( function() { Object.rightButtonClick(); }, this.repeatTime);
			//this.currentNo = this.maxNo - (this.viewCount - 1);
			//this.listObject.style.left = (0 - ((this.currentNo - 1) * this.movingSize)) + "px";
		}
	},
	cloneObjects : function() {
		for (var a = 0; a < this.maxNo ; a++ ) { this.listObject.appendChild(this.itemObjects[a].cloneNode(true)); }
		this.maxNo = getClassInTag(this.container, "li", "item").length;
	},
	buttonSetting : function() {
		var Object = this;
		/* leftButton */
		this.leftButton.style.cursor = "pointer";
		this.leftButton.onclick = function() {
			Object.leftButtonClick();			
		}
		/* rightButton */
		this.rightButton.style.cursor = "pointer";
		this.rightButton.onclick = function() {
			Object.rightButtonClick();			
		}
	},
	leftButtonClick : function() {
		//if (this.currentNo == 1) { this.currentNo = (this.maxNo / 2) + 1; this.listObject.style.left = (0 - (this.movingSize * (this.currentNo - 1))) + "px"; }
		//if (this.currentNo == 1) { alert('´ÙÀ½ÀÚ·á°¡ ¾ø½À´Ï´Ù.'); return; }
		if (this.currentNo == 1) { return; }
		this.currentNo--;
		objectMoving(this.listObject, this.getListObjectLeft(), this.getListObjectLeft() + this.movingSize, 5);
		window.status = this.currentNo + ":" + this.listObject.style.left;
	},
	rightButtonClick : function() {
		//if (this.currentNo == this.maxNo - (this.viewCount - 1)) { this.currentNo = this.currentNo - (this.maxNo / 2); this.listObject.style.left = (0 - (this.movingSize * (this.currentNo - 1))) + "px"; }
		//if (this.currentNo == this.maxNo - (this.viewCount - 1)) { alert('ÀÌÀüÀÚ·á°¡ ¾ø½À´Ï´Ù.'); return; }
		if (this.currentNo == this.maxNo - (this.viewCount - 1)) { return; }
		this.currentNo++;
		objectMoving(this.listObject, this.getListObjectLeft(), this.getListObjectLeft() - this.movingSize, 5);
		window.status = this.currentNo + ":" + this.listObject.style.left;
	},
	getListObjectLeft : function() {
		if (this.listObject.style.left) {
			return parseInt(this.listObject.style.left.replace('px',''),10);
		} else {
			return 0;
		}
	}
}

function objectMoving(obj, start, end, speed) {
	//if (obj.itv) { return; }
	if (obj.itv) { clearInterval(obj.itv); }
	obj.style.left = start + "px";
	obj.itv = setInterval( function() {
		interval = end - parseInt(obj.style.left.split("px")[0]);
		if (interval < 0) move = Math.floor(interval * 0.15);
		else move = Math.ceil(interval * 0.15);
		obj.style.left = parseInt(obj.style.left.split("px")[0]) + move + "px";
		if (obj.style.left == end + "px") {
			clearInterval(obj.itv);
			obj.itv = null;
		}
	}, speed);
	return obj.itv;
}

function getClassInTag(obj,tag,cname) {
	var tags = obj.getElementsByTagName(tag);
	var cnames = new Array();
	for (var a = 0; a < tags.length; a++) {
		if (tags[a].className == cname) {
			cnames.push(tags[a]);
		}
	}
	return cnames;
}