//homepage specific
var tab_id;
var req;
function writeFlashPanel(){
	//write flash panel
	var fv='dark_colour=';
	fv+=dark_colour;
	fv+='&mid_colour=';
	fv+=anim_colour;
	fv+='&light_colour=';
	fv+=light_colour;
	
	var str="";
	if (AC_FL_RunContent == 0) {
	} else {
		str=AC_FL_RunContent_String(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0',
			'width', '550',
			'height', '235',
			'src', cdn_path+'images/anims/nitrome_games',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'window',
			'devicefont', 'false',
			'id', 'nitrome_games',
			'bgcolor', '#ffffff',
			'name', 'nitrome_games',
			'menu', 'true',
			'allowScriptAccess','sameDomain',
			'movie', cdn_path+'images/anims/nitrome_games',
			'salign', '',
			'flashvars',fv
		);
		
	}
	 
	document.getElementById("anim_box").innerHTML=str;
	
}
function writeHotGames(){
	if (window.XMLHttpRequest){// code for all new browsers
  		req=new XMLHttpRequest();
  	}else if (window.ActiveXObject){// code for IE5 and IE6
  		req=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	if (req!=null){
  		req.onreadystatechange=parseHotGames;
  		req.open("GET",xml_folder+"gamedata.xml",true);
  		req.send(null);
  	}else{
  		//alert("Your browser does not support XMLHTTP.");
  	}

}
function parseHotGames(){
	//bit of a hack but seems to work
	if(req.readyState==4){
		if(req.responseText!=""){
			try{
			 	//Internet Explorer
			 	xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
				xmlDoc.async="false";
				xmlDoc.loadXML(req.responseText);
		 	}catch(e){
			 	// code for all new browsers
				parser=new DOMParser();
   		 		xmlDoc=parser.parseFromString(req.responseText,"text/xml");
		 	}
		 	xmlDoc=removeWhitespace(xmlDoc);
    		var games=xmlDoc.documentElement.childNodes;
    		finalizeHotGames(games);
		}
	}
}
function finalizeHotGames(games){
	var game_id=1;
    for(var i=0; i<=15; i++){
	  	//alert(games[i].getAttribute("id"));
	  	var h="";
	 	h+='<a class="h" href="games/';
	 	h+=games[i].getAttribute("id");
		h+='">';
		h+='&nbsp;';
		h+=games[i].getAttribute("name");
		h+='</a>';
		h+='<a href="games/';
		h+=games[i].getAttribute("id");
		h+='">';
		h+='<img src="';
		h+=thumbnails_folder;
		h+='t_';
		h+=games[i].getAttribute("id");
		h+=games[i].getAttribute("imagetype")
		h+='" width="124" height="49" border="0" alt="';
		h+=games[i].getAttribute("id");
		h+='"/>';
		h+='</a>';
	 	document.getElementById("game_"+game_id).innerHTML=h;
	 	game_id++;   
    }
}
function writeTab(tag,image,w,h,border,id,u){
	var s="";
	if(u!=""){
		s+="<a href='";
		s+=u;
		s+="' onmouseover='javascript: tabRollover(&#39;";
		s+=id;
		s+="&#39;);' onmouseout='javascript: tabRollover(&#39;none&#39;);'/>";
	}
	s+="<img src='";
	s+=image;
	s+="' width='";
	s+=w;
	s+="' height='";
	s+=h;
	if(border!=""){
		s+="' border='";
		s+=border;
	}
	s+="' />";
	if(u!=""){
		s+="</a>";
	}
	document.getElementById(tag).innerHTML=s;
}			 
function writeHotTabs(){
	tab_id=0;
	document.getElementById("tabs_box").style.backgroundImage='url('+images_folder+"tabs_sprite.png"+')';
	document.getElementById("tabs_box").style.backgroundPosition="0 0";
	
	writeTab("tab_1",images_folder+"trans.gif","110","20","0","hot","");
	writeTab("tab_2",images_folder+"trans.gif","110","20","0","main","main_games.html");
	writeTab("tab_3",images_folder+"trans.gif","110","20","0","mini","mini_games.html");
	writeTab("tab_4",images_folder+"trans.gif","110","20","0","multi","multiplayer_games.html");
}
function tabRollover(id){
	var roll_id=0;
	if(id=="none"){
		roll_id=0;
	}else if(id=="hot"){
		roll_id=80;
	}else if(id=="main"){
		roll_id=160;
	}else if(id=="mini"){
		roll_id=240;
	}else if(id=="multi"){
		roll_id=320;	
	}
	var ypos=tab_id+roll_id;
	var bp=String("0 -"+ypos);
	if(ypos!=0){
		bp+="px";
	}
	document.getElementById("tabs_box").style.backgroundPosition=bp;
}
//background for the current games box
document.getElementById("current_games_box").style.backgroundImage = 'url('+images_folder+"homepage_game_panel.png"+')';
//main content
writeMenu();
writeTopBar();
writeAdDescriptions();
writeSideAd();
writeCorporate();
writeHotTabs();
writeTopGames();
writeFlashPanel();
writeHotGames();