var proColor = "#447799";
var managedColor = "#999999";
var sysintegColor = "#ca082E";
var voipColor = "#aa8866";
var devColor = "#FF5050";
var inactiveTabColor = "#666666";
var inactiveTabBorder = "1px solid " + inactiveTabColor;
var activeTabBorder = "1px solid #FFFFFF";
var activeTabHeight = "17px";
var prevTab;
var activeTabColor;
var inactiveTabHeight = "16px";
var content;
var header;
var IE6 = false;

function init() {
	if (vIE() == "6") {
		IE6 = true;
		activeTabHeight = "30px";
		document.getElementById("bottomNav").style.paddingBottom = "8px";
		var img = document.getElementById("messageImg");
		img.style.position = "relative";
		img.style.left = "-3px";
	}

	header = document.getElementById('header');
	content = document.getElementById('content');

	addEvent(document.getElementById('managedTabLink'), 'mouseover', mouseoverTabLinkHandler);
	addEvent(document.getElementById('sysintegTabLink'), 'mouseover', mouseoverTabLinkHandler);
	addEvent(document.getElementById('voipTabLink'), 'mouseover', mouseoverTabLinkHandler);
	addEvent(document.getElementById('devTabLink'), 'mouseover', mouseoverTabLinkHandler);
	var tab = document.getElementById('managedTab');
	tab.content = document.getElementById('managedContent');
	tab.imgSrc = 'images/climber.jpg';
	tab.headerUrl = "url('images/managedHeader.gif')";
	activateTab(tab);
	if (IE6) {
		tab.style.position = "absolute";
		tab.style.width = "162px";
	}

   	tab = document.getElementById('sysintegTab');
	tab.content = document.getElementById('sysintegContent');
	tab.imgSrc = 'images/si.jpg';
	tab.style.marginRight = "1px";
	tab.headerUrl = "url('images/sysinteg.jpg')";
	if (IE6) {
		tab.style.position = "absolute";
		tab.style.left = "173px";
		tab.style.width = "162px";
	}

	tab = document.getElementById('voipTab');
	tab.content = document.getElementById('voipContent');
	tab.imgSrc = 'images/voip.jpg';
	tab.style.marginRight = "1px";
	tab.headerUrl = "url('images/voipheader.png')";
	if (IE6) {
		tab.style.position = "absolute";
		tab.style.left = "336px";
		tab.style.width = "162px";
	}

	tab = document.getElementById('devTab');
	tab.content = document.getElementById('devContent');
	tab.imgSrc = 'images/si.jpg';
	tab.style.marginRight = "1px";
	tab.headerUrl = "url('images/sysinteg.jpg')";
	if (IE6) {
		tab.style.position = "absolute";
		tab.style.left = "499px";
		tab.style.width = "162px";
	}
	

	var anchorNode = getLastAnchor(document.getElementById('footerLinks'));

	if (anchorNode != null) {
		anchorNode.style.borderRight = "0";
	}

	anchorNode = getLastAnchor(document.getElementById('bottomNav'));
	if (anchorNode != null) {
		anchorNode.style.borderRight = "0";
	}

}
function vIE(){
	return (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;
}

function getLastAnchor(node) {
	var anchorNode;
	if (node != null) {
		for (var i = 0; i < node.childNodes.length; i++) {
			if (node.childNodes[i].nodeName == 'A') {
				anchorNode = node.childNodes[i];
			}
		}
	}
	return anchorNode;
}

function mouseoverTabLinkHandler() {
	activateTab(this.parentNode);
}
function activateTab(activeTab) {
	if (prevTab == null || prevTab.id != activeTab.id) {
		if (prevTab != null) {
			prevTab.style.border = inactiveTabBorder;
			prevTab.style.height = inactiveTabHeight;
			prevTab.style.backgroundColor = inactiveTabColor;
			prevTab.content.style.display = "none";
		}
		prevTab = activeTab;
		activeTab.style.marginRight = "0";
		if (activeTab.id == 'managedTab') {
			document.getElementById('sysintegTab').style.marginRight = "1px";
			document.getElementById('voipTab').style.marginRight = "1px";
			document.getElementById('devTab').style.marginRight = "1px";
			activeTabColor = managedColor;
			activeTab.style.borderRight = activeTabBorder;
			activeTab.style.borderLeft = "1px solid " + activeTabColor;
		} else if (activeTab.id == 'sysintegTab') {
			document.getElementById('managedTab').style.marginRight = "0";
			document.getElementById('voipTab').style.marginRight = "1px";
			document.getElementById('devTab').style.marginRight = "1px";
			activeTabColor = sysintegColor;
			activeTab.style.borderRight = activeTabBorder;
			activeTab.style.borderLeft = activeTabBorder;
		} else if (activeTab.id == 'voipTab') {
			document.getElementById('sysintegTab').style.marginRight = "0";
			document.getElementById('managedTab').style.marginRight = "1px";
			document.getElementById('devTab').style.marginRight = "1px";
			activeTabColor = voipColor;
			activeTab.style.borderRight = activeTabBorder;
			activeTab.style.borderLeft = activeTabBorder;
		} else if (activeTab.id == 'devTab') {
			document.getElementById('sysintegTab').style.marginRight = "0";
			document.getElementById('managedTab').style.marginRight = "1px";
			document.getElementById('voipTab').style.marginRight = "1px";
			activeTabColor = devColor;
			activeTab.style.borderLeft = activeTabBorder;
			activeTab.style.borderRight = "1px solid " + activeTabColor;
		} 

		header.style.backgroundImage = activeTab.headerUrl;
		activeTab.style.borderTop = activeTabBorder;
		activeTab.style.height = activeTabHeight;
		activeTab.style.borderBottom = "1px solid " + activeTabColor;
		activeTab.style.backgroundColor = activeTabColor;
		activeTab.content.style.display = "block";
		document.getElementById("messageImg").src = activeTab.imgSrc;
		content.style.backgroundColor = activeTabColor;
	}

}

addEvent(window, 'load', init);