var DECOSOFT ={};

DECOSOFT.kDIR_RIGHT 	= -1;
DECOSOFT.kDIR_LEFT		= 1;

var $D = YAHOO.util.Dom;
var $E = YAHOO.util.Event;
var $A = YAHOO.util.Anim;
var $M = YAHOO.util.Motion;
var $DD = YAHOO.util.DD;
var $ = $D.get;

DECOSOFT.slider = function(o, l, r, n, d) {
		this.x = 1;
		this.n = n;
		this.t = o.t;
		this.c = o.c;
		this.s = o.s;
		this.l = l;
		this.r = r;
		this.d = d;
		this.dir = DECOSOFT.kDIR_RIGHT;
		this.paused = false;
}

DECOSOFT.slider.prototype = {
		init : function() {
			$(this.l).slider = this;
			$(this.r).slider = this;
			$E.on([this.l, this.r], 'click', this.move);
		},
		/** click on slider control */
		move : function(e) {
			$E.stopEvent(e);
			switch(this.id) {
				case this.slider.l:
					if ( this.slider.x === 1 ) {
						return;
					}
					var attributes = {
						points : {
							by : [this.slider.d, 0]
						}
					};
					this.slider.x--;
				break;
				case this.slider.r:
					if ( this.slider.x === this.slider.n ) {
						return;
					}
					var attributes = {
						points : {
							by : [0-this.slider.d, 0]
						}
					};
					this.slider.x++;
				break;
			};
			var anim = new $M(this.slider.t, attributes, 0.5, YAHOO.util.Easing.easeOut);
			anim.animate();
		},
		
		/** just slide, no action on control */
		slide: function () {
			if (!this.paused) {
				switch (this.dir) {
					case DECOSOFT.kDIR_LEFT:
						if ( this.x === 1 ) {
							this.dir = DECOSOFT.kDIR_RIGHT;
							return;
						}
						var attributes = {
							points : {
								by : [this.dir*this.d, 0]
							}
						};
						this.x--;
						break;
					case DECOSOFT.kDIR_RIGHT:
						if ( this.x === this.n ) {
							this.dir = DECOSOFT.kDIR_LEFT;
							return;
						}
						var attributes = {
							points : {
								by : [this.dir*this.d, 0]
							}
						};	
						this.x++;
						break;
				};
				var anim = new $M(this.t, attributes, 1, YAHOO.util.Easing.easeOut);
				anim.animate();
			}
		},

		cycle: function() {
			var myClass = this;
			$(myClass.c).onmouseover = function() {
				myClass.pause();
			}
			$(myClass.c).onmouseout = function() {
				myClass.resume();
			}
			
			function handleTimeout() {
				myClass.slide();
			}
			this.timeout = setInterval(handleTimeout, 10000);
		},
		
		stop: function() {
			clearInterval(this.timeout);
			this.t.onMouseOver = "";
			this.t.onMouseOut = "";
		},
		
		pause: function() {
			this.paused = true;
			$(this.s).style.display = 'block';
		},
		
		resume: function() {
			this.paused = false;
			$(this.s).style.display = 'none';
		}
}