﻿/**
 * Slide for Prototype & Scriptaculous (Slide4PS), Version 0.0.1 (2008.8.24 - 2008.8.24)
 *
 * Code Generator : Maeng Joon-Young (http://www.maengis.com)
**/

var slide = Class.create ({
	initialize : function (id, pixel, total_page, sliderName) {
		this.id = $(id);
		this.pixel = pixel;
		this.now_page = 1;
		this.total_page = total_page;
		this.sliderName = sliderName;
		this.direction = "next";
		this.timer = null;
		this.btnLeft = null;
		this.btnLeftSrc = null;
		this.btnRight = null;
		this.btnRightSrc = null;
	},

	play : function (type) {

		switch (type) {
			case 'prev':
				if (type == 'prev' && this.now_page > 1) this.now_page--;
				//else this.now_page = this.total_page;

				if(this.now_page == 1 && this.btnLeft != null){
					this.btnLeft.src = this.btnLeftSrc;
				}
			break;

			case 'next':
				if (type == 'next' && this.now_page < this.total_page) this.now_page++;
				//else this.now_page = 1;

				if(this.now_page == this.total_page && this.btnRight != null){
					this.btnRight.src = this.btnRightSrc;
				}
			break;
		}

		new Effect.Move(this.id, {x : '-'+((this.now_page - 1) * this.pixel), y : 0, mode : 'absolute'});
	},

	page : function (page) {
		if (page > 0 && page <= this.total_page) {
			new Effect.Move(this.id, {x : '-'+((page - 1) * this.pixel), y : 0, mode : 'absolute'});
			this.now_page = page;
		}
	},

	setSpinInterval : function (ms) {
		this.timer = setInterval(this.sliderName + ".spin()", ms);
	},

	clearSpinInterval : function () {
		clearInterval(this.timer);
	},

	spin : function (){

		if (this.direction == "next") {
			this.now_page++;

			if(this.now_page == this.total_page && this.btnRight != null){
				this.btnRight.src = this.btnRightSrc;
				this.direction = "prev";
			}

		}else {
			this.now_page--;

			if(this.now_page == 1 && this.btnLeft != null){
				this.btnLeft.src = this.btnLeftSrc;
				this.direction = "next";
			}

		}

		new Effect.Move(this.id, {x : '-'+((this.now_page - 1) * this.pixel), y : 0, mode : 'absolute'});

	},

	setBtnLeft : function(obj, src){
		this.btnLeft = obj;
		this.btnLeftSrc = src;
	},

	setBtnRight : function(obj, src){
		this.btnRight = obj;
		this.btnRightSrc = src;
	}
});