var Time;
var GameW;
function gamead_init(GameTitle, _GameW, GameH, baseurl, _time) {
	
	GameW = _GameW;
	Time = _time;
	//var PX  = (960 - GameW) * 0.5;
	var PX  = 0;
	var PXC = PX + GameW - 120;
	
	// Background
	var STR;
	STR = "";
	STR += '<div id="adoverlay" align="left" ';
	STR += 'style="position:absolute; ';
	STR += 'left:'+ PX +'px; ';
	STR += 'top:0px; ';
	STR += 'width:'+ GameW +'px; ';
	STR += 'height:'+ GameH +'px; ';
	STR += 'background-image:url('+ baseurl +'images/overlay.png); ';
	STR += 'z-index:3;">';
	STR += '</div>';
	
	// Game is loading ...
	STR += '<div id="msg" align="center" ';
	STR += 'style="position:absolute; ';
	STR += 'left:0px; ';
	STR += 'top:20px; ';
	STR += 'width:'+ GameW +'px; ';
	STR += 'z-index:4;">';
	STR += '<b class="admsg">'+ GameTitle +' is loading ...</b>';
	STR += '</div>';
	
	// Close
	STR += '<div id="close" align="right" ';
	STR += 'style="position:absolute; ';
	STR += 'left:'+ PXC +'px; ';
	STR += 'top:20px; ';
	STR += 'width:100px; ';
	STR += 'z-index:5;">';
	STR += '<a class="adclose" href="javascript:gamead_destroy();">[CLOSE]</a>';
	STR += '</div>';
	
	setGameDivHtml("adcontainer", STR);
	
	// Timer
	STR  = "";
	STR += '<div id="time" align="center" ';
	STR += 'style="position:absolute; ';
	STR += 'left:0px; ';
	STR += 'top:50px; ';
	STR += 'width:'+ GameW +'px;';
	STR += 'z-index:4;">';
	STR += '<b class="adtime">'+ Time +'</b>';
	STR += '</div>';
	
	setGameDivHtml("adtime", STR);
	
	// Clock
	setTimeout(gamead_clock, 1000);
	setTimeout(gamead_destroy, Time * 1000);
	
} // gamead_init


function gamead_clock() {
	
	Time = Time - 1;
	if (Time < 1) {return;}
	
	// Timer
	var STR = "";
	STR += '<div id="time" align="center" ';
	STR += 'style="position:absolute; ';
	STR += 'left:0px; ';
	STR += 'top:50px; ';
	STR += 'width:'+ GameW +'px; ';
	STR += 'z-index:4;">';
	STR += '<b class="adtime">'+ Time +'</b>';
	STR += '</div>';
	
	setGameDivHtml("adtime", STR);
	
	setTimeout(gamead_clock, 1000);
	
} // gamead_clock


function gamead_destroy() {
	
	Time = 0;
	STR = "";
	setGameDivHtml("adcontainer", STR);
	setGameDivHtml("adtime", STR);
	setGameDivHtml("adunit", STR);
	
} // destroy


function setGameDivHtml(DIV, HTML) {
	
	var el = (document.getElementById)? document.getElementById(DIV): (document.all)? document.all[DIV]: (document.layers)? document.layers[DIV]: null;
  	if (!el) return;
	
	var cntnt = HTML;	
  	if (typeof el.innerHTML != "undefined") {
    	el.innerHTML = cntnt;
  	} else if (document.layers) {
   		el.document.write(cntnt);
   		el.document.close();
  	}
	
} // setGameDivHtml
