//game specific
var mor_req;
function logGame(){
	var log_path="../../scripts/log.php?game="+gamename;
	document.getElementById("gamelog").src=log_path;
}
function writeGame(){
	var game_path="../game_page.php?game="+gameid;
	if(gameid==58){
		game_path+="&";
		game_path+=window.location.search.substring(1);
	}
	document.getElementById("nitromegame").height=gameheight;
	document.getElementById("nitromegame").src=game_path;
}
function writeGameInfo(){
	if(gameheight==400){
		document.getElementById("game_info_box").style.backgroundImage='url('+images_folder+"controls_panel.png"+')';
		document.getElementById("game_info_text").innerHTML='<span id="controls">'+gamedesc+'</span>';
	}
}
function writeMoreGames(){
	if(gameheight==400){
		fillWithImage("more_games_border",images_folder+"moregames_top_bar.png","566","19","0","","","");
		document.getElementById("more_games_inner").style.backgroundImage='url('+images_folder+"moregames_panel.png"+')';
		if (window.XMLHttpRequest){// code for all new browsers
  			mor_req=new XMLHttpRequest();
  		}else if (window.ActiveXObject){// code for IE5 and IE6
  			mor_req=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		if (mor_req!=null){
  			mor_req.onreadystatechange=parseMoreGames;
  			mor_req.open("GET",xml_folder+"gamedata.xml",true);
  			//mor_req.open("GET","gamedata.xml",true);
  			mor_req.send(null);
  		}else{
  			//alert("Your browser does not support XMLHTTP.");
  		}
	}
}
function parseMoreGames(){
	if(mor_req.readyState==4){
		if(mor_req.responseText!=""){
			try{
			 	//Internet Explorer
			 	xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
				xmlDoc.async="false";
				xmlDoc.loadXML(mor_req.responseText);
		 	}catch(e){
			 	// code for all new browsers
				parser=new DOMParser();
   		 		xmlDoc=parser.parseFromString(mor_req.responseText,"text/xml");
		 	}
		 	xmlDoc=removeWhitespace(xmlDoc);
    		var games=xmlDoc.documentElement.childNodes;
    		finalizeMoreGames(games);
		}
	}
}
function finalizeMoreGames(games){
	game_id=new Array();
	game_names=new Array();
	game_type=new Array();
	//remove game_name from list
    for(var i=0; i<games.length; i++){
	   	if(games[i].getAttribute("id")==gamename){
		   	games[i].parentNode.removeChild(games[i]);
		    break;
	   	}
   	}
   	var total_games=games.length;
	id_1=Math.floor(Math.random()*(total_games));
	game_id[1]=games[id_1].getAttribute("id");
	game_names[1]=games[id_1].getAttribute("name");
	game_type[1]=games[id_1].getAttribute("imagetype");
	//remove id_1 game from list
	games[id_1].parentNode.removeChild(games[id_1]);
	
   	
   	total_games=games.length;
	id_2=Math.floor(Math.random()*(total_games));
	game_id[2]=games[id_2].getAttribute("id");
	game_names[2]=games[id_2].getAttribute("name");
	game_type[2]=games[id_2].getAttribute("imagetype");
	//remove id_2 game from list
	games[id_2].parentNode.removeChild(games[id_2]);
	
	total_games=games.length;
	id_3=Math.floor(Math.random()*(total_games));
	game_id[3]=games[id_3].getAttribute("id");
	game_names[3]=games[id_3].getAttribute("name");
	game_type[3]=games[id_3].getAttribute("imagetype");
	//remove id_3 game from list
	games[id_3].parentNode.removeChild(games[id_3]);
	
   	total_games=games.length;
	id_4=Math.floor(Math.random()*(total_games));
	game_id[4]=games[id_4].getAttribute("id");
	game_names[4]=games[id_4].getAttribute("name");
	game_type[4]=games[id_4].getAttribute("imagetype");
	//remove id_4 game from list
	games[id_4].parentNode.removeChild(games[id_4]);
	
   	//alert("total games: "+games.length);
   	//alert(id_1+" - "+id_2+" - "+id_3+" - "+id_4);
   	for(var i=1; i<=4; i++){
   		var mg="";
   		mg+='<a class="h" href="';
		mg+=root_dir;
		mg+="games/";
		mg+=game_id[i];
		mg+='" >';
		mg+='&nbsp;';
		mg+=game_names[i];
		mg+='</a>';
		mg+='<br>';
		mg+='<a class="h" href="';
		mg+=root_dir;
		mg+="games/";
		mg+=game_id[i];
		mg+='" >';
		mg+='<img class="bottom" src="';
		mg+=thumbnails_folder;
		mg+="t_";
		mg+=game_id[i];
		mg+=game_type[i];
		mg+='" width="124" height="49" border="0" alt="';
		mg+=game_names[i];
		mg+='"/>';
		mg+='</a>';
		document.getElementById("mg_"+i).innerHTML=mg;
	}
}
//logGame();
writeGame();
writeMenu();
writeTopBar();
writeAdDescriptions();
writeSideAd();
writeCorporate();
writeGameInfo();
writeMoreGames();
writeTopGames();