+ cycleit:function(dir, autorun){ //PUBLIC function to move foward or backwards through each hot tab (tabinstance.cycleit('foward/back') )\r
+ if (dir=="next"){\r
+ var currentTabIndex=(this.currentTabIndex<this.hottabspositions.length-1)? this.currentTabIndex+1 : 0\r
+ }\r
+ else if (dir=="prev"){\r
+ var currentTabIndex=(this.currentTabIndex>0)? this.currentTabIndex-1 : this.hottabspositions.length-1\r
+ }\r
+ if (typeof autorun=="undefined") //if cycleit() is being called by user, versus autorun() function\r
+ this.cancelautorun() //stop auto cycling of tabs (if running)\r
+ this.expandtab(this.tabs[this.hottabspositions[currentTabIndex]])\r
+ },\r
+\r
+ setpersist:function(bool){ //PUBLIC function to toggle persistence feature\r
+ this.enabletabpersistence=bool\r
+ },\r
+\r
+ setselectedClassTarget:function(objstr){ //PUBLIC function to set which target element to assign "selected" CSS class ("linkparent" or "link")\r
+ this.selectedClassTarget=objstr || "link"\r
+ },\r
+\r
+ getselectedClassTarget:function(tabref){ //Returns target element to assign "selected" CSS class to\r
+ return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref\r
+ },\r
+\r
+ urlparamselect:function(tabinterfaceid){\r
+ var result=window.location.search.match(new RegExp(tabinterfaceid+"=(\\d+)", "i")) //check for "?tabinterfaceid=2" in URL\r
+ return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index\r
+ },\r
+\r
+ expandtab:function(tabref){\r
+ var subcontentid=tabref.getAttribute("rel") //Get id of subcontent to expand\r
+ //Get "rev" attr as a string of IDs in the format ",john,george,trey,etc," to easily search through\r
+ var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/\s+/, "")+"," : ""\r
+ this.expandsubcontent(subcontentid)\r
+ this.expandrevcontent(associatedrevids)\r
+ for (var i=0; i<this.tabs.length; i++){ //Loop through all tabs, and assign only the selected tab the CSS class "selected"\r
+ this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("rel")==subcontentid)? "selected" : ""\r
+ }\r
+ if (this.enabletabpersistence) //if persistence enabled, save selected tab position(int) relative to its peers\r
+ ddtabcontent.setCookie(this.tabinterfaceid, tabref.tabposition)\r
+ this.setcurrenttabindex(tabref.tabposition) //remember position of selected tab within hottabspositions[] array\r
+ },\r
+\r
+ expandsubcontent:function(subcontentid){\r
+ for (var i=0; i<this.subcontentids.length; i++){\r
+ var subcontent=document.getElementById(this.subcontentids[i]) //cache current subcontent obj (in for loop)\r
+ subcontent.style.display=(subcontent.id==subcontentid)? "block" : "none" //"show" or hide sub content based on matching id attr value\r
+ }\r
+ },\r
+\r
+ expandrevcontent:function(associatedrevids){\r
+ var allrevids=this.revcontentids\r
+ for (var i=0; i<allrevids.length; i++){ //Loop through rev attributes for all tabs in this tab interface\r
+ //if any values stored within associatedrevids matches one within allrevids, expand that DIV, otherwise, contract it\r
+ document.getElementById(allrevids[i]).style.display=(associatedrevids.indexOf(","+allrevids[i]+",")!=-1)? "block" : "none"\r
+ }\r
+ },\r
+\r
+ setcurrenttabindex:function(tabposition){ //store current position of tab (within hottabspositions[] array)\r
+ for (var i=0; i<this.hottabspositions.length; i++){\r
+ if (tabposition==this.hottabspositions[i]){\r
+ this.currentTabIndex=i\r
+ break\r
+ }\r
+ }\r
+ },\r
+\r
+ autorun:function(){ //function to auto cycle through and select tabs based on a set interval\r
+ this.cycleit('next', true)\r
+ },\r
+\r
+ cancelautorun:function(){\r
+ if (typeof this.autoruntimer!="undefined")\r
+ clearInterval(this.autoruntimer)\r
+ },\r
+\r
+ init:function(automodeperiod){\r
+ var persistedtab=ddtabcontent.getCookie(this.tabinterfaceid) //get position of persisted tab (applicable if persistence is enabled)\r
+ var selectedtab=-1 //Currently selected tab index (-1 meaning none)\r
+ var selectedtabfromurl=this.urlparamselect(this.tabinterfaceid) //returns null or index from: tabcontent.htm?tabinterfaceid=index\r
+ this.automodeperiod=automodeperiod || 0\r
+ for (var i=0; i<this.tabs.length; i++){\r
+ this.tabs[i].tabposition=i //remember position of tab relative to its peers\r
+ if (this.tabs[i].getAttribute("rel")){\r
+ var tabinstance=this\r
+ this.hottabspositions[this.hottabspositions.length]=i //store position of "hot" tab ("rel" attr defined) relative to its peers\r
+ this.subcontentids[this.subcontentids.length]=this.tabs[i].getAttribute("rel") //store id of sub content ("rel" attr value)\r
+ this.tabs[i].onclick=function(){\r
+ tabinstance.expandtab(this)\r
+ tabinstance.cancelautorun() //stop auto cycling of tabs (if running)\r
+ return false\r
+ }\r
+ if (this.tabs[i].getAttribute("rev")){ //if "rev" attr defined, store each value within "rev" as an array element\r
+ this.revcontentids=this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/))\r
+ }\r
+ if (selectedtabfromurl==i || this.enabletabpersistence && selectedtab==-1 && parseInt(persistedtab)==i || !this.enabletabpersistence && selectedtab==-1 && this.getselectedClassTarget(this.tabs[i]).className=="selected"){\r
+ selectedtab=i //Selected tab index, if found\r
+ }\r
+ }\r
+ } //END for loop\r
+ if (selectedtab!=-1) //if a valid default selected tab index is found\r
+ this.expandtab(this.tabs[selectedtab]) //expand selected tab (either from URL parameter, persistent feature, or class="selected" class)\r
+ else //if no valid default selected index found\r
+ this.expandtab(this.tabs[this.hottabspositions[0]]) //Just select first tab that contains a "rel" attr\r
+ if (parseInt(this.automodeperiod)>500 && this.hottabspositions.length>1){\r
+ this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod)\r
+ }\r
+ } //END int() function\r