var ardSlider = new Class({
    initialize: function(slider,myDelay){
    	this.sliderDiv = $(slider);
        this.myDelay = myDelay;
        this.myTimer;
        this.container = this.sliderDiv.getParent();
        this.itemDiv = this.sliderDiv.getChildren()[0];
        this.nbItems = this.sliderDiv.getChildren().length;
        this.curPos = 1;
        this.wStep = this.container.getStyle('width').toInt();
		var w = this.itemDiv.getStyle('width').toInt() * this.nbItems;
		this.sliderDiv.setStyle('width',w);
		//
		this.initArrows();
        this.startSlider();
    },
    callPeriodical: function() {
		this.myTimer = this.slideIt.periodical(this.myDelay,this);
	},
	slideIt: function() {
		if (this.curPos < (this.nbItems-1)	) { 
			var pos = -(this.curPos*this.wStep);
			(this.sliderDiv).tween('left', pos);
			this.curPos++; 
		} 
		else {
			this.sliderDiv.setStyle('left',0);
			this.curPos = 1;
			this.myTimer = $clear(this.myTimer); 
			this.slideIt();
			this.callPeriodical();
		};
	},
    startSlider: function(){
		this.callPeriodical();
    },
	skipToNext: function() {
		this.slideIt();
	},
	skipToPrev: function() {
		if (this.curPos>1) {
			this.curPos -= 2;
			this.slideIt();
		} else {
			var pos = -((this.nbItems-2)*this.wStep);
			this.sliderDiv.setStyle('left',pos);
			this.myTimer = $clear(this.myTimer); 
			var myFx = new Fx.Tween(this.sliderDiv,{property:'left'});
			myFx.start(pos-this.wStep);
			//(this.sliderDiv).tween('left', (pos-this.wStep));
			this.curPos = this.nbItems-3;
			this.slideIt();
		}
	},
    initArrows: function(){
		var arrP = this.container.getParent().getChildren()[0];
		var arrN = this.container.getParent().getChildren()[2];
		
		var f1 = this.skipToNext.bind(this);
		arrN.addEvent('click', f1);
		var f2 = this.skipToPrev.bind(this);
		arrP.addEvent('click', f2);
    }
});
