var blocPrix = Class.create();

blocPrix.prototype = {
	nb : 0,
	widthList : 0,
	actual: 0,
	lists: undefined,
	theID: 1,

	initialize: function(nb, theID) {
		if(typeof nb != 'undefined') {
			this.nb = nb - 1;
		};

		this.theID = theID;
		this.widthList = Element.getWidth($('prix-' + this.theID + '-0'));

		Event.observe($('prixGoDown-' + this.theID), 'click', this.goDown.bindAsEventListener(this));
		Event.observe($('prixGoUp-' + this.theID), 'click', this.goUp.bindAsEventListener(this));
	},

	goTo: function(pos) {
		this.actual = pos;
		colonne = 'colonne-' + this.theID;

		/*
			TODO : meilleur gestion de queue
		*/
		new Effect.Opacity(colonne, {duration: 0.5, from: 1.0, to: 0.5, queue : {scope: 'fadeScope', position: 'front'} });
		new Effect.Move(colonne,{ x: -(this.widthList + 54)*pos, y: 0, mode: 'absolute', afterFinish: this.actualizeCommand() });
		new Effect.Opacity(colonne, {duration: 0.5, from: 0.5, to: 1.0, queue : {scope: 'fadeScope', position: 'end'} });
	},

	goDown: function(e) {
		Event.stop(e);
		if (this.actual == 0) return;
		var pos = this.actual - 1;
		this.goTo(pos);
	},

	goUp: function(e) {
		Event.stop(e);
		if (this.actual == this.nb) return;
		var pos = this.actual + 1;
		this.goTo(pos);
	},

	actualizeCommand: function() {
		$('blocPrix-index-' + this.theID).firstChild.nodeValue = this.actual + 1;

		if (this.actual == 0) {
			$('prixGoDown-' + this.theID).className = 'disabled';
		} else {
			$('prixGoDown-' + this.theID).className = 'undefined';
		}

		if (this.actual == this.nb) {
			$('prixGoUp-' + this.theID).className = 'disabled';
		} else {
			$('prixGoUp-' + this.theID).className = 'undefined';
		}
	}
}

function loadPrix(){
	var liste = $('fillDate').getElementsByTagName('a');

	for(i=0; i<liste.length; i++){
		Event.observe(liste[i], 'click', function(ev){
			var tmp = ev.target.innerHTML.split(' - ');

			$('fi_dd').value = tmp[0];
			$('fi_df').value = tmp[1];
		});
	}
}
