window.addEvent('domready', function(){
	var myMenu = new ImageMenu($$('#top_nav a'));
});

/*****************************************************************
	Script	: Image Menu
	Version	: 2.2
	Authors	: Samuel Birch
	Desc		: 
	Licence	: Open Source MIT Licence
	Modified by Arturo Campos, now is compatible with MooTools 1.2
*****************************************************************/
var ImageMenu = new Class({
	getOptions: function(){
		return {
			onOpen: false,
			onClose: Class.empty,
			openWidth: 215,
			transition: Fx.Transitions.Bounce.easeOut,
			duration: 450,
			open: null,
			border: 2
		};
	},// end of getOptions
	initialize: function(elements, options){
		this.setOptions(this.getOptions(), options);
		this.elements = $$(elements);
		this.widths = {};
		this.widths.closed = this.elements[0].getStyle('width').toInt();
		this.widths.openSelected = this.options.openWidth;
		this.widths.openOthers = Math.round(((this.widths.closed*this.elements.length) - (this.widths.openSelected+this.options.border)) / (this.elements.length-1));
		this.fx = new Fx.Elements(this.elements, {wait: false, duration: this.options.duration, transition: this.options.transition});
		this.elements.each(function(el,i){
			// Event mouseenter													
			el.addEvent('mouseenter', function(e){
				new Event(e).stop();
				this.reset(i);
			}.bind(this));
			// Event mouseleave
			el.addEvent('mouseleave', function(e){
				new Event(e).stop();
				this.reset(this.options.open);
			}.bind(this));
			// Temporal var for store options of Object
			//var obj = this;
			// Temporaly disabled for complete redirection
			// Event click
			/*el.addEvent('click', function(e){
				if(options.onOpen){
					if(obj.options.open == i){
						obj.options.open = null;
						options.onClose(this.id);
					} else {
						obj.options.open = i;
						options.onOpen(this.id);
					}
				}
			})*/
		}.bind(this));
	}, // end of initialize
	reset: function(num){
		if($type(num) == 'number'){
			var width = this.widths.openOthers;
			if(num+1 == this.elements.length){
				width += this.options.border;
			}
		}else{
			var width = this.widths.closed;
		}
		var obj = {};
		this.elements.each(function(el,i){
			var w = width;
			if(i == this.elements.length-1){
				w = width+5
			}
			obj[i] = {'width': w};
		}.bind(this));
		if($type(num) == 'number'){
			obj[num] = {'width': this.widths.openSelected};
		}
		this.fx.start(obj);
	} // end of reset
}); // end of ImageMenu
ImageMenu.implement(new Options);
ImageMenu.implement(new Events);