<!--
//////////////////////////////////
// Advanced graphics script
///////////
// Used to draw lines, etc

function line (X1, Y1, X2, Y2, Z, THICKNESS, COLOUR, PARENT) {
	//Creates a div and rotates it. Returns a handle of the element
	var ELEMENT = document.createElement('div');
	ELEMENT.setAttribute('class','absolutePosition');
	if (PARENT == -1)
		document.body.appendChild(ELEMENT);
	else
		document.getElementById(PARENT).appendChild(ELEMENT);

	//Position it
	var length = Math.sqrt((Y2-Y1)*(Y2-Y1) + (X2-X1)*(X2-X1));
	var angle  = Math.atan2(Y2-Y1,X2-X1);
	ELEMENT.style.position = 'absolute';
	ELEMENT.style.left = (X1 - 0.5*length*(1-Math.cos(angle)) - THICKNESS/2) + 'px';
	ELEMENT.style.top  = (Y1 + 0.5*length*Math.sin(angle) - THICKNESS/2) + 'px';
	ELEMENT.style.width = length + 'px';
	ELEMENT.style.height = THICKNESS + 'px';
	ELEMENT.style.zIndex = Z;
	
	//Colour it
	ELEMENT.style.backgroundColor = '#'+COLOUR;
	
	//Rotate it
	ELEMENT.style.MozTransform = ELEMENT.style.WebkitTransform = ELEMENT.style.OTransform = ELEMENT.style.transform = 'rotate(' + angle + 'rad)';
	return ELEMENT;
	}
	
function lineTag (X1, Y1, X2, Y2, Z, THICKNESS, COLOUR) {
	//Creates a rotated div in the form of a tag, for use with drawing national borders
	var length = Math.sqrt((Y2-Y1)*(Y2-Y1) + (X2-X1)*(X2-X1));
	var angle  = Math.atan2(Y2-Y1,X2-X1);
		
	var HTMLSA = '<div class = "absolutePosition" style = "left: '+(X1-0.5*length*(1-Math.cos(angle))-THICKNESS/2)+'px; top: '+(Y1+0.5*length*Math.sin(angle)-THICKNESS/2)+'px; width: '+length+'px; height: '+THICKNESS+'px; background-color: #'+COLOUR+'; z-index: '+Z+'; ';
	
	//Rotate it
	var ANGLESTR = 'rotate(' + angle + 'rad)';
	HTMLSA += '-moz-transform: '+ANGLESTR+'; -webkit-transform: '+ANGLESTR+'; -o-transform: '+ANGLESTR+'; transform: '+ANGLESTR+';'
	
	//Close the tag	
	HTMLSA += ';"></div>';
	
	//Spit it out
	return HTMLSA;
	}
	
///////////////////////////
// Arrows
function Arrow (START_X, START_Y, END_X, END_Y, _Z, THICKNESS, COLOUR, PARENT, HEAD_LENGTH) {
	// Create with new Arrow ()
	/*
	var arrowLine;
	var arrowHeadLine1;
	var arrowHeadLine2;
	*/
	this.parent = document.getElementById(PARENT);
	
	//Create the line
	this.arrowLine = line(START_X, START_Y, END_X, END_Y, _Z, THICKNESS, COLOUR, PARENT);
	
	//The head is made of 2 more lines
	var angle = Math.atan2(END_Y-START_Y,END_X-START_X);
	
    this.arrowHeadLine1 = line (END_X - THICKNESS * 0.5 * Math.cos(angle + Math.PI*(3/4)), END_Y - THICKNESS * 0.5 * Math.sin(angle + Math.PI*(3/4)), END_X + (HEAD_LENGTH) * Math.cos(angle + Math.PI*(3/4)), END_Y + (HEAD_LENGTH) * Math.sin(angle + Math.PI*(3/4)), _Z,THICKNESS, COLOUR, PARENT);
    this.arrowHeadLine2 = line (END_X - THICKNESS * 0.5 * Math.cos(angle - Math.PI*(3/4)), END_Y - THICKNESS * 0.5 * Math.sin(angle - Math.PI*(3/4)), END_X + (HEAD_LENGTH) * Math.cos(angle - Math.PI*(3/4)), END_Y + (HEAD_LENGTH) * Math.sin(angle - Math.PI*(3/4)), _Z,THICKNESS, COLOUR, PARENT);
    
	this.destroy = function () {
		this.parent.removeChild(this.arrowLine);
		this.parent.removeChild(this.arrowHeadLine1);
		this.parent.removeChild(this.arrowHeadLine2);
		}
		
	this.hide = function () {
		this.arrowLine.style.display = 'none';
		this.arrowHeadLine1.style.display = 'none';
		this.arrowHeadLine2.style.display = 'none';
		}	
			
	this.show = function () {
		this.arrowLine.style.display = 'block';
		this.arrowHeadLine1.style.display = 'block';
		this.arrowHeadLine2.style.display = 'block';
		}
	}
	
////////////////////////////
// Misc functions

function darken(COLOUR) {
	//Halves the rgb values of a given funciton
	var red   = dechex(Math.floor(hexdec(''+COLOUR[0]+COLOUR[1])*0.5));
	var green = dechex(Math.floor(hexdec(''+COLOUR[2]+COLOUR[3])*0.5));
	var blue  = dechex(Math.floor(hexdec(''+COLOUR[4]+COLOUR[5])*0.5));
	if (red.length == 1) red = '0'+red;
	if (green.length == 1) green = '0'+green;
	if (blue.length == 1) blue = '0'+blue;
	return ''+red+green+blue;
	}

function padhex(hex) {
	if (hex.length == 1)
		hex = '0'+hex;
	return hex;
	}

function dechex(N) {
    return N.toString(16);
    }
function hexdec(N) {
    return parseInt(N,16);
    } 

/////////////////////////
// RENDER HEADER - Makes the top header bar for the game

LOAD_TIME = 0;
NEXT_UPDATE = 0;

function setUpdateString() {
	var HTMLS = '';
	HTMLS = 'Next update: ';
	var DELTAT = NEXT_UPDATE-LOAD_TIME;
	if (DELTAT <= 0) {
		HTMLS += '<a href = "'+SITE+'main_g.php#update">Now!</a>';
		}
	else {
		var h = Math.floor(DELTAT / 3600);
		var m = Math.floor((DELTAT - h*3600) / 60);
		var s = DELTAT - h*3600 - m*60;
		if (s < 10)
			s = '0'+s;
		if (m < 10)
			m = '0'+m
		HTMLS += h+'h '+m+'m '+s+'s ';
		}
	document.getElementById('updateString').innerHTML = HTMLS;
	LOAD_TIME++;
	}

function renderHeader (GAME_ID,COUNTRY_ID,FACTION,MAP_MODE,NEW_MESSAGES,IS_MOD,_LOAD_TIME,_NEXT_UPDATE) {
	//Draws the menu and the header
	var E = document.getElementById('headerDiv');
	var HTMLS = '';
	
	if (_LOAD_TIME && _NEXT_UPDATE && GAME_ID >= 0) {
		LOAD_TIME = _LOAD_TIME - 1; //this is incremented on generation of the initial string
		NEXT_UPDATE = _NEXT_UPDATE;
		setInterval('setUpdateString()',1000);
		}
	
	//Header structure is a 88px image bar with a row underneath for the menu.
	HTMLS += '<div class = "header_container">';
	
	HTMLS += '<img src = "'+IMG+'sprites/headerBack.png" class = "absolutePosition">';
	HTMLS += '<img src = "'+IMG+'sprites/header.png" class = "header_img">';
	
	if (GAME_ID != -2) {					
		//Help
		HTMLS += '<div class = "absolutePosition" style = "right: 1em; top: 0px; z-index: 9999">';

		//New messages
		if (NEW_MESSAGES){
			HTMLS += '<a href="'+SITE+'inbox.php"><i>You have <b>'+NEW_MESSAGES+'</b> new message';
			if (NEW_MESSAGES > 1)
				HTMLS += 's';
			HTMLS += '!</i></a>&nbsp;|&nbsp;';
			}
					
		//Update string
		if (_LOAD_TIME && _NEXT_UPDATE && GAME_ID >= 0) {
			HTMLS += '<span class = "updateString" id = "updateString"></span>&nbsp;| ';
			}
		
		//Admin
		if (IS_MOD)
			HTMLS += '<a href = "'+SITE+'admin.php">Admin</a> | ';
		HTMLS += '<a href = "'+SITE+'help.php">Help?</a></div>';
		}

	HTMLS += '<div class = "menu_container">';
	
	var T = 0;
	if (GAME_ID >= 0) {
		// For anyone snooping this code for a good idea for dropdown menu code,
		// google "Suckfish Dropdowns" as that is what this is based on
		// http://www.htmldog.com/articles/suckerfish/dropdowns/
		
		HTMLS += '<ul id = "nav">';
		//Game menu
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'gameinfo.php">Game'+GAME_ID)+'</a><ul>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'gameEvents.php">Game Events</a>')+'</li>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'worldmap.php">World Map</a>')+'</li>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'main.php">Exit to Home</a>')+'</li>';
		HTMLS += '</ul></li>';
		//Main
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'main_g.php">Main</a>')+'</li>';
		//Messages
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'inbox.php">Messages ['+NEW_MESSAGES+']</a>')+'</li>';
		//Map
		if (MAP_MODE)
			HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'province.php">Province</a>')+'<ul>';
		else
			HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'map.php">Map</a>')+'<ul>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'map.php?size=5">Map (Small)</a>')+'</li>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'map.php?size=7">Map (Medium)</a>')+'</li>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'map.php?size=10">Map (Large)</a>')+'</li>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'province.php">Province</a>')+'</li>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'worldmap.php">World Map</a>')+'</li>';
		HTMLS += '</ul></li>';		
		//Production
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'production.php">Production</a>')+'<ul>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'production.php">At Cities/Bases</a>')+'</li>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'production.php?atunit=1">On Units</a>')+'</li>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'tech.php">Tech</a>')+'</li>';
		HTMLS += '</ul></li>';
		//Information
		HTMLS += '<li>'+getValignDiv('Information')+'<ul>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'units.php">Units</a>')+'</li>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'allunittypes.php">All Unit Types</a>')+'</li>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'clawtab.php">Scheduled Missions</a>')+'</li>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'battleEvents.php">Battle Events</a>')+'</li>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'diplomaticEvents.php">Diplomatic Events</a>')+'</li>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'alliance.php">Alliances</a>')+'</li>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'country.php">Countries</a>')+'</li>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'territory.php">Territories</a>')+'</li>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'players.php">Players</a>')+'</li>';
		HTMLS += '</ul></li>';
		//Exit
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'main.php">Exit to Home</a>')+'</li>';
		//Dummies
		HTMLS += '<li class = "menuDummy1"></li>';
		HTMLS += '<li class = "menuDummy2"></li>';
		HTMLS += '</ul>';
		}
	else if (GAME_ID == -1) {
		HTMLS += '<ul id = "nav">';
		//Global
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'main.php">Main</a>')+'</li>';
		//Messages
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'inbox.php">Inbox ['+NEW_MESSAGES+']</a>')+'</li>';
		//Options
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'editplayer.php">Options</a>')+'</li>';
		//Information
		HTMLS += '<li>'+getValignDiv('Information')+'<ul>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'allunittypes.php">All Unit Types</a>')+'</li>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'todo.php">Admin ToDo List</a>')+'</li>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'players.php">Players</a>')+'</li>';
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'credits.php">Credits</a>')+'</li>';
		HTMLS += '</ul></li>';
		//Communication
		HTMLS += '<li>'+getValignDiv('Community')+'<ul>';
		HTMLS += '<li>'+getValignDiv('<a href = "irc://irc.coldfront.net/gamerwarfare">IRC</a>')+'</li>';
		HTMLS += '</ul></li>';
		//Logout
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'logout.php">Logout</a>')+'</li>';
		HTMLS += '<li class = "menuDummy1"></li>';
		HTMLS += '<li class = "menuDummy2"></li>';
		HTMLS += '</ul>';
		}
	else if (GAME_ID == -2) {
		//Login screen
		HTMLS += '<ul id = "nav">';
		//Global
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'index.php">Login Page</a>')+'</li>';
		//Messages
		HTMLS += '<li>'+getValignDiv('<a href = "'+SITE+'signup.php">Sign Up</a>')+'</li>';
		//Dummies
		HTMLS += '<li class = "menuDummy1"></li>';
		HTMLS += '<li class = "menuDummy2"></li>';
		HTMLS += '</ul>';		
		}
				
	//Make the search bar
	if (GAME_ID != -2) {
		HTMLS += '<div class = "search" align = "center">';
		HTMLS += '<form action = "'+SITE+'search.php" method = "get" class = "search">';
		//HTMLS += '<div ';
		HTMLS += '<input type = "text" name = "query">&nbsp;';
		HTMLS += '<select name = "mode"><option ';
		if (GAME_ID == -1)
				HTMLS += 'checked ';
		HTMLS += 'value = "player">Players</option>';
		if(GAME_ID != -1) {
			HTMLS += '<option selected = "selected" value = "country">Countries</option>';
			HTMLS += '<option value = "alliance">Alliances</option>';	
			}
		HTMLS += '</select>';
		HTMLS += '&nbsp;<input type  = "submit" value = "Search">';
		HTMLS += '</form></div>';
		}
		
	//Close the div
	HTMLS += '</div></div>';
	
	//Set the HTML
	E.innerHTML = HTMLS;
	
	//Set the update string if applicable
	if (_LOAD_TIME && _NEXT_UPDATE && GAME_ID >= 0) {
		setUpdateString();
		}
	}
	
function getValignDiv (InnerHTML) {
	return '<div class = "valignContainer"><div class = "valign">'+InnerHTML+'</div></div>';
	}
-->

