/**
 * Aga v1.04
 * http://squareflower.de/downloads/jquery/aga/
 *
 * Copyright 2010, Lukas Rydygel
 * Attribution-ShareAlike 3.0 Unported
 * http://creativecommons.org/licenses/by-sa/3.0/
 */
(function(b){b.fn.aga=function(m){var h=function(){},j=[];j.horizontal=["aga-horizontal","aga-horizontal-item","aga-horizontal-item-open"];j.vertical=["aga-vertical","aga-vertical-item","aga-vertical-item-open"];var a={easing:["",""],size:{min:53.7,max:"variable"},handler:function(a){return b(a)},orientation:"horizontal",direction:"left",start:0,action:"click",stayOpen:!0,animationTime:500,hoverTime:500,items:"li",open:{before:h,each:h,after:h},close:{before:h,each:h,after:h}},n=a.start,l,e={_getItems:function(){return b(this).children(a.items)}, _getSize:function(){switch(a.orientation){case "horizontal":return b(this).width();case "vertical":return b(this).height()}},_getAnimationProperties:function(a,b){switch(a){case "top":return{top:b};case "right":return{right:b};case "bottom":return{bottom:b};case "left":return{left:b};case "horizontal":return{width:b};case "vertical":return{height:b}}},_setOptions:function(c){b.extend(!0,a,c);b(this).data("aga-settings",a)},_getOptions:function(){return b(this).data("aga-settings")},options:function(a){return typeof a=== "object"?e._setOptions.apply(this,[a]):e._getOptions.apply(this)},init:function(c){e._setOptions.apply(this,[c]);b(this).data("aga-pointer",n).addClass(j[a.orientation][0]);var f=this,d=e._getItems.apply(this),g;for(c=0;c<d.length;c++)(function(c){g=typeof a.handler=="function"?a.handler(d[c]):null;b(d[c]).addClass(j[a.orientation][1]);if(g)switch(a.action){case "click":g.bind("click",function(){n=b(f).data("aga-pointer");c==n&&!a.stayOpen?e.close.apply(f,[c,!1]):e.open.apply(f,[c,!1])});break;case "hover":b(f).hover(function(){clearTimeout(l)}, function(){clearTimeout(l);l=setTimeout(function(){a.stayOpen||e.close.apply(f,[c,!1])},a.hoverTime)}),g.hover(function(){clearTimeout(l);l=setTimeout(function(){e.open.apply(f,[c,!1])},a.hoverTime)})}})(c);a.start==null?e.close.apply(this,[null,!0]):e.open.apply(this,[a.start,!0])},close:function(c,f){b(this).data("aga-pointer",null);var d=e._getItems.apply(this),g=e._getAnimationProperties(a.orientation,d.length*a.size.min),h=f?0:a.animationTime;b(this).animate(g,h,a.easing[1]);a.close.before(d, c);for(var i=0;i<d.length;i++)g=i*a.size.min,g=e._getAnimationProperties(a.direction,g),b(d[i]).animate(g,h,a.easing[1],function(){a.close.each(d,i,c)}),b(d[i]).removeClass(j[a.orientation][2]);a.close.after(d,c)},open:function(c,f){b(this).data("aga-pointer",c);var d=e._getItems.apply(this),g=a.size.max=="variable"?e._getSize.apply(d[c]):a.size.max,h=f?0:a.animationTime,i=e._getAnimationProperties(a.orientation,a.size.max=="variable"?(d.length-1)*a.size.min+g:(d.length-1)*a.size.min+a.size.max); b(this).animate(i,h,a.easing[0]);a.open.before(d,c);for(var k=0;k<d.length;k++)i=k<=c?k*a.size.min:(k-1)*a.size.min+g,i=e._getAnimationProperties(a.direction,i),b(d[k]).animate(i,h,a.easing[0],function(){a.open.each(d,k,c)}).removeClass(j[a.orientation][2]),k==c&&b(d[k]).addClass(j[a.orientation][2]);a.open.after(d,c)},destroy:function(){var c=e._getItems.apply(this),f;b(this).removeClass(j[a.orientation][0]);for(var d=0;d<c.length;d++)(function(d){f=typeof a.handler=="function"?a.handler(c[d]):null; b(c[d]).removeClass(j[a.orientation][0]+" "+j[a.orientation][1]);if(f)switch(a.action){case "click":f.unbind("click");break;case "hover":b(this).unbind("mouseenter mouseleave"),f.unbind("mouseenter")}})(d)}},o=arguments;return this.each(function(){e[m]?(a=e._getOptions.apply(this),n=b(this).data("aga-pointer"),e[m].apply(this,Array.prototype.slice.call(o,1))):(typeof m==="object"||!m)&&e.init.apply(this,o)})}})(jQuery);
