//** Tab Content script v2.0- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)

function dinamods3(tabinterfaceid3){this.tabinterfaceid3=tabinterfaceid3;this.tabs=document.getElementById(tabinterfaceid3).getElementsByTagName("a");this.enabletabpersistence=true;this.hottabspositions=[];this.currentTabIndex3=0; this.subcontentid3s=[];this.revcontentids=[];this.selectedClassTarget="link";}
dinamods3.getCookie=function(Name){ 
	var re3=new RegExp(Name+"=[^;]+", "i");
	if (document.cookie.match(re3))
		return document.cookie.match(re3)[0].split("=")[1];
	return "";
}
dinamods3.setCookie=function(name, value){
	document.cookie = name+"="+value+";path=/";
}
dinamods3.prototype={
	cycleit:function(dir, autorun){
		if (dir=="next"){
			var currentTabIndex3=(this.currentTabIndex3<this.hottabspositions.length-1)? this.currentTabIndex3+1 : 0;
		}
		else if (dir=="prev"){
			var currentTabIndex3=(this.currentTabIndex3>0)? this.currentTabIndex3-1 : this.hottabspositions.length-1;
		}
		if (typeof autorun=="undefined")
			this.cancelautorun();
		this.expandtab(this.tabs[this.hottabspositions[currentTabIndex3]]);
	},
	setpersist:function(bool){
			this.enabletabpersistence=bool;
	},
	setselectedClassTarget:function(objstr){
		this.selectedClassTarget=objstr || "link";
	},
	getselectedClassTarget:function(tabref){ 
		return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref;
	},
	expandtab:function(tabref){
		var subcontentid3=tabref.getAttribute("rel");
		var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/\s+/, "")+"," : "";
		this.expandsubcontent(subcontentid3);
		this.expandrevcontent(associatedrevids);
		for (var i=0; i<this.tabs.length; i++){
			this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("rel")==subcontentid3)? "dm_selected3" : "";
		}
		if (this.enabletabpersistence)
			dinamods3.setCookie(this.tabinterfaceid3, tabref.tabposition);
		this.setcurrentTabIndex3(tabref.tabposition);

		// Google Analytics integration
		if (typeof this.autoruntimer!="undefined" && this.autoruntimer==false  && typeof(pageTracker) != 'undefined' && typeof(pageTracker._trackPageview) != 'undefined' ) {
   			pageTracker._trackPageview( tabref.getAttribute("href"));
		}
	},
	expandsubcontent:function(subcontentid3){
		for (var i=0; i<this.subcontentid3s.length; i++){
			var subcontent=document.getElementById(this.subcontentid3s[i]); 
			subcontent.style.display=(subcontent.id==subcontentid3)? "block" : "none";
		}
	},
	expandrevcontent:function(associatedrevids){
		var allrevids=this.revcontentids;
		for (var i=0; i<allrevids.length; i++){
			document.getElementById(allrevids[i]).style.display=(associatedrevids.indexOf(","+allrevids[i]+",")!=-1)? "block" : "none";
		}
	},
	setcurrentTabIndex3:function(tabposition){
		for (var i=0; i<this.hottabspositions.length; i++){
			if (tabposition==this.hottabspositions[i]){
				this.currentTabIndex3=i;
				break;
			}
		}
	},
	autorun:function(){
		this.cycleit('next', true);
	},
	cancelautorun:function(){
		if (typeof this.autoruntimer!="undefined") {
			clearInterval(this.autoruntimer);
			this.autoruntimer=false;
		}
	},
	init:function(automodeperiod,change){
		var persistedtab=dinamods3.getCookie(this.tabinterfaceid3);
		var persisterror=true;
		this.automodeperiod=automodeperiod || 0;
		for (var i=0; i<this.tabs.length; i++){
			this.tabs[i].tabposition=i;
			if (this.tabs[i].getAttribute("rel")){
				var tabinstance=this;
				this.hottabspositions[this.hottabspositions.length]=i;
				this.subcontentid3s[this.subcontentid3s.length]=this.tabs[i].getAttribute("rel");
				this.tabs[i].onclick=function(){
					 tabinstance.expandtab(this);
					 tabinstance.cancelautorun();
					 return false;
				}
				if (change==1){
					this.tabs[i].onmouseover=this.tabs[i].onclick
				}
				if (this.tabs[i].getAttribute("rev")){
					this.revcontentids=this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/));
				}
				if (this.enabletabpersistence && parseInt(persistedtab)==i || !this.enabletabpersistence && this.getselectedClassTarget(this.tabs[i]).className=="dm_selected3"){
					this.expandtab(this.tabs[i]);
					persisterror=false;
				}
			}
		}
		if (persisterror)
			this.expandtab(this.tabs[this.hottabspositions[0]]);
		if (parseInt(this.automodeperiod)>500 && this.hottabspositions.length>1){
			this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod);
		}

	}
}
