
// --- tabmenu.js ---

/* 1 (1) */ 	//** Tab Content script v2.0- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
/* 2 (2) */ 	//** Updated Oct 7th, 07 to version 2.0. Contains numerous improvements:
/* 3 (3) */ 	//   -Added Auto Mode: Script auto rotates the tabs based on an interval, until a tab is explicitly selected
/* 4 (4) */ 	//   -Ability to expand/contract arbitrary DIVs on the page as the tabbed content is expanded/ contracted
/* 5 (5) */ 	//   -Ability to dynamically select a tab either based on its position within its peers, or its ID attribute (give the target tab one 1st)
/* 6 (6) */ 	//   -Ability to set where the CSS classname "selected" get assigned- either to the target tab's link ("A"), or its parent container
/* 7 (7) */ 	//** Updated Feb 18th, 08 to version 2.1: Adds a "tabinstance.cycleit(dir)" method to cycle forward or backward between tabs dynamically
/* 8 (8) */ 	//** Updated April 8th, 08 to version 2.2: Adds support for expanding a tab using a URL parameter (ie: http://mysite.com/tabcontent.htm?tabinterfaceid=0) 
/* 9 (9) */ 	
/* 10 (10) */ 	////NO NEED TO EDIT BELOW////////////////////////
/* 11 (11) */ 	
/* 12 (12) */ 	function ddtabcontent(tabinterfaceid){
/* 13 (13) */ 		this.tabinterfaceid=tabinterfaceid //ID of Tab Menu main container
/* 14 (14) */ 		this.tabs=document.getElementById(tabinterfaceid).getElementsByTagName("a") //Get all tab links within container
/* 15 (15) */ 		this.enabletabpersistence=true
/* 16 (16) */ 		this.hottabspositions=[] //Array to store position of tabs that have a "rel" attr defined, relative to all tab links, within container
/* 17 (17) */ 		this.currentTabIndex=0 //Index of currently selected hot tab (tab with sub content) within hottabspositions[] array
/* 18 (18) */ 		this.subcontentids=[] //Array to store ids of the sub contents ("rel" attr values)
/* 19 (19) */ 		this.revcontentids=[] //Array to store ids of arbitrary contents to expand/contact as well ("rev" attr values)
/* 20 (20) */ 		this.selectedClassTarget="link" //keyword to indicate which target element to assign "selected" CSS class ("linkparent" or "link")
/* 21 (21) */ 	}
/* 22 (22) */ 	
/* 23 (23) */ 	ddtabcontent.getCookie=function(Name){ 
/* 24 (24) */ 		var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
/* 25 (25) */ 		if (document.cookie.match(re)) //if cookie found
/* 26 (26) */ 			return document.cookie.match(re)[0].split("=")[1] //return its value
/* 27 (27) */ 		return ""
/* 28 (28) */ 	}
/* 29 (29) */ 	
/* 30 (30) */ 	ddtabcontent.setCookie=function(name, value){
/* 31 (31) */ 		document.cookie = name+"="+value+";path=/" //cookie value is domain wide (path=/)
/* 32 (32) */ 	}
/* 33 (33) */ 	
/* 34 (34) */ 	ddtabcontent.prototype={
/* 35 (35) */ 	
/* 36 (36) */ 		expandit:function(tabid_or_position){ //PUBLIC function to select a tab either by its ID or position(int) within its peers
/* 37 (37) */ 			this.cancelautorun() //stop auto cycling of tabs (if running)
/* 38 (38) */ 			var tabref=""
/* 39 (39) */ 			try{
/* 40 (40) */ 				if (typeof tabid_or_position=="string" && document.getElementById(tabid_or_position).getAttribute("rel")) //if specified tab contains "rel" attr
/* 41 (41) */ 					tabref=document.getElementById(tabid_or_position)
/* 42 (42) */ 				else if (parseInt(tabid_or_position)!=NaN && this.tabs[tabid_or_position].getAttribute("rel")) //if specified tab contains "rel" attr
/* 43 (43) */ 					tabref=this.tabs[tabid_or_position]
/* 44 (44) */ 			}
/* 45 (45) */ 			catch(err){alert("Invalid Tab ID or position entered!")}
/* 46 (46) */ 			if (tabref!="") //if a valid tab is found based on function parameter
/* 47 (47) */ 				this.expandtab(tabref) //expand this tab
/* 48 (48) */ 		},
/* 49 (49) */ 	
/* 50 (50) */ 		cycleit:function(dir, autorun){ //PUBLIC function to move foward or backwards through each hot tab (tabinstance.cycleit('foward/back') )
/* 51 (51) */ 			if (dir=="next"){
/* 52 (52) */ 				var currentTabIndex=(this.currentTabIndex<this.hottabspositions.length-1)? this.currentTabIndex+1 : 0
/* 53 (53) */ 			}
/* 54 (54) */ 			else if (dir=="prev"){
/* 55 (55) */ 				var currentTabIndex=(this.currentTabIndex>0)? this.currentTabIndex-1 : this.hottabspositions.length-1
/* 56 (56) */ 			}
/* 57 (57) */ 			if (typeof autorun=="undefined") //if cycleit() is being called by user, versus autorun() function
/* 58 (58) */ 				this.cancelautorun() //stop auto cycling of tabs (if running)
/* 59 (59) */ 			this.expandtab(this.tabs[this.hottabspositions[currentTabIndex]])
/* 60 (60) */ 		},
/* 61 (61) */ 	
/* 62 (62) */ 		setpersist:function(bool){ //PUBLIC function to toggle persistence feature
/* 63 (63) */ 				this.enabletabpersistence=bool
/* 64 (64) */ 		},
/* 65 (65) */ 	
/* 66 (66) */ 		setselectedClassTarget:function(objstr){ //PUBLIC function to set which target element to assign "selected" CSS class ("linkparent" or "link")
/* 67 (67) */ 			this.selectedClassTarget=objstr || "link"
/* 68 (68) */ 		},
/* 69 (69) */ 	
/* 70 (70) */ 		getselectedClassTarget:function(tabref){ //Returns target element to assign "selected" CSS class to
/* 71 (71) */ 			return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref
/* 72 (72) */ 		},
/* 73 (73) */ 	
/* 74 (74) */ 		urlparamselect:function(tabinterfaceid){
/* 75 (75) */ 			var result=window.location.search.match(new RegExp(tabinterfaceid+"=(\\d+)", "i")) //check for "?tabinterfaceid=2" in URL
/* 76 (76) */ 			return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index
/* 77 (77) */ 		},
/* 78 (78) */ 	
/* 79 (79) */ 		expandtab:function(tabref){
/* 80 (80) */ 			var subcontentid=tabref.getAttribute("rel") //Get id of subcontent to expand
/* 81 (81) */ 			//Get "rev" attr as a string of IDs in the format ",john,george,trey,etc," to easily search through
/* 82 (82) */ 			var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/\s+/, "")+"," : ""
/* 83 (83) */ 			this.expandsubcontent(subcontentid)
/* 84 (84) */ 			this.expandrevcontent(associatedrevids)
/* 85 (85) */ 			for (var i=0; i<this.tabs.length; i++){ //Loop through all tabs, and assign only the selected tab the CSS class "selected"
/* 86 (86) */ 				this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("rel")==subcontentid)? "selected" : ""
/* 87 (87) */ 			}
/* 88 (88) */ 			if (this.enabletabpersistence) //if persistence enabled, save selected tab position(int) relative to its peers
/* 89 (89) */ 				ddtabcontent.setCookie(this.tabinterfaceid, tabref.tabposition)
/* 90 (90) */ 			this.setcurrenttabindex(tabref.tabposition) //remember position of selected tab within hottabspositions[] array
/* 91 (91) */ 		},
/* 92 (92) */ 	
/* 93 (93) */ 		expandsubcontent:function(subcontentid){
/* 94 (94) */ 			for (var i=0; i<this.subcontentids.length; i++){
/* 95 (95) */ 				var subcontent=document.getElementById(this.subcontentids[i]) //cache current subcontent obj (in for loop)
/* 96 (96) */ 				subcontent.style.display=(subcontent.id==subcontentid)? "block" : "none" //"show" or hide sub content based on matching id attr value
/* 97 (97) */ 			}
/* 98 (98) */ 		},
/* 99 (99) */ 	
/* 100 (100) */ 		expandrevcontent:function(associatedrevids){
/* 101 (101) */ 			var allrevids=this.revcontentids
/* 102 (102) */ 			for (var i=0; i<allrevids.length; i++){ //Loop through rev attributes for all tabs in this tab interface
/* 103 (103) */ 				//if any values stored within associatedrevids matches one within allrevids, expand that DIV, otherwise, contract it
/* 104 (104) */ 				document.getElementById(allrevids[i]).style.display=(associatedrevids.indexOf(","+allrevids[i]+",")!=-1)? "block" : "none"
/* 105 (105) */ 			}
/* 106 (106) */ 		},
/* 107 (107) */ 	
/* 108 (108) */ 		setcurrenttabindex:function(tabposition){ //store current position of tab (within hottabspositions[] array)
/* 109 (109) */ 			for (var i=0; i<this.hottabspositions.length; i++){
/* 110 (110) */ 				if (tabposition==this.hottabspositions[i]){
/* 111 (111) */ 					this.currentTabIndex=i
/* 112 (112) */ 					break
/* 113 (113) */ 				}
/* 114 (114) */ 			}
/* 115 (115) */ 		},
/* 116 (116) */ 	
/* 117 (117) */ 		autorun:function(){ //function to auto cycle through and select tabs based on a set interval
/* 118 (118) */ 			this.cycleit('next', true)
/* 119 (119) */ 		},
/* 120 (120) */ 	
/* 121 (121) */ 		cancelautorun:function(){
/* 122 (122) */ 			if (typeof this.autoruntimer!="undefined")
/* 123 (123) */ 				clearInterval(this.autoruntimer)
/* 124 (124) */ 		},
/* 125 (125) */ 	
/* 126 (126) */ 		init:function(automodeperiod){
/* 127 (127) */ 			var persistedtab=ddtabcontent.getCookie(this.tabinterfaceid) //get position of persisted tab (applicable if persistence is enabled)
/* 128 (128) */ 			var selectedtab=-1 //Currently selected tab index (-1 meaning none)
/* 129 (129) */ 			var selectedtabfromurl=this.urlparamselect(this.tabinterfaceid) //returns null or index from: tabcontent.htm?tabinterfaceid=index
/* 130 (130) */ 			this.automodeperiod=automodeperiod || 0
/* 131 (131) */ 			for (var i=0; i<this.tabs.length; i++){
/* 132 (132) */ 				this.tabs[i].tabposition=i //remember position of tab relative to its peers
/* 133 (133) */ 				if (this.tabs[i].getAttribute("rel")){
/* 134 (134) */ 					var tabinstance=this
/* 135 (135) */ 					this.hottabspositions[this.hottabspositions.length]=i //store position of "hot" tab ("rel" attr defined) relative to its peers
/* 136 (136) */ 					this.subcontentids[this.subcontentids.length]=this.tabs[i].getAttribute("rel") //store id of sub content ("rel" attr value)
/* 137 (137) */ 					this.tabs[i].onclick=function(){
/* 138 (138) */ 						tabinstance.expandtab(this)
/* 139 (139) */ 						tabinstance.cancelautorun() //stop auto cycling of tabs (if running)
/* 140 (140) */ 						return false
/* 141 (141) */ 					}
/* 142 (142) */ 					if (this.tabs[i].getAttribute("rev")){ //if "rev" attr defined, store each value within "rev" as an array element
/* 143 (143) */ 						this.revcontentids=this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/))
/* 144 (144) */ 					}
/* 145 (145) */ 					if (selectedtabfromurl==i || this.enabletabpersistence && selectedtab==-1 && parseInt(persistedtab)==i || !this.enabletabpersistence && selectedtab==-1 && this.getselectedClassTarget(this.tabs[i]).className=="selected"){
/* 146 (146) */ 						selectedtab=i //Selected tab index, if found
/* 147 (147) */ 					}
/* 148 (148) */ 				}
/* 149 (149) */ 			} //END for loop
/* 150 (150) */ 			if (selectedtab!=-1) //if a valid default selected tab index is found
/* 151 (151) */ 				this.expandtab(this.tabs[selectedtab]) //expand selected tab (either from URL parameter, persistent feature, or class="selected" class)
/* 152 (152) */ 			else //if no valid default selected index found
/* 153 (153) */ 				this.expandtab(this.tabs[this.hottabspositions[0]]) //Just select first tab that contains a "rel" attr
/* 154 (154) */ 			if (parseInt(this.automodeperiod)>500 && this.hottabspositions.length>1){
/* 155 (155) */ 				this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod)
/* 156 (156) */ 			}
/* 157 (157) */ 		} //END int() function
/* 158 (158) */ 	
/* 159 (159) */ 	} //END Prototype assignment