/* Copyright (C) YOOtheme GmbH, http://www.gnu.org/licenses/gpl.html GNU/GPL */

(function(d){var e=function(){};d.extend(e.prototype,{name:"dropdownMenu",options:{mode:"default",itemSelector:"li",firstLevelSelector:"li.level1",dropdownSelector:"ul",duration:600,remainTime:800,remainClass:"remain",matchHeight:!0,transition:"easeOutExpo",withopacity:!0,centerDropdown:!1,reverseAnimation:!1,fixWidth:!1,fancy:null,boundary:d(window),boundarySelector:null},initialize:function(e,g){this.options=d.extend({},this.options,g);var a=this,h=null,r=!1;this.menu=e;this.dropdowns=[];this.options.withopacity=
d.support.opacity?this.options.withopacity:!1;if(this.options.fixWidth){var s=5;this.menu.children().each(function(){s+=d(this).width()});this.menu.css("width",s)}this.options.matchHeight&&this.matchHeight();this.menu.find(this.options.firstLevelSelector).each(function(q){var k=d(this),b=k.find(a.options.dropdownSelector).css({overflow:"hidden"});if(b.length){b.css("overflow","hidden").show();b.data("init-width",parseFloat(b.css("width")));b.data("columns",b.find(".column").length);b.data("single-width",
1<b.data("columns")?b.data("init-width")/b.data("columns"):b.data("init-width"));var f=d("<div>").css({overflow:"hidden"}).append("<div></div>"),e=f.find("div:first");b.children().appendTo(e);f.appendTo(b);a.dropdowns.push({dropdown:b,div:f,innerdiv:e});b.hide()}k.bind({mouseenter:function(){r=!0;a.menu.trigger("menu:enter",[k,q]);if(h){if(h.index==q)return;h.item.removeClass(a.options.remainClass);h.div.hide().parent().hide()}if(b.length){b.parent().find("div").css({width:"",height:"","min-width":"",
"min-height":""});b.removeClass("flip").removeClass("stack");k.addClass(a.options.remainClass);f.stop().show();b.show();a.options.centerDropdown&&b.css("margin-left",-1*(parseFloat(b.css("width"))/2-k.width()/2));var c=b.css("width",b.data("init-width")).data("init-width");dpitem=a.options.boundarySelector?d(a.options.boundarySelector,f):f;boundary={top:0,left:0,width:a.options.boundary.width()};e.css({"min-width":c});try{d.extend(boundary,a.options.boundary.offset())}catch(g){}if(dpitem.offset().left<
boundary.left||dpitem.offset().left+c-boundary.left>boundary.width)b.addClass("flip"),dpitem.offset().left<boundary.left&&(b.removeClass("flip").addClass("stack"),c=b.css("width",b.data("single-width")).data("single-width"),e.css({"min-width":c}),a.options.centerDropdown&&b.css({"margin-left":""}));var l=parseFloat(b.height());switch(a.options.mode){case "showhide":c={width:c,height:l};f.css(c);break;case "diagonal":var i={width:0,height:0},c={width:c,height:l};a.options.withopacity&&(i.opacity=0,
c.opacity=1);f.css(i).animate(c,a.options.duration,a.options.transition);break;case "height":i={width:c,height:0};c={height:l};a.options.withopacity&&(i.opacity=0,c.opacity=1);f.css(i).animate(c,a.options.duration,a.options.transition);break;case "width":i={width:0,height:l};c={width:c};a.options.withopacity&&(i.opacity=0,c.opacity=1);f.css(i).animate(c,a.options.duration,a.options.transition);break;case "slide":b.css({width:c,height:l});f.css({width:c,height:l,"margin-top":-1*l}).animate({"margin-top":0},
a.options.duration,a.options.transition);break;default:i={width:c,height:l},c={},a.options.withopacity&&(i.opacity=0,c.opacity=1),f.css(i).animate(c,a.options.duration,a.options.transition)}h={item:k,div:f,index:q}}else h=active=null},mouseleave:function(c){if(c.srcElement&&d(c.srcElement).hasClass("module"))return!1;r=!1;b.length?window.setTimeout(function(){if(!(r||"none"==f.css("display"))){a.menu.trigger("menu:leave",[k,q]);var b=function(){k.removeClass(a.options.remainClass);h=null;f.hide().parent().hide()};
if(a.options.reverseAnimation)switch(a.options.mode){case "showhide":b();break;case "diagonal":var c={width:0,height:0};a.options.withopacity&&(c.opacity=0);f.stop().animate(c,a.options.duration,a.options.transition,function(){b()});break;case "height":c={height:0};a.options.withopacity&&(c.opacity=0);f.stop().animate(c,a.options.duration,a.options.transition,function(){b()});break;case "width":c={width:0};a.options.withopacity&&(c.opacity=0);f.stop().animate(c,a.options.duration,a.options.transition,
function(){b()});break;case "slide":f.stop().animate({"margin-top":-1*parseFloat(f.data("dpheight"))},a.options.duration,a.options.transition,function(){b()});break;default:c={},a.options.withopacity&&(c.opacity=0),f.stop().animate(c,a.options.duration,a.options.transition,function(){b()})}else b()}},a.options.remainTime):a.menu.trigger("menu:leave")}})});if(this.options.fancy){var j=d.extend({mode:"move",transition:"easeOutExpo",duration:500,onEnter:null,onLeave:null},this.options.fancy),m=this.menu.append('<div class="fancy bg1"><div class="fancy-1"><div class="fancy-2"><div class="fancy-3"></div></div></div></div>').find(".fancy:first").hide(),
o=this.menu.find(".active:first"),n=null,t=function(a,d){if(!d||!(n&&a.get(0)==n.get(0)))m.stop().show().css("visibility","visible"),"move"==j.mode?!o.length&&!d?m.hide():m.animate({left:a.position().left+"px",width:a.width()+"px"},j.duration,j.transition):d?m.css({opacity:o?0:1,left:a.position().left+"px",width:a.width()+"px"}).animate({opacity:1},j.duration):m.animate({opacity:0},j.duration),n=d?a:null};this.menu.bind({"menu:enter":function(a,d,b){t(d,!0);if(j.onEnter)j.onEnter(d,b,m)},"menu:leave":function(a,
d,b){t(o,!1);if(j.onLeave)j.onLeave(d,b,m)},"menu:fixfancy":function(){n&&m.stop().show().css({left:n.position().left+"px",width:n.width()+"px"})}});o.length&&"move"==j.mode&&t(o,!0)}},matchHeight:function(){this.menu.find("li.level1.parent").each(function(){var e=0;d(this).find("ul.level2").each(function(){var g=d(this),a=g.parents(".dropdown:first").show();e=Math.max(g.height(),e);a.hide()}).css("min-height",e)})}});d.fn[e.prototype.name]=function(){var p=arguments,g=p[0]?p[0]:null;return this.each(function(){var a=
d(this);if(e.prototype[g]&&a.data(e.prototype.name)&&"initialize"!=g)a.data(e.prototype.name)[g].apply(a.data(e.prototype.name),Array.prototype.slice.call(p,1));else if(!g||d.isPlainObject(g)){var h=new e;e.prototype.initialize&&h.initialize.apply(h,d.merge([a],p));a.data(e.prototype.name,h)}else d.error("Method "+g+" does not exist on jQuery."+e.name)})}})(jQuery);
