﻿var ImageMenu=new Class({getOptions:function(){return {onOpen:false,onClose:Class.empty,openWidth:200,transition:Fx.Transitions.quadOut,duration:400,open:null,border:0}},initialize:function(a,b){this.setOptions(this.getOptions(),b);this.elements=$$(a);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(c,b){c.addEvent("mouseenter",function(a){(new Event(a)).stop();this.reset(b)}.bind(this));c.addEvent("mouseleave",function(a){(new Event(a)).stop();this.reset(this.options.open)}.bind(this));var a=this;c.addEvent("click",function(c){if(a.options.onOpen){(new Event(c)).stop();if(a.options.open==b){a.options.open=null;a.options.onClose(this.href,b)}else{a.options.open=b;a.options.onOpen(this.href,b)}}})}.bind(this));if(this.options.open)if($type(this.options.open)=="number")this.reset(this.options.open);else this.elements.each(function(a,b){if(a.id==this.options.open)this.reset(b)},this)},reset:function(a){if($type(a)=="number"){var b=this.widths.openOthers;if(a+1==this.elements.length)b+=this.options.border}else var b=this.widths.closed;var c={};this.elements.each(function(e,a){var d=b;if(a==this.elements.length-1)d=b+5;c[a]={width:d}}.bind(this));if($type(a)=="number")c[a]={width:this.widths.openSelected};this.fx.start(c)}});ImageMenu.implement(new Options);ImageMenu.implement(new Events)
