/************************************************************************************
Simple reusable DHTML library made by Thomas Brattli from www.bratta.com
Tutorial availble at 
http://www.bratta.com/dhtml/scripts.asp?url=howtos/dhtmllib.asp

More scripts and tutorial availble at DHTML Scriptomania:
http://www.bratta.com/dhtml/scripts.asp

Please keep this notice in the code if you use it. Thanks.

bratta-dhtml-lib ver 1
************************************************************************************/

//Extra functions
function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ie=this.ie4||this.ie5
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	return this
}
var bw=new lib_bwcheck()

//In most cases you want to check if the user is using a supported browser in this step
//and send them to a page saying "sorry you need a 4.x+ browser to see this page" or similar
//Just uncomment the next line and place in the url to your "sorry" page:

//if(!bw.bw) location.href='sorry.html'

function lib_doc_size(){ //Page positions - needed!
	this.x=0;this.x2=bw.ie && document.body.offsetWidth-5||innerWidth||0;
	this.y=0;this.y2=bw.ie && document.body.offsetHeight-5||innerHeight||0;
	if(!this.x2||!this.y2) return message('Document has no width or height') 
	this.x50=this.x2/2;     this.y50=this.y2/2;
	this.x10=(this.x2*10)/100;this.y10=(this.y2*10)/100
	return this;
}
function lib_message(txt){ //Error feedback function
	alert(txt)
	return false
}

//Default lib functions
function lib_obj(obj,nest){
	function lib_moveIt(x,y){ //Move to a spesified position
	        this.x=x;this.y=y
	        this.css.left=x;this.css.top=y
	}
	function lib_moveBy(x,y){ //Move by a spesified number of pixels
	        this.moveIt(this.x+x,this.y+y)
	}
	function lib_showIt(){ //Show a layer
	        this.css.visibility="visible"
	}
	function lib_hideIt(){ //Hide a layer
	        this.css.visibility="hidden"
	}
	function lib_bg(color){ //Changing backgroundcolor
	        if(bw.dom || bw.ie4) this.css.backgroundColor=color
	        else if(bw.ns4) this.css.bgColor=color  
	}
	function lib_writeIt(text,startHTML,endHTML){  //Writing new content to a layer
	        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 //NOTE: This only works on Explorer4+5 and Gecko M16+
	}
	function lib_clipTo(t,r,b,l,setwidth){ //Clip to a spesified setting
		this.ct=t; this.cr=r; this.cb=b; this.cl=l
		if(bw.ns4){
			this.css.clip.top=t;this.css.clip.right=r
			this.css.clip.bottom=b;this.css.clip.left=l
		}else{
			if(t<0)t=0;if(r<0)r=0;if(b<0)b=0;if(b<0)b=0
			this.css.clip="rect("+t+","+r+","+b+","+l+")";
			if(setwidth){this.css.width=r; this.css.height=b}
		}
	}
	function lib_clipBy(t,r,b,l,setwidth){ //Clip by a spesified number of pixels
		this.clipTo(this.ct+t,this.cr+r,this.cb+b,this.cl+l,setwidth)
	}
	if(!bw.bw) return message('Old browser')
	this.evnt=bw.dom && document.getElementById(obj)||bw.ie4 && document.all[obj]|| (nest?bw.ns4 && document[nest].document[obj]:bw.ns4 && document.layers[obj]);
	if(!this.evnt) return lib_message('The layer does not exist ('+obj+') - Exiting script\n\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=this.css.left||this.css.pixelLeft||this.evnt.offsetLeft||0
	this.y=this.css.top||this.css.pixelTop||this.evnt.offsetTop||0
	this.w=this.ref.width||this.evnt.offsetWidth||this.css.pixelWidth||0
	this.h=this.ref.height||this.evnt.offsetHeight||this.css.pixelHeight||0
	this.moveIt=lib_moveIt; this.moveBy=lib_moveBy; 
	this.showIt=lib_showIt; this.hideIt=lib_hideIt;
	this.writeIt=lib_writeIt; this.bg=lib_bg;
	//Clip values
	this.c=0
	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.clipTo=lib_clipTo;	this.clipBy=lib_clipBy;
	this.obj = obj + "Object"; 	eval(this.obj + "=this")
	return this
}
