// ----------------------------------------------------------------- //
// all functions and variables in Gamelib core are prefixed with Gl_ //
// ----------------------------------------------------------------- //

var Sp_totalsprites=0;
Sp_xoffset=0;
Sp_yoffset=0;

var Gl_version=1.3;
var Gl_totalpreimages=0;
var Gl_interval=null;
var Gl_hooked=new Array();
var Gl_preimage=new Array();
var Gl_ticker=0;
var Gl_sin=new Array();
var Gl_cos=new Array();
var Gl_failure=false;
var Gl_cookies=new Array();
var Gl_layer_index=0;

var ie=false,ie5=false,ns=false,ns5=false,appleBrowser=false;
Gl_getbrowser();
Gl_makedegs();
Gl_get_cookies();

function Gl_getbrowser(){
	var ua = navigator.userAgent.toLowerCase();
	var ver = parseInt(navigator.appVersion);
	if(ua.indexOf("msie")!=-1){
		if(document.all) ie=true;
		if(ua.indexOf("msie 5")!=-1)
			ie5=true
	}else if(ua.indexOf("mozilla")!=-1){
		if(document.layers)
			ns=true;
		if(ns&&(ver>4)) ns5=true
	}

	if((ua.indexOf('macintosh')!=-1)||(ua.indexOf('ppc')!=-1)||(ua.indexOf('powerpc')!=-1))
		appleBrowser=true;

	if(!ns&&!ie&&!ns5&&!ie5)
		Gl_failure=true
}

function Gl_preloader(img){var x=Gl_totalpreimages++;Gl_preimage[x]=new Image;Gl_preimage[x].src=img}
function Gl_hook(fnc){Gl_hooked[Gl_hooked.length]=fnc}
function Gl_unhook(fnc){var fnd=false;for(var n=0;n<Gl_hooked.length;n++) if(Gl_hooked[n]==fnc){fnd=true;break}if(fnd){for(var i=n;i<Gl_hooked.length-1;i++) Gl_hooked[i]=Gl_hooked[i+1];Gl_hooked.length--}}
function Gl_start(){Gl_interval=setInterval("Sp_loop()",50)}
function Gl_stop(){clearInterval(Gl_interval)}
function Gl_makedegs(){for(n=0;n<360;n++){Gl_sin[n]=(Math.sin(3.14159*n/180));Gl_cos[n]=-(Math.cos(3.14159*n/180))}}
function Gl_get_cookies(){var tar=document.cookie.split("; ");for(var n=0;n<tar.length;n++) Gl_cookies[n]=new Gl_Cookie_construct(tar[n])}
function Gl_Cookie_construct(Gl_var){var tmp=Gl_var.split("=");this.name=unescape(tmp[0]);this.value=unescape(tmp[1])}
function Gl_set_cookie(Gl_value){document.cookie=this.name+"="+escape(Gl_value)+"; expires= Wed, 1 May 2030 23:00:00 UTC; path=/";this.value=Gl_value;return true}
function Gl_delete_cookie(){for(var n=0;n<Gl_cookies.length;n++){if(Gl_cookies[n].name==this.name){this.value=null;document.cookie=this.name+"=; expires= Mon, 3 Jan 2000 00:00:00 UTC; path=/";Gl_cookies[n].name="";Gl_cookies[n].value="";break}}return true}
function Gl_get_cookie(c_name){for(var n=0;n<Gl_cookies.length;n++){if(Gl_cookies[n].name==c_name){return Gl_cookies[n].value}}return null}
function Gl_cookie(Gl_name){this.name=Gl_name;this.value=Gl_get_cookie(Gl_name);this.setvalue=Gl_set_cookie;this.erase=Gl_delete_cookie}
function Gl_get_window_height(){if(ie) return windowheight=document.body.offsetHeight;else return windowheight=window.innerHeight}
function Gl_get_window_width(){if(ie) return windowwidth=document.body.offsetWidth;else return windowwidth=window.innerWidth}

function Gl_layer(Gl_xstart,Gl_ystart,Gl_w,Gl_html){
		this.x=Gl_xstart;
		this.y=Gl_ystart;
		this.z=Gl_layer_index;
		this.innerHTML=Gl_html;
		this.width=Gl_w;
		this.height=0;
	if(ie){
		document.body.insertAdjacentHTML("BeforeEnd",'<div id="Adiv'+Gl_layer_index+'" style="position: absolute; left:'+Gl_xstart+'; top:'+Gl_ystart+'; width:'+Gl_w+'; visibility: visible">'+Gl_html+'</div>');
		this.ob=document.all["Adiv"+Gl_layer_index].style;
		this.raw=document.all["Adiv"+Gl_layer_index];
		this.write=Gl_layerwriteIE;
		this.append=Gl_layerappendIE;
		this.moveTo=Gl_moveto;
		this.setZ=Gl_setz;
		this.clip=Gl_obclipIE;
	}else{
		this.ob=document.layers[Gl_layer_index]=new Layer(Gl_w);
		document["Adiv"+Gl_layer_index]=this.ob;
		this.ob.name=Gl_layer_index;
		this.ob.height=0;
		this.ob.left=Gl_xstart;
		this.ob.top=Gl_ystart;
		this.ob.zIndex=Gl_layer_index;
		this.ob.visibility="show";
		this.raw=this.ob;
		this.ob.document.open();
		this.ob.document.write(Gl_html);
		this.ob.document.close();
		this.write=Gl_layerwriteNS;
		this.append=Gl_layerappendNS;
		this.moveTo=Gl_moveto;
		this.setZ=Gl_setz;
		this.clip=Gl_obclipNS;
	}
	this.Gl_index=Gl_layer_index;
	Gl_layer_index++;
	return this;
}

function Gl_layerwriteIE(Gl_txt){
	this.raw.innerHTML=Gl_txt;
	if(appleBrowser){
		this.raw.style.height=0;
		this.innerHTML="<div>"+Gl_txt+"\n</div>\n";
	}
	else
		this.innerHTML=Gl_txt;

	this.width=this.raw.clientWidth;
	this.height=this.raw.clientHeight
}

function Gl_layerappendIE(Gl_txt,Gl_pos){if(Gl_pos && Gl_pos<this.innerHTML.length){var Gl_tmp=this.innerHTML.substring(0,Gl_pos)+Gl_txt+this.innerHTML.substring(Gl_pos,this.innerHTML.length);this.innerHTML=Gl_tmp;this.raw.innerHTML=Gl_tmp}else{this.innerHTML+=Gl_txt;this.raw.innerHTML=this.innerHTML}this.width=this.raw.clientWidth;this.height=this.raw.clientHeight}
function Gl_layerappendNS(Gl_txt,Gl_pos){if(Gl_pos && Gl_pos<this.innerHTML.length){var Gl_tmp=this.innerHTML.substring(0,Gl_pos)+Gl_txt+this.innerHTML.substring(Gl_pos,this.innerHTML.length);this.innerHTML=Gl_tmp}else this.innerHTML+=Gl_txt;this.ob.document.open();this.ob.document.write(this.innerHTML);this.ob.document.close();this.width=this.raw.clip.width;this.height=this.raw.clip.height}
function Gl_layerwriteNS(Gl_txt){this.ob.width=0;this.ob.height=0;this.ob.document.open();this.ob.document.write(Gl_txt);this.ob.document.close();this.innerHTML=Gl_txt;this.width=this.raw.clip.width;this.height=this.raw.clip.height}
function Gl_moveto(Gl_x,Gl_y){this.ob.top=Gl_y;this.ob.left=Gl_x;this.x=Gl_x;this.y=Gl_y}
function Gl_setz(Gl_z){this.ob.zIndex=Gl_z;this.z=Gl_z}
function Gl_get_heightIE(){return this.raw.clientHeight}
function Gl_get_heightNS(){return this.raw.clip.height}
function Gl_get_widthIE(){return this.raw.clientWidth}
function Gl_get_widthNS(){return this.raw.clip.width}
function Gl_obclipNS(Gl_left,Gl_right,Gl_top,Gl_bottom){this.ob.clip.left=Gl_left;this.ob.clip.right=Gl_right;this.ob.clip.top=Gl_top;this.ob.clip.bottom=Gl_bottom}
function Gl_obclipIE(Gl_left,Gl_right,Gl_top,Gl_bottom){this.ob.clip="rect("+Gl_top+","+Gl_right+","+Gl_bottom+","+Gl_left+")"}
