/*
 * (c) Dynarch.com 2007 | All rights reserved
 *
 * This file is part of TagForge CMS.  Please do not use nor distribute it
 * separately!
 */
 function Section(args){function PD(args,key,val){if(args[key]==undefined)args[key]=val;};PD(args,"frames",Section.DEFAULT_FRAMES);PD(args,"fps",Section.DEFAULT_FPS);PD(args,"no_opacity",/linux/i.test(navigator.userAgent));PD(args,"hidden",null);PD(args,"cookie",null);PD(args,"hoverBody",false);if(args.cookie){PD(args.cookie,"name","DA_Sections");PD(args.cookie,"expires",30);PD(args.cookie,"path","/");}if(typeof args.title=="string")args.title=document.getElementById(args.title);if(typeof args.body=="string")args.body=document.getElementById(args.body);if(!args.title||!args.body)throw "You must specify both title and body arguments as ID of DOM element or reference to DOM element";args.title.unselectable=true;var div=args.body.parentNode;if(!TF.HC(div,"Section-Body")){div=document.createElement("div");div.className="Section-Body";args.body.parentNode.insertBefore(div,args.body);div.appendChild(args.body);}this.bodyParent=div;this.args=args;this.anim=null;if(args.hidden==null)args.hidden=!this.getSavedState();this.height=args.hidden?0:this.bodyParent.offsetHeight;if(this.height==0){args.body.style.display="block";this.height=this.bodyParent.offsetHeight;this._do_hide(true);}else{this._do_show(true);}this._setupHandlers();};Section.DEFAULT_FRAMES=10;Section.DEFAULT_FPS=40;Section.PARSED_COOKIES={};Section.SECTIONS=[];TF.at_unload(function(){var a=Section.SECTIONS,i=a.length;while(--i>=0)a[i].destroy();});Section.prototype.getSavedState=function(){var cp=this.args.cookie;if(cp){var tmp=Section.PARSED_COOKIES[cp.name];if(!tmp){tmp=Section.PARSED_COOKIES[cp.name]={};var re=new RegExp(cp.name+"=(.*?)\s*(;|$)");if(document.cookie.match(re)){var ck=RegExp.$1,a=ck.split(/\./),i=a.length;while(--i>=0){var b=a[i].split(/:/);tmp[b[0]]=(1==b[1]);}};}if(tmp[cp.id]==null)tmp[cp.id]=true;return tmp[cp.id];}return true;};Section.prototype.saveState=function(){var cp=this.args.cookie;if(cp){var p=Section.PARSED_COOKIES,tmp=p[cp.name];tmp[cp.id]=this.visible()?1:0;for(var i in p){var ck=i+"=";var a=[];for(var j in p[i])a.push(j+":"+(p[i][j]?1:0));ck+=a.join(".");if(cp.path)ck+=";path="+cp.path;if(cp.expires){var tmp=new Date();tmp.setTime(cp.expires*86400000+tmp.getTime());ck+=";expires="+tmp.toGMTString();}document.cookie=ck;}}};Section.prototype.visible=function(){return TF.HC(this.args.title,"Section-Title-Expanded");};Section.prototype._setupHandlers=function(){var self=this;Section.SECTIONS.push(this);self.args.title.onmousedown=function(ev){self.toggle();return TF.stopEvent(ev);};function onmouseover(ev){ev||(ev=window.event);var title=self.args.title;if(!TF.isRelatedEvent(title,ev)){TF.AC(title,"Section-Title-Hover");TF.AC(title,(self.visible()?"Section-Title-Hover-Expanded":"Section-Title-Hover-Collapsed"));}};function onmouseout(ev){ev||(ev=window.event);var title=self.args.title;if(!TF.isRelatedEvent(title,ev)){TF.DC(title,"Section-Title-Hover");TF.DC(title,"Section-Title-Hover-Expanded");TF.DC(title,"Section-Title-Hover-Collapsed");}};self.args.title.onmouseover=onmouseover;if(self.args.hoverBody)self.args.body.onmouseover=onmouseover;self.args.title.onmouseout=self.args.body.onmouseout=onmouseout;if(self.args.hoverBody)self.args.body.onmouseout=onmouseout;};Section.prototype.destroy=function(){var t=this.args.title;this.args.title=null;t.onmousedown=null;t.onmouseover=null;t.onmouseout=null;t=this.args.body;this.args.body=null;t=this.bodyParent;this.bodyParent=null;};Section.prototype._stopAnimation=function(callHandlers){if(this.anim)this.anim.stop(callHandlers);this.anim=null;};Section.prototype._setupAnimation=function(hide,nosave){this._stopAnimation();var a=this.anim=new Animation(this.args.frames,this.args.fps,this.pos,hide?0:this.getHeight());if(hide)a.accel=true;a.nosave=nosave;a.hide=!!hide;a.obj=this;a.onUpdate=Section._anim_onUpdate;a.onStop=Section._anim_onStop;return a;};Section.prototype.contentUpdated=function(){if(!this.visible()&&!this.anim)this._do_hide();};Section.prototype.getHeight=function(){return this.args.body.offsetHeight;};Section._anim_onUpdate=function(){var sec=this.obj;var b=sec.args.body;var margin=this.pos-sec.getHeight();if(is_ie&&margin>=-2)return;b.style.marginTop=margin+"px";var o=this.percent;if(this.hide)o=100-o;if(!sec.args.no_opacity){if(is_ie){sec.bodyParent.style.filter="alpha(opacity="+o+")";}else{sec.bodyParent.style.opacity=o/100;}}sec.pos=this.pos;};Section._anim_onStop=function(){if(this.hide)this.obj._do_hide(this.nosave);else this.obj._do_show(this.nosave);};Section.prototype.show=function(instant,nosave){this.args.body.style.display="";TF.DC(this.args.title,"Section-Title-Collapsed");TF.DC(this.args.title,"Section-Title-Totally-Collapsed");TF.AC(this.args.title,"Section-Title-Expanded");if(instant)this._do_show(nosave);else this._setupAnimation(false,nosave).restart();};Section.prototype.hide=function(instant,nosave){TF.DC(this.args.title,"Section-Title-Expanded");TF.AC(this.args.title,"Section-Title-Collapsed");if(instant)this._do_hide(nosave);else this._setupAnimation(true,nosave).restart();};Section.prototype._do_show=function(nosave){this.anim=null;TF.DC(this.args.title,"Section-Title-Collapsed");TF.AC(this.args.title,"Section-Title-Expanded");var b=this.args.body;b.style.display="";b.style.marginTop="";b=this.bodyParent;if(!this.args.no_opacity){if(is_ie){b.style.filter="";}else{b.style.opacity="";}}this.pos=this.getHeight();nosave||this.saveState();};Section.prototype._do_hide=function(nosave){this.anim=null;TF.DC(this.args.title,"Section-Title-Expanded");TF.AC(this.args.title,"Section-Title-Collapsed");TF.AC(this.args.title,"Section-Title-Totally-Collapsed");this.args.body.style.marginTop=-this.getHeight()+"px";this.pos=0;this.args.body.style.display="none";nosave||this.saveState();};Section.prototype.toggle=function(instant){if(this.visible())this.hide(instant);else this.show(instant);};function Animation(length,speed,pos1,pos2){this.length=length;this.speed=Math.round(1000/speed);this.pos1=pos1;this.pos2=pos2;this.diff=pos2-pos1;this.percent=0;this.timerID=null;this.accel=false;};Animation.prototype={clearTimer:function(){(this.timerID)&&Interval.clear(this.timerID);this.timerID=null;},start:function(){if(typeof this.step=="undefined"||this.step<0||this.step>=this.length)this.restart();else{var self=this;this.clearTimer();this.timerID=Interval.set(function(){self.update();},this.speed);}},restart:function(){this.onStart(this);this.pos=this.pos1;this.step=0;this.diff=this.pos2-this.pos1;this.rad_step=Math.PI/(2*this.length);this.rad_pos=0;this.start();},update:function(){if(this.step<this.length&&this.step>=0){var f=this.accel?(1-Math.cos(this.rad_pos)):Math.sin(this.rad_pos);this.delta=Math.round(f*this.diff);this.pos=this.pos1+this.delta;this.percent=Math.round(100*(this.pos-this.pos1)/this.diff);this.onUpdate(this);++this.step;this.rad_pos+=this.rad_step;}else{this.delta=this.pos2-this.pos;this.pos=this.pos2;this.percent=100;this.onUpdate(this);this.stop(true);}},stop:function(call){this.clearTimer();call&&this.onStop(this);},onStart:function(){},onStop:function(){},onUpdate:function(){}};Interval={_currentId:0,_cached:{},_timers:{},set:function(action,speed){var o,id=++Interval._currentId;if(Interval._cached[speed]){o=Interval._cached[speed];o.actions[id]=action;++o.length;Interval._timers[id]=o;return id;}else{o={speed:speed,actions:{},length:1,timerID:setInterval(function(){var a=o.actions;for(var i in a)a[i]();},speed)};o.actions[id]=action;Interval._cached[speed]=o;Interval._timers[id]=o;}return id;},clear:function(id){var o=Interval._timers[id];--o.length;if(o.length==0){delete Interval._cached[o.speed];clearInterval(o.timerID);}else{delete o.actions[id];}delete Interval._timers[id];}};