//(C) Caspar Dekker
//Using parts of this file for sites other then run at the domain www.voidofspace.com is hereby not allowed 

//Show menu
function show_menu()
{
	var frame = window.frameElement;
	var menu = frame.parentNode;
	
	if(frame.getAttribute('ah') != undefined)
	{
		var size = document.getElementById('size');
		frame.style.height = size.offsetHeight;
		frame.style.width = size.offsetWidth;
		menu.style.height = size.offsetHeight;
		menu.style.width = size.offsetWidth;
		
		var vTop = parent.document.body.scrollTop + (parent.document.body.clientHeight / 2) - (document.body.scrollHeight /2);
		var vLeft = parent.document.body.scrollLeft + (parent.document.body.clientWidth / 3) - (document.body.scrollWidth /2);
		if(vTop < 0)
		{
			vTop = 0;
		}
		if(vLeft < 0)
		{
			vLeft = 0;
		}
		
		menu.style.position = "absolute";
		menu.style.top = vTop;
		menu.style.left = vLeft;
		menu.style.border = "1px solid #369";
	}
	else
	{
		frame.style.height = document.body.scrollHeight + frame.scrollTop;
		frame.style.width = document.body.scrollWidth;
		menu.style.border = "0px solid #369";
	}
	menu.style.visibility="visible";
}

function hide_menu()
{
	var frame = window.frameElement;
	var menu = frame.parentNode;
	menu.style.visibility="hidden";
}

//Open a menu
function context_menu(url)
{
	var frame = window.top.document.getElementById("context_frame");
	var menu = frame.parentNode;
	menu.style.visibility="hidden";
	frame.style.height = 1;
	frame.style.width = 1;
	menu.style.height = 1;
	menu.style.width = 1;
	frame.src = url;
}

//Close menu
function close_menu(a)
{
	a.parentNode.parentNode.style.visibility="hidden";
}

//Close menu from within popwindow
function close_within()
{
	window.frameElement.parentNode.style.visibility="hidden";
}

function queue_menu()
{
	var frame = window.frameElement;
	if(frame.style.height < 50 && document.body.scrollHeight + 18 + document.body.scrollTop > 50)
	{
		frame.style.height = document.body.scrollHeight + 18 + document.body.scrollTop;
	}
	window.document.body.scrollLeft = document.body.scrollWidth;
}

//Refresh head page
function refresh_top(url)
{
	window.top.location.replace(window.top.location.href);
 //unescape(url));
}

//Refresh head page
function replace_top(url)
{
	window.top.location.replace(unescape(url));
}

//Change top page without removing history
function change_top(url)
{
	window.top.location.href = url;
}

//Toggle colonize mode
function toggle_collonize(a)
{
	var text;
	if(document.form.option.value == '1')
	{
		text = "enable colonize";
		document.form.option.value = '0';
	}
	else
	{
		text = "disable colonize";
		document.form.option.value = '1';
	}
	a.innerHTML = text;
}

function addFlight(oname,ox,oy,or,ou,time)
{
	if(or != 0 || ou != 0)
	{
		flight[0][flight[0].length] = oname;
		flight[2][flight[2].length] = parseFloat(ox);
		flight[3][flight[3].length] = parseFloat(oy);
		flight[4][flight[4].length] = parseFloat(or);
		flight[5][flight[5].length] = parseFloat(ou);
		flight[6][flight[6].length] = parseFloat(time);
	}
}

var inTurn;
var maxTurn;

function flightControl(inTurnII, maxTurnII)
{
	inTurn = inTurnII;
	maxTurn = maxTurnII + 2;
	controlFlight();
}

function controlFlight()
{
	var obj;
	//Move all moving objects
	for(var i=0; i < flight[0].length; i++)
	{
		obj = document.getElementById(flight[0][i]);
		obj.style.left = flight[2][i] - flight[4][i] * (flight[6][i] - inTurn);
		obj.style.top = flight[3][i] - flight[5][i] * (flight[6][i] - inTurn);
		//stop movement
		if((flight[6][i] - inTurn) < 0)
		{	
			obj.style.left = flight[2][i]+5;
			obj.style.top = flight[3][i]+5;
			flight[0].splice(i,1);
			flight[1].splice(i,1);
			flight[2].splice(i,1);
			flight[3].splice(i,1);
			flight[4].splice(i,1);
			flight[5].splice(i,1);
			flight[6].splice(i,1);
		}
	}
	
	if(flight[0].length > 0)
	{
		inTurn = inTurn + 3;
		//No new turn
		if(inTurn < maxTurn)
			setTimeout("controlFlight()",3000);
		//Reload page on new turn
		else
			window.location.replace(unescape(window.location.pathname + window.location.search));
	}
}

//Count down
function addTimer(time,id)
{
	if(time > 0)
	{
		var day = Math.floor(time / 86400);
		time = time - day * 86400;
		var hour = Math.floor(time / 3600);
		time = time - hour * 3600;
		var min = Math.floor(time / 60);
		time = Math.round(time - min * 60);
		
		secs[secs.length] = time;
		mins[mins.length] = min;
		hours[hours.length] = hour;
		days[days.length] = day;
		ids[ids.length] = id;
	}
	else
	{
		disp = "N/A";
		var elm = document.getElementById(id);
		elm.innerHTML = disp;
	}
}

function countDown()
{
	for(var i=0; i < secs.length; i++)
	{
		secs[i]--;
		//Seconds from 0 to 59
		if(secs[i] < 0) 
		{
			secs[i] = 59;
			mins[i]--;
			//Minutes from 0 to 59
			if(mins[i] < 0) 
			{
				mins[i] = 59;
				hours[i]--;
			}
			//Hours from 0 to 24
			if(hours[i] < 0) 
			{
				hours[i] = 23;
				days[i]--;
			}
			//Reload page when a counter reached 0
			if(days[i] < 0)
			{
				window.location.replace(unescape(window.location.pathname + window.location.search));
			}
		}
		
		//Display format
		disp = (hours[i] < 10 ? "0" + hours[i] : hours[i]) + ":" + (mins[i] < 10 ? "0" + mins[i] : mins[i]) + ":" + (secs[i] < 10 ? "0" + secs[i] : secs[i]) + (days[i] == 0 ? "" : " and " + days[i] + " day(s)");
		var elm = document.getElementById(ids[i]);
		elm.innerHTML = disp;
	}
	//Stop when not needed
	if(secs.length > 0)
		setTimeout(countDown,1000);
}

//Some variables
var secs = new Array();
var mins = new Array();
var hours = new Array();
var days = new Array();
var ids = new Array();
var flight = new Array(new Array, new Array, new Array, new Array, new Array, new Array, new Array);

//Google settings
google_ad_client = "pub-9994626491843573";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "image";
google_color_border = "312e3d";
google_color_bg = "131119";
google_color_link = "a9e1e9";
google_color_text = "ffffff";
google_color_url = "b9e1e9";