function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion;
	this.dom=document.getElementById?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?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.ie6;
	this.ns5 = (navigator.vendor == ("Netscape6") || navigator.product == ("Gecko"));
	this.ns4=(document.layers && !this.dom)?1:0;
	this.ns=this.ns4||this.ns5;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5 || this.ie6);
        this.IECSS = (this.ie && document.compatMode) ? document.compatMode ==  "CSS1Compat" : false;
	this.IEDTD = (this.ie && document.doctype) ? document.doctype.name.indexOf(".dtd")!=-1 : this.IECSS;
	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(w, d){ //Page positions - needed!
	if (!d) {
	  d = document;
	}
	if (!w) {
	  w = window;
        }
	this.x=0;this.x2=bw.ie && d.body.offsetWidth-5||w.innerWidth||0;
	this.y=0;this.y2=bw.ie && d.body.offsetHeight-5||w.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 && 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;
}

function Replace(Input, StringToSearchFor, StringToReplaceWith) {
  var Output, Pos, Hit;
  Output = Input;
  Pos = 0;
  while ((Hit = Output.indexOf(StringToSearchFor, Pos)) > 0) {
    Output = Output.substring(0, Hit) + StringToReplaceWith + Output.substring(Hit+StringToSearchFor.length, Output.length);
    Pos = Hit+StringToSearchFor.length;
  }
  return Output;
}
	 
function setVisibility(obj, toggle) {
  if (!obj) {
    return;
  }
  var Local = obj;
  if (Local.style) {
    Local = Local.style;
  }
  if (toggle == 1) {
    Local.visibility = 'visible';
  }
  else {
    Local.visibility = 'hidden';
  }
}

function findObj(n, d) {
  var p,i,x,obj;
  x = 0;
  obj = d;
  if(!d) {
    d=document;
  }
  else if (d.document) {
    d = d.document;
  }
  p = n.indexOf("?");
  if((p > 0)&&(parent.frames.length)) {
    d=parent.frames[n.substring(p+1)];
    if (d) {
      d = d.document;
    }
    n=n.substring(0,p);
  }
  if (!x&&obj) {
    if (obj.frames) {
      x = obj.frames[n];
    }
  }
  if (!x&&d.frames) {
    x = d.frames[n];
  }
  if (!x&&d.all) {
    x = d.all[n];
  }
  if (!x&&d.getElementById) {
    x = d.getElementById(n);
  }
  if (!x&&d.links) {
    x=d.links[n];
  }
  if (!x&&d.forms) {
    for (i=0;!x&&i<d.forms.length;i++) {
      if (d.forms[i].name == n) {
        x = d.forms[i];
      }
      else {
        x=d.forms[i][n];
      }
    }
  }
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) {
    if (d.layers[i].name == n) {
      x = d.layers[i];
    }
    else if (d.layers[i].id == n) {
      x = d.layers[i];
    }
    else {
      x=findObj(n,d.layers[i]);
    }
  }
  if (!x&&d.images) {
    x=d.images[n];
    for (i=0; !x&&d.images&&i<d.images.length;i++) {
      if (d.images[i].name == n) {
        x = d.images[i];
      }
    }
  }
  return x;
}

function reloadPage(init) {  //reloads the window if Nav4 resized
  if (init == 1) {
    if (bw.ns4) {
      PageWidth=top.innerWidth;
      PageHeight=top.innerHeight;
      top.onResize=reloadPage;
    }
  }
  else {
    if(bw.ns4) {
      if ((top.innerWidth != PageWidth) ||
	  (top.innerHeight!= PageWidth)) {
	ShiftLayers();
      }
    }
  }
}

function ShiftLayers() {
  self.document.location.reload(false);
}

