
// Universal functions

window.defaultStatus = "";

function Over(msg) { window.status = msg;}

function Dimmer(what) { if (document.all) what.blur(); }


// REMOVES SPACES FROM STRING - formats character name to pop-window name
function subspaceA(name) {
	var badChar = /\W/g;
	var cleanName = name.replace(badChar,"");
	return cleanName;
}

// REPLACES SPACES WITH UNDERSCORES - formats character name to image name
function subspaceB(name) {
	var space = /\s/g;
	var cleanName = name.replace(space,"_");
	return cleanName;
}


var screenW		= screen.availWidth - 30;
var screenH 	= screen.availHeight - 30;
var VscrollComp	= 16;
var HscrollComp	= 16;

// do pop-up window

function Reflector(CharName,imgPath,imgType,imgWidth,imgHeight) {

	var winName 	= subspaceA(CharName);
	var imgName 	= subspaceB(CharName).toLowerCase();

	var winWidth	= parseInt(imgWidth) + 10;
	var winHeight	= parseInt(imgHeight) + 10;
	
	var scroll		= "";
	
	if (imgWidth > screenW) { 
		winWidth = screenW - 25; 
		winHeight += VscrollComp; 
		scroll = ",scrollbars"; 
	}

	if (imgHeight > screenH) { 
		winHeight = screenH - 25; 
		winWidth+= HscrollComp; 
		scroll = ",scrollbars"; 
	}

	/*
	if ((imgWidth > screenW) && (imgHeight > screenH)) {
		winWidth = screenW-50;
		winHeight = screenH-50;
		scroll = ",scrollbars";
	}
	*/

	if (imgType != "team") {

		var winURL	= "http://" + location.hostname + "/archive/focus.asp?"
					+ "CharName="	+ escape(CharName) + "&"
					+ "ImgURL="		+ escape(imgPath + imgName + "." + imgType) + "&"
					+ "imgWidth="	+ imgWidth + "&"
					+ "imgHeight="	+ imgHeight;
	
		var pop = window.open(winURL,winName,'status,top=0,left=0,width=' + winWidth + ',height=' + winHeight + scroll);

	}
	
	else {
	
		destRef = ("/archive/micromaster.asp?team=" + escape(CharName)).toString();
		setTimeout("location.href = '" + destRef + "'", 50);
		
	}
	
}


// SUB-NAVIGATION CONTROLS

var navArray = ["Autobot", "Decepticon", "Europe", "Japan", "More"];

var defaultNav = null;

function subnav(whichNav)
{
	if (defaultNav == null) defaultNav = whichNav;
	
	for (a=0; a < navArray.length; a++)
	{
		document.getElementById('cell_' + navArray[a]).style.backgroundColor = "transparent";
		document.getElementById('arrow_' + navArray[a]).style.visibility = "hidden";
		document.getElementById('divSubNav_' + navArray[a]).style.display = "none";
	}
	
	document.getElementById('cell_' + whichNav).style.backgroundColor = "#111111";
	document.getElementById('arrow_' + whichNav).style.visibility = "visible";
	document.getElementById('divSubNav_' + whichNav).style.display = "block";
}


var cancelSubnavReset = false;

function resetSubnav(e) {
	
	if (cancelSubnavReset) return;
	
	if (!e) var e = window.event;
	
	if (window.event && e.toElement.id == "archiveBodyCell")
	{
		subnav(defaultNav);
		return;
	}
	
	var tg = (window.event) ? e.srcElement : e.target;
	
	if (tg.id != 'divTeletran_InnerShell') return;
	
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	while (reltg != tg && reltg.id != 'divTeletran_OuterShell')
		reltg= reltg.parentNode
	if (reltg== tg) return;
	
	// Mouseout took place when mouse actually left layer
	// Handle event
	
	subnav(defaultNav);
}	

