slideSpeed = 10;
tabIdToSlideDown = null;
visibleTabId = null;
slideInProgress = false;
rotationInProgress = false;
onMouseOverTimer = null;
slideRotateTimer = null;

function toggleContent(e, tabId) {
	if(slideRotateTimer) {
		clearTimeout(slideRotateTimer);
		slideRotateTimer  = null;
	}
	if(onMouseOverTimer) {
		clearTimeout(onMouseOverTimer);
		onMouseOverTimer  = null;
	}
	if(slideInProgress) return;
	slideInProgress = true;
	if(!tabId) tabId = this.id;
	var tabNumber = tabId.substring(6);
	var container = document.getElementById("slide_container_" + tabNumber);

	tabIdToSlideDown = null;

	if(!container.style.display || container.style.display == "none") {
		if(visibleTabId != null && visibleTabId != tabNumber) {
			tabIdToSlideDown = tabNumber;
			slideContent(visibleTabId, (slideSpeed*-1));
		} else {
			with(container.style) {
				display = "block";
				visibility = "visible";
			}
			slideContent(tabNumber,slideSpeed);
		}
	} else {
		slideContent(tabNumber, (slideSpeed*-1));
		visibleTabId = null;
	}
}

function toggleContentWithTimerOn(e) {
	if(onMouseOverTimer) {
		clearTimeout(onMouseOverTimer);
		onMouseOverTimer  = null;
	}
	if(slideInProgress) return;
	var tabNumber = this.id.substring(6);
	var container = document.getElementById("slide_container_" + tabNumber);
	if(!container.style.display || container.style.display == "none") {
		onMouseOverTimer = setTimeout("document.getElementById('slide_" + tabNumber + "').onclick();",500);
	}
}

function toggleContentWithTimerOff(e) {
	if(onMouseOverTimer) {
		clearTimeout(onMouseOverTimer);
		onMouseOverTimer  = null;
	}
}

function slideContent(tabId, direction) {
	var container = document.getElementById("slide_container_" + tabId);
	var content = document.getElementById("slide_content_" + tabId);
	var height = container.clientHeight;
	if(height == 0) height = container.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height > content.offsetHeight){
		height = content.offsetHeight;
		rerunFunction = false;
	}
	if(height <= 1){
		height = 1;
		rerunFunction = false;
	}

	// if safari, need to resize flash to fix bug in safari
	var userAgent = navigator.userAgent.toLowerCase();
	if(userAgent.indexOf("safari") >= 0 || userAgent.indexOf("linux") >= 0) {
		var divs = content.getElementsByTagName("DIV");
		for(var i = 0; i < divs.length; i++) {
			if(divs[i].className == "flashobj") {
				divs[i].style.visibility = (rerunFunction) ? "hidden" : "visible";
				break;
			}
		}
	}

	container.style.height = height + "px";
	var topPos = height - content.offsetHeight;
	if(topPos > 0) topPos = 0;
	content.style.top = "0px";
	if(rerunFunction) {
		setTimeout("slideContent(" + tabId + "," + direction + ")",10);
		document.getElementById("slide_"+tabId).className = "slide-tab-selected";
	}
	else {
		if(height <= 1){
			container.style.display = "none"; 
			if(tabIdToSlideDown != null && tabIdToSlideDown != tabId){
				with(document.getElementById("slide_container_" + tabIdToSlideDown).style) {
					display = "block";
					visibility = "visible";
				}
				slideContent(tabIdToSlideDown,slideSpeed);
			}
			else slideInProgress = false;
			document.getElementById("slide_"+tabId).className = "slide-tab";
		} else {
			visibleTabId = tabId;
			slideInProgress = false;
		}
	}
}

function slideToNextTab() {
	if(slideInProgress || visibleTabId == null) return;
	var tabNumber = visibleTabId+1;
	var nextSlideTab = document.getElementById("slide_"+tabNumber);
	if(nextSlideTab) {
		nextSlideTab.onclick();
		slideRotateTimer = setTimeout("slideToNextTab();",rotateSlideTimer*1000);
	}
	else {
		// no more tabs, so stop rotating and stay on last tab
		clearTimeout(slideRotateTimer);
		slideRotateTimer  = null;
	}
}

var preSlideOnload = window.onload;
window.onload = function() {
	var slideTabs = document.getElementById("slide-tabs");
	if(!slideTabs) return;
	var divs = slideTabs.getElementsByTagName("DIV");
	var tabs = new Array();
	var tabCount = 0;
	for(var i=0; i < divs.length; i++) {
		if(divs[i].className == "slide-tab") {
			var tab = divs[i];
			tab.onclick = toggleContent;
			tab.onmouseover = toggleContentWithTimerOn;
			tab.onmouseout = toggleContentWithTimerOff;
			tab.id = "slide_" + tabCount;

			var container = tab.nextSibling;
			while(container && container.tagName != "DIV") container = container.nextSibling;
			container.id = "slide_container_" + tabCount;

			var content = container.getElementsByTagName("DIV")[0];
			content.style.top = 0 - content.offsetHeight + "px"; 
			content.id = "slide_content_" + tabCount;

			container.style.display = "none";
			container.style.height = "1px";
			tabs[tabs.length] = tab;
			tabCount++;
		}
	}
	var startTab = getQueryParm('tab');
	if(!startTab) tabs[0].onclick();
	else tabs[startTab].onclick();
	if(preSlideOnload) preSlideOnload();
	if(typeof rotateSlideTimer != "undefined") {
		slideRotateTimer = setTimeout("slideToNextTab();",rotateSlideTimer*1000);
	}
}

