var slider = Class.create({	
	initialize: function(container,params) {
		this.container 	= container;
		this.ref_id		= params.ref_id;
		this.current	= 1;	
		this.total 		= 0;
		this.wrapping 	= (typeof(params.wrapping) == 'boolean')?params.wrapping:true;
		this.sliding 	= false;
		this.duration 	= (params.duration)?params.duration:.5;
		this.children 	= new Array;

		if (params.ref_id) {
			try { 
				for (i = 1;document.getElementById((params.ref_id + i)) != null;i++) { this.children.push($(params.ref_id + i)); }
			} catch (e) { /* */ } 
		} else if (params.ref_class) {
			try {
				var c = params.ref_class;
				var c = $(container).getElementsByClassName(c);
				for (i=0; c.length > i;i++) {  this.children.push(c[i]);  }
			} catch (e) {  /* */ }
		} else if (params.refs) { 
			try {
		
			} catch (e) { /* */ }
		}
		this.total 		= this.children.length;
	},
	next: function () {
		var i = (this.current-1);
		var c = this.children[i];
		var wrapping = false;
		var n;
		
		if (this.children.length > (i+1)) {
			var n = (i+1);
			var obj = this.children[n];
		} else {
			var obj = this.children[0];
			wrapping = true; 
			n = 0;
		}
		
		if (!wrapping || this.wrapping) {
			// var obj = this.children[n];
	
			try {
				var w = ($(this.container).getWidth() * -1);

				var options = {
					x: w, y: 0,
					beforeStart: function () { 
						this.sliding = true; 
					}.bind(this),
					afterFinish: function () { 
						this.sliding = false;  
						this.children[(this.current-1)].setStyle({ left: 0, top: 0 }); 
					}.bind(this)
				};
		
				if (!this.sliding) {
					$(c).setStyle({ left: 0, top: 0 });
					var sp = $(this.container).getWidth();
					$(obj).setStyle({ left: sp, top: 0 });
					new Effect.Move(c, { x: w, y: 0 });
					new Effect.Move(obj, options) ;
					this.current = (n+1);
				}	
			} catch (e) { }
		} 
	},
	prev: function () { 
		var i = (this.current-1);		
		var c = this.children[i];
		var wrapping = false;
		var n;
		
		if (0 <= (i-1)) {
			n = (i-1);
			var obj = this.children[n];
		} else {
			wrapping = true; 
			n = (this.children.length - 1);
			var obj = this.children[n];
		}		
		
		if (!wrapping || this.wrapping) { 
			try {
				var w = ($(this.container).getWidth());
				var options = {
					x: w, y: 0,
					beforeStart: function () { 
						this.sliding = true; 
					}.bind(this),
					afterFinish: function () {
					 	this.sliding = false; 
					 	this.children[(this.current-1)].setStyle({ left: 0, top: 0 });
					}.bind(this)
				};
			
				if (!this.sliding) {	
					$(c).setStyle({ left: 0, top: 0 });
					$(obj).setStyle({ left: ($(this.container).getWidth() * -1), top: 0 });
					new Effect.Move(c, { x: w, y: 0 });
					new Effect.Move(obj,  options);
					this.current = (n+1);
				}	
			} catch (e) { }
		}
	},
	jump: function (p) {
		var page = (p-1); 
		var c = (this.current-1);
		var q = new Array;
		
		if ((page >= 0) && (this.children.length > page) && (page != c)) {
				if (c > page) { 
					// slide left 
					for (i = c; i < page; i++) {
						q.push(this.children[i]);					
					} 
					var w = ($(this.container).getWidth() * 1);
				} else {
					// slide right
					for (i = c; i > page; i--) {
						q.push(this.children[i]);					
					} 
					var w = ($(this.container).getWidth() * -1);
				}
				
				q.each(function (k) {  k.setStyle({ left: w, top: 0}); });
				c = this.children[c];
				obj = this.children[page];
				
				var options = {
					x: w, y: 0,
					beforeStart: function () { 
						this.sliding = true; 
					}.bind(this),
					afterFinish: function () {
					 	this.sliding = false; 
					 	this.children[(this.current-1)].setStyle({ left: 0, top: 0 }); 
					}.bind(this)
				};
				
				if (!this.sliding) {	
					$(c).setStyle({ left: 0, top: 0 });
					$(obj).setStyle({ left: (w*-1), top: 0 });
					new Effect.Move(c, { x: w, y: 0 });
					new Effect.Move(obj,  options);
					this.current = (page+1);
				}	
				
		
		} else {
			
		}
		
		
	}
});


