﻿function ddtabcontent(A){this.tabinterfaceid=A;this.tabs=document.getElementById(A).getElementsByTagName("a");this.enabletabpersistence=true;this.hottabspositions=[];this.currentTabIndex=0;this.subcontentids=[];this.revcontentids=[];this.selectedClassTarget="link"}ddtabcontent.getCookie=function(A){var B=new RegExp(A+"=[^;]+","i");if(document.cookie.match(B)){return document.cookie.match(B)[0].split("=")[1]}return""};ddtabcontent.setCookie=function(A,B){document.cookie=A+"="+B+";path=/"};ddtabcontent.prototype={expandit:function(A){this.cancelautorun();var B="";try{if(typeof A=="string"&&document.getElementById(A).getAttribute("rel")){B=document.getElementById(A)}else{if(parseInt(A)!=NaN&&this.tabs[A].getAttribute("rel")){B=this.tabs[A]}}}catch(C){alert("Invalid Tab ID or position entered!")}if(B!=""){this.expandtab(B)}},cycleit:function(B,A){if(B=="next"){var C=(this.currentTabIndex<this.hottabspositions.length-1)?this.currentTabIndex+1:0}else{if(B=="prev"){var C=(this.currentTabIndex>0)?this.currentTabIndex-1:this.hottabspositions.length-1}}if(typeof A=="undefined"){this.cancelautorun()}this.expandtab(this.tabs[this.hottabspositions[C]])},setpersist:function(A){this.enabletabpersistence=A},setselectedClassTarget:function(A){this.selectedClassTarget=A||"link"},getselectedClassTarget:function(A){return(this.selectedClassTarget==("linkparent".toLowerCase()))?A.parentNode:A},urlparamselect:function(B){var A=window.location.search.match(new RegExp(B+"=(\\d+)","i"));return(A==null)?null:parseInt(RegExp.$1)},expandtab:function(B){var C=B.getAttribute("rel");var D=(B.getAttribute("rev"))?","+B.getAttribute("rev").replace(/\s+/,"")+",":"";this.expandsubcontent(C);this.expandrevcontent(D);for(var A=0;A<this.tabs.length;A++){this.getselectedClassTarget(this.tabs[A]).className=(this.tabs[A].getAttribute("rel")==C)?"selected":""}if(this.enabletabpersistence){ddtabcontent.setCookie(this.tabinterfaceid,B.tabposition)}this.setcurrenttabindex(B.tabposition)},expandsubcontent:function(C){for(var B=0;B<this.subcontentids.length;B++){var A=document.getElementById(this.subcontentids[B]);A.style.display=(A.id==C)?"block":"none"}},expandrevcontent:function(C){var A=this.revcontentids;for(var B=0;B<A.length;B++){document.getElementById(A[B]).style.display=(C.indexOf(","+A[B]+",")!=-1)?"block":"none"}},setcurrenttabindex:function(A){for(var B=0;B<this.hottabspositions.length;B++){if(A==this.hottabspositions[B]){this.currentTabIndex=B;break}}},autorun:function(){this.cycleit("next",true)},cancelautorun:function(){if(typeof this.autoruntimer!="undefined"){clearInterval(this.autoruntimer)}},init:function(A){var E=ddtabcontent.getCookie(this.tabinterfaceid);var D=-1;var F=this.urlparamselect(this.tabinterfaceid);this.automodeperiod=A||0;for(var C=0;C<this.tabs.length;C++){this.tabs[C].tabposition=C;if(this.tabs[C].getAttribute("rel")){var B=this;this.hottabspositions[this.hottabspositions.length]=C;this.subcontentids[this.subcontentids.length]=this.tabs[C].getAttribute("rel");this.tabs[C].onclick=function(){B.expandtab(this);B.cancelautorun();return false};if(this.tabs[C].getAttribute("rev")){this.revcontentids=this.revcontentids.concat(this.tabs[C].getAttribute("rev").split(/\s*,\s*/))}if(F==C||this.enabletabpersistence&&D==-1&&parseInt(E)==C||!this.enabletabpersistence&&D==-1&&this.getselectedClassTarget(this.tabs[C]).className=="selected"){D=C}}}if(D!=-1){this.expandtab(this.tabs[D])}else{this.expandtab(this.tabs[this.hottabspositions[0]])}if(parseInt(this.automodeperiod)>500&&this.hottabspositions.length>1){this.autoruntimer=setInterval(function(){B.autorun()},this.automodeperiod)}}};