/* Copyright  2007 - 2010 YOOtheme GmbH, YOOtheme Proprietary Use License (http://www.yootheme.com/license) */

var Warp=Warp||{};
Warp.Menu=new Class({Implements:[Events,Options],initialize:function(d,c){this.setOptions({mode:"default",itemSelector:"li",firstLevelSelector:"li.level1",dropdownSelector:"ul",duration:600,remainTime:800,remainClass:"remain",transition:Fx.Transitions.linear,wait:false},c);var a=this;this.menu=document.id(d);this.hovered=this.timer=null;this.dropdowns=[];this.remain=[];if(this.menu){this.firstLevelItems=this.menu.getElements(this.options.firstLevelSelector);this.menu.addEvents({mouseenter:function(){a.remain=[];
a.removeRemain(10,true)},mouseleave:function(){a.remain.each(function(b){b.addClass(a.options.remainClass)});a.removeRemain(a.options.remainTime);a.menu.getElement("li."+a.options.remainClass)||a.fireMenuEvent("menu:leave")}});this.firstLevelItems.addEvent("mouseenter",function(){if(!this.hasClass(a.options.remainClass)){a.fireMenuEvent("menu:leave");a.fireMenuEvent("menu:enter",this)}});this.menu.getElements(this.options.itemSelector).each(function(b){var e=b.getElement(this.options.dropdownSelector);
if(e){this.dropdowns.include(b);this.options.mode=="slide"?this.attachSlideFx(b,e):this.attachDefaultFx(b,e);b.addEvents({mouseenter:function(){b._dropdownhover=true;a.remain=[];b.hasClass(a.options.remainClass)||b.fireEvent("fx:dropdown")},mouseleave:function(f){b._dropdownhover=false;a.menu!=f.relatedTarget&&!a.menu.hasChild(f.relatedTarget)&&a.remain.include(b)}})}}.bind(this));this.options.fancy&&Warp.FancyMenu&&new Warp.FancyMenu(this.menu,$extend({hoverClass:a.options.hoverClass},a.options.fancy))}},
fireMenuEvent:function(d,c){if(d=="menu:leave"){if(!this.hovered)return;c=this.hovered}else this.hovered=c;for(var a=0,b=0;b<this.firstLevelItems.length;b++)if(c==this.firstLevelItems[b]){a=b;break}this.menu.fireEvent(d,[c,a])},attachDefaultFx:function(d,c){var a=c.getStyles("width","height","opacity"),b={width:0,height:0};(new Element("div")).adopt(c.getChildren()).injectInside(c).setStyle("width",a.width.toInt());var e=new Fx.Morph(c,this.options);switch(this.options.mode){case "width":b={width:0};
break;case "height":b={height:0}}d.addEvent("fx:dropdown",function(){e.element.setStyles($extend(b,window.ie?{overflow:"hidden"}:{opacity:0,overflow:"hidden"}));e.start(a).chain(function(){e.element.setStyles(a)})})},attachSlideFx:function(d,c){var a=c.getStyles("width","height","opacity"),b=(new Element("div")).adopt(c.getChildren()).injectInside(c),e=new Fx.Morph(c,this.options),f=new Fx.Morph(b,this.options);d.addEvent("fx:dropdown",function(){e.element.setStyles({height:0,overflow:"hidden"});
e.start(a).chain(function(){e.element.setStyles(a)});f.element.setStyles({"margin-top":-a.height.toInt()});f.start({"margin-top":0})})},removeRemain:function(d,c){$clear(this.timer);this.timer=function(){this.dropdowns.each(function(a){if(a.hasClass(this.options.remainClass)&&!a._dropdownhover){a.removeClass(this.options.remainClass);c||this.fireMenuEvent("menu:leave")}a.removeClass(this.options.remainClass)}.bind(this))}.delay(d,this)},matchHeight:function(){this.menu&&this.menu.getElements("li.level2 div.sub").each(function(d){var c=
d.getStyle("padding-top").toInt()+d.getStyle("padding-bottom").toInt()+d.getStyle("border-top-width").toInt()+d.getStyle("border-bottom-width").toInt(),a=d.getParent().getElement("div.hover-box4"),b=Math.max(d.getDimensions().height,a.getDimensions().height)-c;[d,a].each(function(e){e.setStyle("height",b)})})},matchUlHeight:function(){this.menu&&this.menu.getElements("div.dropdown-3").each(function(d){d=d.getChildren();var c=0;d.each(function(a){c=Math.max(a.getSize().y,c)});d.each(function(a){a.setStyle("height",
c)})})}});
