var ie = document.all;
var ff = !document.all && document.getElementById;

var whichExplorer = " =//= MCTekK.com Explorer";
var justmcStatus  = "closed";
var mcanimeStatus = "closed";

window.onload = function loader()
{
	ff ? objectCreator() : "";
	setVariables();
	
	dashboard.style.height = bodyHeight + "px";
	layers.style.height    = bodyHeight + "px";
	layers.style.left      = ((bodyWidth * 0.1) / 2) + "px";
	
	resize_images();
}

function objectCreator()
{
	dashboard = document.getElementById("dashboard");
	layers    = document.getElementById("layers");
}

function setVariables()
{
	bodyHeight = document.body.clientHeight;
	bodyWidth  = document.body.clientWidth;
}

function openDashboard(whichSite)
{
	closeDashboard("all");
	openBehind();
	
	switch (whichSite)
	{
		case "justmc":
			!document.getElementById("justmcWin") ? createWin("JustMC", "http://www.justmc.com/foro/") : document.getElementById("justmcWin").style.display = "block";
			justmcStatus = "open";
		break;
		
		case "mcanime":
			!document.getElementById("mcanimeWin") ? createWin("MCAnime", "http://foro.mcanime.net") : document.getElementById("mcanimeWin").style.display = "block";
			mcanimeStatus = "open";
		break;
	}
	
	setDocumentScroll("hidden");
}

function closeDashboard(whichSite)
{
	closeBehind();
	
	switch (whichSite)
	{
		case "all":
			document.getElementById("justmcWin") ? document.getElementById("justmcWin").style.display = "none" : "";
			justmcStatus = "closed";
			
			document.getElementById("mcanimeWin") ? document.getElementById("mcanimeWin").style.display = "none" : "";
			mcanimeStatus = "closed";
		break;
	}
	
	setDocumentScroll("");
}

function closeBehind()
{
	dashboard.style.display = "none";
	layers.style.display    = "none";
}

function openBehind()
{
	dashboard.style.display = "block";
	layers.style.display    = "block";
}

function setDocumentScroll(scrollValue)
{
	document.body.style.overflow = scrollValue;
}

function createWin(winTitle, winSrc)
{
	winId = winTitle.toLowerCase() + "Win";
	
	newElem(layers, "div", Array("id::" + winId));
	newElem(winId, "span", Array("innerHTML::[X]"), "", Array("onclick::closeDashboard('all')"));
	newElem(winId, "div");
		titleElement = newElement;
		newElem(titleElement, "b", Array("innerHTML::" + winTitle));
		newElem(titleElement, "i", Array("innerHTML::" + whichExplorer));
	newElem(winId, "iframe", Array("height::" + (bodyHeight - 24), "src::" + winSrc));
}

function processOnkeyup(e)
{
	ie ? key = window.event.keyCode : "";
	ff ? key = e.which : "";
	
	if (key == 27)
		closeDashboard("all");
		
	if (key == 120) // F9
		justmcStatus == "closed" ? openDashboard("justmc") : closeDashboard("all");
		
	if (key == 145) // Scroll Lock
		mcanimeStatus == "closed" ? openDashboard("mcanime") : closeDashboard("all");
}

document.onkeyup = processOnkeyup;