var ListItemSelector = new Class({
	Implements: [Options, Events],
	initialize: function(element, options) {
		this.setOptions({
			"supressClicks": false,
			"startSelected": false,
			"staySelected": true,
			"selected": 0,
			"callback": null,
			"fxMin": 0.3,
			"fxMax": 1,
			"fxDuration": 300,
			"fxType": "opacity",
			"fxTransition": Fx.Transitions.Quad.easeOut
		}, options);
		
		if(element)
			this.elements = element.getChildren();
		else
			return;
					
		this.elements.each((function(el, index){
			el.fx = new Fx.Tween(el, { "duration":this.options.fxDuration, "transition": this.options.fxTransition, "link":"cancel"}).set(this.options.fxType, this.options.fxMin);
			el.clicked = false;
			el.index = index;
			el.addEvents({
				"mouseover": (function(){ 
					el.fx.start(this.options.fxType, this.options.fxMax);
				}).bind(this),
				"mouseout": (function(){ 
					if(!el.clicked) {
						el.fx.start(this.options.fxType, this.options.fxMin) 
					}
				}).bind(this),
				"click": (function(e){ 
					if(this.options.supressClicks) { 
						new Event(e).stop();
					} 
					if(!el.clicked && this.options.staySelected){
						this.select(el.index);
					} 
				}).bind(this)
			});
		}).bind(this));

		if(this.options.startSelected) {
			this.elements[this.options.selected].clicked = true;
			this.elements[this.options.selected].fx.set(this.options.fxMax);
			this.select(this.options.selected);
		}
	},
	
	select: function(index) {
		this.fireEvent("callback", [this.elements[index], index]);
		if(index == this.options.selected && this.elements[this.options.selected].clicked == true) 
			return;
			
		this.elements[this.options.selected].clicked = false;
		this.elements[this.options.selected].fx.start(this.options.fxType, this.options.fxMin);
		this.options.selected = index;
		this.elements[this.options.selected].clicked = true;
		this.elements[this.options.selected].fx.start(this.options.fxType, this.options.fxMax);
	},
	
	selectClass: function(strClassname) {
		this.elements.each(function(el, index){
			if(el.hasClass(strClassname)){
				this.select(index);
				return;
			}
		}.bind(this));
		
		return this.options.selected;
	}

});
