// HARRY POTTER FAIRYLAND 14.0

var pageSignature = "index";
var idleTime = 0;
var idleCounter;
var mainPageURL = "home/website/start.php";
var edgeHeight = 150;

window.onresize = function() {
	mframeResize();
};

window.onmouseover = function() {
	resetIdle();
};

//****************XMLHTTP Object*******************
var onlineStatRequest = false;
try {
	onlineStatRequest = new XMLHttpRequest();
} catch (trymicrosoft) {
	try {
		onlineStatRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (othermicrosoft) {
		try {
			onlineStatRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (failed) {
			onlineStatRequest = false;
		}
	}
}

//*******************Functions**********************
//-------------------Online Status-----------------------
function getOnlineUsr() {
	var url = "/home/application/home/server/onlineCount.php";
	request.open("GET", url, true);
	request.onreadystatechange = updatePage;
	request.send(null);
}

function updatePage() {
	if (request.readyState == 4) {
		if (request.status == 200) {
			var response = request.responseText;
			document.getElementById('onlineCount').innerHTML = response;
			setTimeout("getOnlineUsr()",40000);
		}
	}
}

//----------------Window Resize Adjustment---------------
function mframeResize() {
	var innerHeight = (document.all) ? document.body.offsetHeight : window.innerHeight;
	var innerWidth = (document.all) ? document.body.offsetWidth : window.innerWidth;
	
	$("#mainFrame").height(innerHeight - edgeHeight);
}

//-----------------Top Layout Adjustment-----------------
function topLayoutMinimize() {
	edgeHeight = 15;
	var innerHeight = (document.all) ? document.body.offsetHeight : window.innerHeight;
	
	$("#personalBar").fadeOut(200, function() {
		$("#topLayout").slideUp(500);
		$("#topBackground").slideUp(500);
		$("#topLogo").slideUp(500);
		$("#topFrame").slideUp(500);
		$("#mainFrame").animate({ height: innerHeight - edgeHeight}, 500);
	});
	
	document.getElementById('toggleTopLayout').onclick = topLayoutExpand;
}

function topLayoutExpand() {
	edgeHeight = 150;
	var innerHeight = (document.all) ? document.body.offsetHeight : window.innerHeight;
	
	$("#mainFrame").animate({ height: innerHeight - edgeHeight}, 500);
	$("#topLayout").slideDown(500);
	$("#topBackground").slideDown(500);
	$("#topLogo").slideDown(500);
	$("#topFrame").slideDown(500, function() {
		$("#personalBar").fadeIn(200);
	});	
	
	document.getElementById('toggleTopLayout').onclick = topLayoutMinimize;
}

//----------------Main Menu Controls----------------------
function mmenuOver(obj) {
	obj.className = "mmenu_on";
}

function mmenuOut(obj) {
	obj.className = "mmenu_normal";
}

function mmenuGoTo(num) {
	var locaterArray = new Array();
	locaterArray[0] = "home/online/forum/entrance.php";
	locaterArray[1] = "home/online/greathall.php";
	locaterArray[2] = "home/news/overview.php";
	locaterArray[3] = "home/website/sections/zone_movie/index.html";
	
	document.getElementById('mainFrame').src = locaterArray[num];
}

//-------------------URL Navigator--------------------------
function initFrame() {
	if (window.location.hash.indexOf("#!/") > -1) {
		var localPage = window.location.hash.toString();
		localPage = localPage.replace("#!/", "");
		document.getElementById('mainFrame').src = localPage;
	}
}

function getFrameLocation() {
	if (window.frames['mainFrame']) {
		var localPage = window.frames['mainFrame'].location;
	} else {
		var localPage = mainFrame.location.toString();
	}
	localPage = localPage.replace("http://www.hpfl.net/", "");
	
	if (window.location.hash.indexOf("#!/") > -1) {
		var hashPage = window.location.hash.toString();
		hashPage = hashPage.replace("#!/", "");
		
	}
	
	//if (hashPage != localPage) {
		if (localPage == mainPageURL) {
			//alert(localPage);
			window.location.replace("http://www.hpfl.net/newIndex.php#");
		} else {
			//alert(localPage);
			window.location.replace("http://www.hpfl.net/newIndex.php#!/" + localPage);
		}
	//}
}

//------------------System Routine--------------------------
function resetIdle() {
	idleTime = 0;
}

function gainIdle() {
	idleTime++;
	document.getElementById('onlineCount').innerHTML = idleTime;
}

function idleCount() {
	idleCounter = setInterval(gainIdle, 1000);
}

//---------------Miscellcious Buttons-----------------------
function goBackHome() {
	document.getElementById('mainFrame').src = mainPageURL;
}
