// Page functions *************
function lib_resize(){
	if(bw.ns4) lib_reload();
	lib_obj_align();
}
function lib_evt_scroll(){lib_obj_align();}
function lib_reload(init) {
	if (bw.ns4){ if (init) {nsFix=new lib_doc_size();}
	else if (innerWidth!=nsFix.x2 || innerHeight!=nsFix.y2){location.reload();}}
}
lib_reload(true);
//Document size object ********
function lib_doc_size(){
	//alert(document.body.offsetWidth + "\n" + document.body.clientWidth)
	this.x=0;this.x2=bw.ie && document.body.offsetWidth-20||innerWidth||0;
	this.y=0;this.y2=bw.ie && document.body.offsetHeight-5||innerHeight||0;
	this.yScroll=bw.ie?document.body.scrollTop:pageYOffset||0;
	if(!this.x2||!this.y2) return lib_message('Document has no width or height');
	this.x50=this.x2/2;this.y50=this.y2/2;
	return this;
}
// Layer align functions **************
var nObjAlign=0,aObjAlign=new Array();
function lib_add_obj_align(obj){aObjAlign[nObjAlign++]=obj;}
function lib_obj_align(){
	var doc=new lib_doc_size();
	for(var i=0;i<aObjAlign.length;i++){var o=aObjAlign[i];
		if(o.align=="center")o.moveIt(doc.x50-((lib_get_w(o)/2)-o.offset),o.y);
		else if(o.align=="right")o.moveIt(doc.x2-(lib_get_w(o)-o.offset),o.y);
		if(o.valign=="center")o.moveIt(o.x,doc.y50-((lib_get_h(o)/2)-o.voffset));
		else if(o.valign=="bottom")o.moveIt(o.x,doc.yScroll+doc.y2-(lib_get_h(o)-o.voffset));
		else if(o.valign=="top")o.moveIt(o.x,doc.yScroll+o.voffset);
	}
}
//Debug function ******************
function lib_message(txt){alert(txt); return false}
//Lib objects  ********************
function lib_obj(obj,nest,align,offset,valign,voffset){ 
	if(!bw.bw) return lib_message('Old browser')
	nest=(!nest) ? "":'document.'+nest+'.'
	this.evnt=bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+"document.layers." +obj):0;	
	if(!this.evnt) return lib_message('The layer does not exist ('+obj+') - \nIf your using Netscape please check the nesting of your tags!')
	this.css=bw.dom||bw.ie4?this.evnt.style:this.evnt; 
	this.ref=bw.dom||bw.ie4?document:this.css.document;
	this.x=parseInt(this.css.left)||this.css.pixelLeft||this.evnt.offsetLeft||0;
	this.y=parseInt(this.css.top)||this.css.pixelTop||this.evnt.offsetTop||0;
	this.w=lib_get_w(this);
	this.h=lib_get_h(this);
	this.c=0; //Clip values
	if((bw.dom || bw.ie4) && this.css.clip) {
		this.c=this.css.clip; this.c=this.c.slice(5,this.c.length-1); 
		this.c=this.c.split(' ');
		for(var i=0;i<4;i++){this.c[i]=parseInt(this.c[i])}
	}
	this.ct=this.css.clip.top||this.c[0]||0;
	this.cr=this.css.clip.right||this.c[1]||this.w||0;
	this.cb=this.css.clip.bottom||this.c[2]||this.h||0; 
	this.cl=this.css.clip.left||this.c[3]||0;
	this.obj = obj + "Object"; eval(this.obj + "=this");
	this.showIt=lib_showIt;this.hideIt=lib_hideIt;this.moveIt=lib_moveIt;this.moveBy=lib_moveBy;this.writeIt=lib_writeIt;
	this.dragdrop();
	this.align=(!align)?"":align.toLowerCase();
	this.valign=(!valign)?"":valign.toLowerCase();
	this.offset=(!offset)?0:(bw.ns4)?offset-20:offset;
	this.voffset=(!voffset)?0:(bw.ns4)?voffset-20:voffset;
	if(this.align) lib_add_obj_align(this);
	return this
}
function lib_get_w(o) { return o.evnt.offsetWidth||o.css.clip.width||o.ref.width||o.css.pixelWidth||0; }
function lib_get_h(o) { return o.evnt.offsetHeight||o.css.clip.height||o.ref.height||o.css.pixelHeight||0; }
function lib_moveIt(x,y){this.x=x;this.y=y; this.css.left=x;this.css.top=y}
function lib_moveBy(x,y){this.css.left=this.x+=x; this.css.top=this.y+=y}
function lib_showIt(){this.css.visibility="visible"}
function lib_hideIt(){this.css.visibility="hidden"}
// dummy functions when lib_dd.js is not loaded
lib_obj.prototype.dragdrop = function(obj){return}
lib_obj.prototype.nodragdrop = function(obj){return}
//Writing content to object ***
function lib_writeIt(text,startHTML,endHTML){
	if(bw.ns4){
		if(!startHTML){startHTML=""; endHTML=""}
		this.ref.open("text/html"); 
		this.ref.write(startHTML+text+endHTML); 
		this.ref.close()
	}else this.evnt.innerHTML=text;
}
