function launchSite(i) {
	switch (i) {
	case 3: 
		//window.open('index3.html', 'mangetoWin3', 'width=1024,height=770,scrollbars=yes,resizable=yes');
		break;
	default:
		//window.open('index2.html', 'mangetoWin', 'width=1024,height=770,scrollbars=yes,resizable=yes');
		//document.location.href = 'index2.html';
		break;
	}
}

function hideNavs() {
	aNavs = document.getElementsByTagName('div');
	for(i=0; i<aNavs.length; i++) {
		if (aNavs[i].className.indexOf('leftNav2') > -1) {
			aNavs[i].style.visibility = 'hidden';
		}
	}
}

function switchNav(thisNav) {
	aNavs = document.getElementsByTagName('div');

	hideNavs();
	
	var navStr = '';

	switch(thisNav.id) {
	case 'nav1_magneto': 	navStr = 'magneto'; break;
	case 'nav1_latest': 	navStr = 'latest'; break;
	case 'nav1_campaigns': 	navStr = 'campaigns'; break;
	case 'nav1_product': 	navStr = 'product'; break;
	case 'nav1_contact': 	navStr = 'contact'; break;
	case 'nav1_blog': 	navStr = 'blog'; break;

default: break;
	}
	
	if (navStr.length > 0) {
		navStr += 'Nav';
		document.getElementById(navStr).style.visibility = 'visible';
	}
}

function setupPage() {
	if (window.attachEvent) { startIntro(); }
	
	aNavImgs1 = document.getElementById('leftNav').getElementsByTagName('a');
	aNavImgs2 = document.getElementById('magnetoNav').getElementsByTagName('a');
	aNavImgs3 = document.getElementById('latestNav').getElementsByTagName('a');
	aNavImgs4 = document.getElementById('campaignsNav').getElementsByTagName('a');
	aNavImgs5 = document.getElementById('productNav').getElementsByTagName('a');
	
	leftNav_setup(aNavImgs1, 'mouseover');
	leftNav_setup(aNavImgs2, 'mouseover');
	leftNav_setup(aNavImgs3, 'mouseover');
	leftNav_setup(aNavImgs4, 'mouseover');
	leftNav_setup(aNavImgs5, 'mouseover');
	
	c = document.cookie;
	if (c.indexOf('hideIntro') > -1) { hideIntro(); }
	
	//setStage('intro');
	launchPage();
	
}

function leftNav_setup(oList, thisEvent) {
	for (i=0; i<oList.length; i++) {
		thisImg = oList[i].getElementsByTagName("IMG")[0];
		if (thisImg.className == 'trunk' || thisImg.className == 'topBranch' || thisImg.className == 'bottomBranch') {}
		else {
			menuLevel = parseInt(thisImg.className.substring(5,6));
			switch (thisEvent) {
			case 'mouseover':
				if (thisImg.addEventListener) {
					thisImg.addEventListener("mouseover", leftNav_hover_on, false);
					if (menuLevel > 1) { 
						thisImg.addEventListener("mouseout", leftNav_hover_thisOff, false); 
						thisImg.addEventListener("click", leftNav_stay_on, false);
					}
				} else {
					//thisImg.attachEvent("onmouseover", leftNav_hover_on);
					//thisImg.attachEvent("onmouseout", leftNav_hover_thisOff);
					//thisImg.attachEvent("onclick", leftNav_stay_on);
					thisImg.onmouseover = leftNav_hover_on;
					if (menuLevel > 1) { 
						thisImg.onmouseout = leftNav_hover_thisOff; 
						thisImg.onclick = leftNav_stay_on;
					}
				}
				break;
			default:
				if (thisImg.addEventListener) {
					thisImg.addEventListener("click", leftNav_hover_on, false);
				} else {
					//thisImg.attachEvent("onclick", leftNav_hover_on);
					thisImg.onclick = leftNav_hover_on;
				}
				break;
			}
		}
	}
}

function remove_navClicked(thisNode) {

	aClass = thisNode.className.split(" ");
	sClass = '';
	for (j=0; j<aClass.length; j++) {
		if (aClass[j] != 'navClicked') { sClass += aClass[j]+" "; }
	}
	sClass = sClass.substr(0, sClass.length-1);
	thisNode.className = sClass;
}

function leftNav_stay_on() {
	// Unmark all elements
	aMenuItems = document.getElementsByTagName('li');
	for (i=0; i<aMenuItems.length; i++) {
		menuImg = aMenuItems[i].getElementsByTagName('img')[0];
		if (menuImg.className.indexOf('navClicked') > 0) {
			menuLevel = parseInt(menuImg.className.substring(5,6));
			switch(thisLevel) {
			case 3:
				if (menuLevel >= 2) {
					remove_navClicked(menuImg);
					leftNav_hover_off(menuImg);
				}
				break;
			case 2:
				if (menuLevel >= 2) {
					remove_navClicked(menuImg);
					leftNav_hover_off(menuImg);
				}
				break;
			default:
				if (menuLevel == 1) {
					remove_navClicked(menuImg);
					leftNav_hover_off(menuImg);
				}
				break;
			}
		}
	}
	
	// Mark this element to stay on
	thisImg = this;
	thisImg.className += " navClicked";
	
	// Handle level3 images (numbers)
	if (thisImg.className == 'level3NavImg navClicked') {
		parentImg = thisImg.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('img')[0];
		parentImg.className += " navClicked";
	}
}

function leftNav_hover_on() {
	thisImg = this;
	thisLevel = parseInt(thisImg.className.substring(5,6));
	if (thisImg.src.indexOf('_red.gif') > -1) {}
	else {
		aMenuItems = document.getElementsByTagName('li');
		for (i=0; i<aMenuItems.length; i++) {
			menuImg = aMenuItems[i].getElementsByTagName('img')[0];
			menuLevel = parseInt(menuImg.className.substring(5,6));
			switch(thisLevel) {
			case 3:
				if (menuLevel >= 2) {
					leftNav_hover_off(menuImg);
				}
				break;
			case 2:
				if (menuLevel >= 2) {
					leftNav_hover_off(menuImg);
				}
				break;
			default:
				if (menuLevel == 1) {
					leftNav_hover_off(menuImg);
				}
				break;
			}
		}
		
		thisImg.src = thisImg.src.substring(0, thisImg.src.indexOf('.gif')) + "_red.gif";
		
		if (thisImg.className == 'level3NavImg') {
			parentImg = thisImg.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('img')[0];
			if (parentImg.src.substring(parentImg.src.length-7) == "red.gif") {}
			else {
				parentImg.src = parentImg.src.substring(0, parentImg.src.indexOf('.gif')) + "_red.gif";
			}
		}
	}
}

function leftNav_hover_off(thisImg) {
	if (thisImg.src.length == 0) { return false; }
	if (thisImg.src.indexOf('_red.gif') < 0) {}
	else if (thisImg.className.indexOf('navClicked') > 0) {}
	else {
		thisImg.src = thisImg.src.substring(0, thisImg.src.indexOf('_red.gif')) + ".gif";
	}
}

function leftNav_hover_thisOff(e) {
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	
	if (e.target) { thisImg = e.target; }
	else if (e.srcElement) { thisImg = e.srcElement; }
	else { return false; }

	if (thisImg.tagName == 'IMG') {
		leftNav_hover_off(thisImg);
	}
}

function centerSite() {
	// Horizontal centering handled by CSS
	oSite = document.getElementsByTagName('body')[0];
	
	winH = (window.innerHeight) ? window.innerHeight : document.documentElement.clientHeight;
	siteH = 675;
	topMargin = (winH-siteH)/2;

	if (topMargin > 0) {
		oSite.style.marginTop = topMargin+'px';
	} else {
		oSite.style.marginTop = '10px';
	}
	
	//alert(winH+" + "+siteH+" /2 = "+topMargin);
}

window.onresize = centerSite;

function startIntro() {
	/*
	var agt=navigator.userAgent.toLowerCase();
	var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	if (is_ie) {
		aImg	= document.getElementsByTagName('img');
	
		for (i=0; i<aImg.length; i++) {
			if (aImg[i].width < 1) {
				aImg[i].src = aImg[i].src;
			}
		}
	}
	*/
	/*
	var foIntro = new FlashObject("swf/intro.swf", "intro2", "948", "675", "7", "#FFFFFF");
	foIntro.addParam("wmode", "transparent");
	foIntro.write("intro");
	*/
	//setupPage();
	centerSite();
	hideIntro();
}

function prepareIntro() {
	oIntro = document.getElementById('introBox');
	oMainBox = document.getElementById('mainBox');
	oIntro.style.backgroundColor = 'transparent';
	oMainBox.style.display = 'block';
}

function hideIntro() {
	prepareIntro();
	
	oIntro = document.getElementById('introBox');
	oBrand = document.getElementById('brandWisdomSmall');

	oIntro.style.display = "none";
	oBrand.style.display = "block";

	document.cookie = "hideIntro=true;";
}

function openBrandWisdom() {
	oWin = window.open('brandWisdom.html', 'brandWisdom', 'width=800,height=432,resizable=yes,scrollbars=no,status=no,menubar=no');
}
