var animatedcollapse={divholders:{},divgroups:{},lastactiveingroup:{},preloadimages:[],show:function(a){if(typeof a=="object"){for(var b=0;b<a.length;b++)this.showhide(a[b],"show")}else this.showhide(a,"show")},hide:function(a){if(typeof a=="object"){for(var b=0;b<a.length;b++)this.showhide(a[b],"hide")}else this.showhide(a,"hide")},toggle:function(a){if(typeof a=="object")a=a[0];this.showhide(a,"toggle")},addDiv:function(a,b){this.divholders[a]={id:a,$divref:null,attrs:b};this.divholders[a].getAttr=function(a){var b=new RegExp(a+"=([^,]+)","i");return b.test(this.attrs)&&parseInt(RegExp.$1)!=0?RegExp.$1:null};this.currentid=a;return this},showhide:function(a,b){var c=this.divholders[a].$divref;if(this.divholders[a]&&c.length==1){var d=this.divgroups[c.attr("groupname")];if(c.attr("groupname")&&d.count>1&&(b=="show"||b=="toggle"&&c.css("display")=="none")){if(d.lastactivedivid&&d.lastactivedivid!=a)this.slideengine(d.lastactivedivid,"hide");this.slideengine(a,"show");d.lastactivedivid=a}else{this.slideengine(a,b)}}},slideengine:function(a,b){var c=this.divholders[a].$divref;var d=this.divholders[a].$togglerimage;if(this.divholders[a]&&c.length==1){var e={height:b};if(c.attr("fade"))e.opacity=b;c.animate(e,c.attr("speed")?parseInt(c.attr("speed")):500,function(){if(d){d.attr("src",c.css("display")=="none"?d.data("srcs").closed:d.data("srcs").open)}if(animatedcollapse.ontoggle){try{animatedcollapse.ontoggle(jQuery,c.get(0),c.css("display"))}catch(a){alert('An error exists inside your "ontoggle" function:\n\n'+a+"\n\nAborting execution of function.")}}});return false}},generatemap:function(){var a={};for(var b=0;b<arguments.length;b++){if(arguments[b][1]!=null){a[arguments[b][0]]=arguments[b][1]}}return a},init:function(){var a=this;jQuery(document).ready(function(b){animatedcollapse.ontoggle=animatedcollapse.ontoggle||null;var c=animatedcollapse.urlparamselect();var d=a.getCookie("acopendivids");var e=a.getCookie("acgroupswithpersist");if(d!=null)d=d=="nada"?[]:d.split(",");e=e==null||e=="nada"?[]:e.split(",");jQuery.each(a.divholders,function(){this.$divref=b("#"+this.id);if((this.getAttr("persist")||jQuery.inArray(this.getAttr("group"),e)!=-1)&&d!=null){var f=jQuery.inArray(this.id,d)!=-1?"block":"none"}else{var f=this.getAttr("hide")?"none":null}if(c[0]=="all"||jQuery.inArray(this.id,c)!=-1){f="block"}else if(c[0]=="none"){f="none"}this.$divref.css(a.generatemap(["height",this.getAttr("height")],["display",f]));this.$divref.attr(a.generatemap(["groupname",this.getAttr("group")],["fade",this.getAttr("fade")],["speed",this.getAttr("speed")]));if(this.getAttr("group")){var g=a.divgroups[this.getAttr("group")]||(a.divgroups[this.getAttr("group")]={});g.count=(g.count||0)+1;if(jQuery.inArray(this.id,c)!=-1){g.lastactivedivid=this.id;g.overridepersist=1}if(!g.lastactivedivid&&this.$divref.css("display")!="none"||f=="block"&&typeof g.overridepersist=="undefined")g.lastactivedivid=this.id;this.$divref.css({display:"none"})}});jQuery.each(a.divgroups,function(){if(this.lastactivedivid&&c[0]!="none")a.divholders[this.lastactivedivid].$divref.show()});if(animatedcollapse.ontoggle){jQuery.each(a.divholders,function(){animatedcollapse.ontoggle(jQuery,this.$divref.get(0),this.$divref.css("display"))})}var f=b("a[rel]").filter('[rel^="collapse["], [rel^="expand["], [rel^="toggle["]');f.each(function(){this._divids=this.getAttribute("rel").replace(/(^\w+)|(\s+)/g,"").replace(/[\[\]']/g,"");if(this.getElementsByTagName("img").length==1&&a.divholders[this._divids]){animatedcollapse.preloadimage(this.getAttribute("data-openimage"),this.getAttribute("data-closedimage"));$togglerimage=b(this).find("img").eq(0).data("srcs",{open:this.getAttribute("data-openimage"),closed:this.getAttribute("data-closedimage")});a.divholders[this._divids].$togglerimage=b(this).find("img").eq(0);a.divholders[this._divids].$togglerimage.attr("src",a.divholders[this._divids].$divref.css("display")=="none"?$togglerimage.data("srcs").closed:$togglerimage.data("srcs").open)}b(this).click(function(){var a=this.getAttribute("rel");var b=this._divids==""?[]:this._divids.split(",");if(b.length>0){animatedcollapse[/expand/i.test(a)?"show":/collapse/i.test(a)?"hide":"toggle"](b);return false}})});b(window).bind("unload",function(){a.uninit()})})},uninit:function(){var a="",b="";jQuery.each(this.divholders,function(){if(this.$divref.css("display")!="none"){a+=this.id+","}if(this.getAttr("group")&&this.getAttr("persist"))b+=this.getAttr("group")+","});a=a==""?"nada":a.replace(/,$/,"");b=b==""?"nada":b.replace(/,$/,"");this.setCookie("acopendivids",a);this.setCookie("acgroupswithpersist",b)},getCookie:function(a){var b=new RegExp(a+"=[^;]*","i");if(document.cookie.match(b))return document.cookie.match(b)[0].split("=")[1];return null},setCookie:function(a,b,c){if(typeof c!="undefined"){var d=new Date;d.setDate(d.getDate()+c);document.cookie=a+"="+b+"; path=/; expires="+d.toGMTString()}else document.cookie=a+"="+b+"; path=/"},urlparamselect:function(){window.location.search.match(/expanddiv=([\w\-_,]+)/i);return RegExp.$1!=""?RegExp.$1.split(","):[]},preloadimage:function(){var a=this.preloadimages;for(var b=0;b<arguments.length;b++){if(arguments[b]&&arguments[b].length>0){a[a.length]=new Image;a[a.length-1].src=arguments[b]}}}}
