// <![CDATA[
 /*                   Copyright©2001 Garrett S. Smith                     	
Web: DHTMLKitchen.com                          
This code may be used without permission, for free. This copyright   
Must remain in the code. See DHTMLkitchen.com for usage instructions and terms of use.     */                                       
var MAC_IE5, IE5;
var tabs, tabArray, activeTab, relatedTab = null;
function tabInit(){ //protected
	tabs = document.getElementById('tabs');
	if ( tabs == null )
		return false;

	tabs.getElementsByClass= objectGetElementsByClass;

	var tabArray= tabs.getElementsByClass("*", "tab");
	for(var i = 0;i < tabArray.length; i++){
		tabArray[i].content=document.getElementById("content"+(i+1));
		
		// deal with any img tab.
		if(tabArray[i].tagName.toLowerCase() == "img"){
			tabArray[i].setAttribute("normalsrc", tabArray[i].src);
			tabArray.isImg= true;
			tabArray[i].setAttribute("normalsrc", tabArray[i].src);
			tabArray[i].hover= new Image();
			tabArray[i].hover.src= tabArray[i].getAttribute("hoversrc");
			tabArray[i].active= new Image();
			tabArray[i].active.src= tabArray[i].getAttribute("activesrc");
		}
		// add Event Listeners for Moz, or override any given handler for IE.
		if(tabArray[i].addEventListener){
			tabArray[i].addEventListener("mouseover", hoverTab ,false);
			tabArray[i].addEventListener("mouseout", hoverOff ,false);
			tabArray[i].addEventListener("mousedown", depressTab ,false);
		}
		else{
			tabArray[i].onmouseover= hoverTab;
			tabArray[i].onmouseout= hoverOff;
			tabArray[i].onmousedown= depressTab;
		}
			tabArray[i].depressTab= depressTab;
	}

	tabs.onchange= new Function();

	// depress tab 1.
	tabArray[0].depressTab();
	
	// Switch to a tab in the search string.
	var q = String(window.location.search);
	if(q && q.indexOf("tab=") > 0)
		switchTabs(q.substring(q.indexOf("tab=")+4,q.indexOf("tab=")+8))

	// Unsightly IE hacks saved for last. 
	if(IE5 && !IE6 && !MAC && !tabArray.isImg) tabs.style.top=(tabs.offsetTop+3)+"px";	
	if(IE5 && !IE5_5 && !IE6 && !MAC && tabArray.isImg) tabs.style.top=(tabs.offsetTop+2)+"px";	
	if(MAC_IE5) document.body.setAttribute("onunload","switchTabs('tab1')"); // odd fix for odd behavior.
 }	
	
	function switchTabs(tab,e){
		tab=document.getElementById(tab);
		tab.depressTab(e);
 		window.scrollTo(0,0);
	}
	function hoverTab() {
		if(activeTab==this) return;
		this.className= "tabHover";
		this.src= this.getAttribute("hoversrc");
	}
	function hoverOff() {
		if(activeTab==this) return;
		this.className= "tab";
		this.src= this.getAttribute("normalsrc");
	}
	function depressTab(e) {
		if(activeTab == this) return;
		relatedTab= activeTab;
		this.className= "tab";
		this.className= "tabHover";
	 	this.className= "tabActive";
		this.src= this.getAttribute("activesrc");
		if(activeTab) resetTab(activeTab);

		activeTab= this;
		tabs.onchange(e);
		setVisible(this.content);
	 	if(MAC_IE5) resizeFix();
	}
	function resetTab(tab) {
		tab.className= "tab";
		tab.className= "tabHover";
		tab.className= "tab";
		tab.src= tab.getAttribute("normalsrc");

		setVisible(tab.content,false);
	}
	function objectGetElementsByClass(tagName, className){
		var collection;
		var returnedCollection = new Array(0);
		if(document.all && tagName == "*") collection = document.all;
		else collection = this.getElementsByTagName(tagName);
		for(var i = 0, counter = 0; i < collection.length; i++){
			if(collection[i].className == className){
				returnedCollection[counter] = collection[i];
				counter++;
			}
		}
		return returnedCollection;
	}
		
	function resizeFix(){
		this.resizeBy(0,1);
		this.resizeBy(0,-1);
	}

	function setVisible(obj, bool){
		if(bool == false) obj.style.display = 'none';
		else obj.style.display = '';
	}
	

	function myFunction(e){
		// no event for IE.
		if(e) e.preventDefault();
		var target= e?("; Event.target.id= "+e.target.id) : "";
		window.status= ("activeTab= "+activeTab.id+"; relatedTab= "+relatedTab.id+ target);
		//alert("You just triggered the onchange method by clicking "+activeTab.id);
	}	
	function init(){
		tabInit();
		
		//function pointer to function myFunction().
		if ( tabs != null )
			tabs.onchange=myFunction;
	}

