var Toggle = Class.create({	
	initialize: function(collection, options){
		this.collection = $(collection);
		this.options = $.extend({
			current_index: 0,
			register: true
		}, options || {});
		
		if(this.options.current_index > 0){ this.current_link = this.collection[this.options.current_index-1].addClass('selected'); }
		if(this.options.register){ this._register(); }
	},
	
	_toggle: function(element){
		this.collection.removeClass('selected');
		this.collection[element.name - 1].addClass('selected');
	},
	
	_mouseover: function(event){
		$(event.currentTarget).addClass('selected');
	},
	
	_mouseout: function(event){
		var element = $(event.currentTarget);
		if(!element.is(this.current_link)){ element.removeClass('selected'); }
	},
	
	_click: function(event){
		var element = $(event.currentTarget);
		this.collection.removeClass('selected');
		this.current_link = element;
		this.current_link.addClass('selected');
		if(this.options.callback){ this.options.callback(event); }
	},
	
	_register: function(type){
		switch(type){
			case 'mouseover':
				this.collection.bind(type, this._mouseover._bind(this));
				break;
			case 'mouseout':
				this.collection.bind(type, this._mouseout._bind(this));
				break;          
			case 'click':       
				this.collection.bind(type, this._click._bind(this));
				break;          
			default:
				this.collection.bind('mouseover', this._mouseover._bind(this)).bind('mouseout', this._mouseout._bind(this)).bind('click', this._click._bind(this));
				break;
		}
	},
	
	_unregister: function(type){
		switch(type){
			case 'mouseover':
				this.collection.unbind(type, this._mouseover._bind(this));
				break;
			case 'mouseout':
				this.collection.unbind(type, this._mouseout._bind(this));
				break;
			case 'click':
				this.collection.unbind(type, this._click._bind(this));
				break;
			default:
				this.collection.unbind('mouseover').unbind('mouseout').unbind('click');
				break;
		}
	}
});
