//Extra functions
function browserCheck()
{
	//Browsercheck
	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 browserCheck();

//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 documentSize()
{
	//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 message(txt)
{
	//Error feedback function
	alert(txt);
	return false;
}

//Default lib functions
function moveIt(x,y)
{
	//Move to a spesified position
	this.x=x;
	this.y=y;
	if(bw.ns4)this.css.moveTo(x,y);
	else
	{
		this.css.left=x;
		this.css.top=y;
	}
}

function moveBy(x,y)
{
	//Move by a spesified number of pixels
	this.moveIt(this.x+x,this.y+y);
}

function showIt()
{
	//Show a layer
	if(bw.dom || bw.ie4)this.css.visibility="visible";
	else if(bw.ns4)this.css.visibility="show";
}

function hideIt()
{
	//Hide a layer
	if(bw.dom || bw.ie4)this.css.visibility="hidden";
	else if(bw.ns4)this.css.visibility="hide";
}
	
function setBackgroundColor(color)
{
	//Changing backgroundcolor
	if(bw.dom || bw.ie4) this.css.backgroundColor=color;
	else if(bw.ns4) this.css.bgColor=color;
}

function 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 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(l<0)l=0;

		this.css.clip = "rect(" + t + "px " + r + "px " + b + "px " + l + "px)";
		if(setwidth)
		{
			this.css.width=r;
			this.css.height=b
		}
	}
}

function 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);
}

function makeObj(obj, nest, nest2)
{
	if(!bw.bw) return message('Old browser');
	this.evnt=bw.dom && document.getElementById(obj)||bw.ie4 && document.all[obj]|| (nest2?bw.ns4 && document[nest2].document[nest].document[obj]:nest?bw.ns4 && document[nest].document[obj]:bw.ns4 && document.layers[obj]);
	if(!this.evnt) return 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.css.clip.width||this.evnt.offsetWidth||this.ref.width||this.css.pixelWidth||0;
	this.h=this.css.clip.height||this.evnt.offsetHeight||this.ref.height||this.css.pixelHeight||0;

	this.moveIt=moveIt;
	this.moveBy=moveBy;
	this.showIt=showIt;
	this.hideIt=hideIt;
	this.writeIt=writeIt;
	this.setBackgroundColor=setBackgroundColor;

	//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=clipTo;
	this.clipBy=clipBy;

	this.obj = obj + "Object";
	eval(this.obj + "=this");

	return this;
}