// System info e.g. browser, OS
function systemInfo() {
	var b=navigator.appName; 
	if (b=="Netscape") {this.b = "ns"} else if (b=="Microsoft Internet Explorer") {this.b="ie"} 
  else if (b=="Opera") {this.b = "opera"}	else {this.b=b}
	this.version=navigator.appVersion;this.v=parseInt(this.version)
	this.ns=(this.b=="ns"&&this.v>=4);this.ns4=(this.b=="ns"&&this.v==4);this.ns6=(this.b=="ns"&&this.v>4)
	this.ie=(this.b=="ie"&&this.v>=4);
  if (this.version.indexOf('MSIE 4')>0) {this.ie4=true; this.v=4}
  if (this.version.indexOf('MSIE 5')>0) {this.ie5=true; this.v=5}
  if (this.version.indexOf('MSIE 6')>0) {this.ie6=true; this.v=6}
  this.opera5 = (this.b=="opera" && this.v>4);this.dom=document.getElementById?1:0
	this.agent = navigator.userAgent.toLowerCase();
	if (this.agent.indexOf("mac")!=-1){this.os="mac"}	else if (this.agent.indexOf("win")!=-1){this.os="win"} 	
  else this.os = "other"
}
is=new systemInfo()
var mousecaptured = false
// window dimensions
function getInnerWindowWidth(){if(is.ie){return parseInt(document.body.offsetWidth-5)}else{return parseInt(window.innerWidth)}}
function getInnerWindowHeight(){if (is.ie){return parseInt(document.body.offsetHeight-5)}else{return parseInt(window.innerHeight)}}
// Return layer pointer functions
function getLayer(name, nestref) {
  if (is.dom) return document.getElementById(name); 
  if (is.ns4) {
    if (!nestref) return findLayer(name, document);
    else return  eval(nestref + '.document.layers["' + name + '"]')
  }
  if (is.ie4) return eval('document.all.' + name); msg("Browser not supported.")
}
function findLayer(name, doc) { //Used by netscape 4 only
  var i, lay;
  for (i=0;i<doc.layers.length; i++) {
    lay = doc.layers[i]; if (lay.name == name) return lay;
    if (lay.document.layers.length > 0){
      lay=findLayer(name,lay.document);
      if (lay != null && lay != undefined) return lay;
    }
  }
}
// Message displayer
function msg(txt){alert(txt)}
// dhtml layer object - nestref is optional (for backward compatibility only)
function mfLayer(name,nestref){
  this.id=name
  this.elm=getLayer(name,nestref); 
  if (!this.elm){msg("Could not find layer - " + name); return;}
  this.layerName=name; this.obj=name+"mfLayer"; eval(this.obj+"=this");
  if (is.dom) {this.css=this.elm.style;this.doc=document}
  if (is.ns6) {
    var tempx=0; var tempy=0;
    if (this.elm.parentNode.id != ""){
      tempx = this.elm.offsetLeft-this.elm.parentNode.offsetLeft;
      tempy = this.elm.offsetTop-this.elm.parentNode.offsetTop;
    }
    else {tempx = this.elm.offsetLeft; tempy = this.elm.offsetTop}
    this.moveTo(tempx,tempy);
  }
  if (is.ie4) {this.css=document.all[name].style;this.doc=document}
  if (is.ns4) {this.css=this.elm;this.doc=this.elm.document}
  // create a reference to the object itself
  this.obj = name + "mfLayer";  eval(this.obj + "=this");  this.name=name;
}
// basic get functions
mfLayer.prototype.getLeft = mfLayerGetLeft; mfLayer.prototype.getRight = mfLayerGetRight;
mfLayer.prototype.getTop = mfLayerGetTop; mfLayer.prototype.getBottom = mfLayerGetBottom; 
mfLayer.prototype.getX = mfLayerGetLeft; mfLayer.prototype.getY = mfLayerGetTop;
mfLayer.prototype.getWidth = mfLayerGetWidth; mfLayer.prototype.getHeight = mfLayerGetHeight
mfLayer.prototype.getZIndex = mfLayerGetZIndex;
function mfLayerGetLeft(){return parseInt(this.css.left||this.css.pixelLeft||this.elm.offsetLeft||0)}
function mfLayerGetTop(){return parseInt(this.css.top||this.css.pixelTop||this.elm.offsetTop||0)}
function mfLayerGetRight(){return parseInt(this.getLeft()+this.getWidth())}
function mfLayerGetBottom(){return parseInt(this.getTop()+this.getHeight())}
function mfLayerGetWidth(){return parseInt(this.css.clip.width||this.elm.offsetWidth||this.css.pixelWidth||this.elm.clientWidth||0)}
function mfLayerGetHeight(){return parseInt(this.css.clip.height||this.elm.offsetHeight||this.css.pixelHeight||this.css.clientHeight||0)}
function mfLayerGetZIndex(){return parseInt(this.css.zIndex)}
// basic set properties
mfLayer.prototype.setBgColor = mfLayerSetBgColor; mfLayer.prototype.setBgImage = mfLayerSetBgImage
mfLayer.prototype.setZIndex = mfLayerSetZIndex; mfLayer.prototype.setOpacity = mfLayerSetOpacity
function mfLayerSetBgColor(color){
  // Opera 5 need to set background-color in css before using
  if (is.ns4) {this.css.bgColor=color} else if (is.opera5) {this.css.background = color}
  else this.css.backgroundColor = color
}
function mfLayerSetBgImage(img){if (is.opera5) return;
  (is.ns4) ? this.css.background.src = img : this.css.backgroundImage = "url(" + img + ")"
}
function mfLayerSetZIndex(zindex){this.css.zIndex = zindex;}
function mfLayerSetOpacity(opacity){
  if (is.ns4 || is.opera5) return; if (opacity<0 || opacity>100) opacity=100;
  (is.ns6) ? this.css.MozOpacity=""+opacity+"%" : this.css.filter="alpha(opacity="+opacity+")"
}
// Show and hide functions
mfLayer.prototype.show = mfLayerShow; mfLayer.prototype.hide = mfLayerHide
function mfLayerShow() {this.css.visibility = (is.ns4)? "show" : "visible"}
function mfLayerHide() {this.css.visibility = (is.ns4)? "hide" : "hidden"}
// Clip functions
mfLayer.prototype.clipInit = mfLayerClipInit; mfLayer.prototype.clipTo = mfLayerClipTo
mfLayer.prototype.clipBy = mfLayerClipBy; mfLayer.prototype.clipValues = mfLayerClipValues
function mfLayerClipInit(t,r,b,l) {
	if (is.ie) {
		if (arguments.length==4) this.clipTo(t,r,b,l)
		else if (is.ie4) this.clipTo(0,this.css.pixelWidth,this.css.pixelHeight,0)
	}
}
function mfLayerClipTo(t,r,b,l) {
	if (is.opera5) return;
  if (t==null) t = this.clipValues('t');	if (r==null) r = this.clipValues('r')
	if (b==null) b = this.clipValues('b');	if (l==null) l = this.clipValues('l')
	if (is.ns4) {
		this.css.clip.top = t; this.css.clip.right = r
		this.css.clip.bottom = b; this.css.clip.left = l
	}
	else this.css.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)"
}
function mfLayerClipBy(t,r,b,l) {
	this.clipTo(this.clipValues('t')+t,this.clipValues('r')+r,this.clipValues('b')+b,this.clipValues('l')+l)
}
function mfLayerClipValues(which) {
  if (is.opera5) return;
	if (is.ie) var clipv = this.css.clip.split("rect(")[1].split(")")[0].split("px")
	if (which=="t") return (is.ns)? this.css.clip.top : Number(clipv[0])
	if (which=="r") return (is.ns)? this.css.clip.right : Number(clipv[1])
	if (which=="b") return (is.ns)? this.css.clip.bottom : Number(clipv[2])
	if (which=="l") return (is.ns)? this.css.clip.left : Number(clipv[3])
}
// Move functions
mfLayer.prototype.moveTo = mfLayerMoveTo; mfLayer.prototype.moveBy = mfLayerMoveBy
mfLayer.prototype.centerLayer = mfLayerCenterLayer; mfLayer.prototype.centerLayer = mfLayerCenterLayer
function mfLayerMoveTo(x,y) {
  if (is.opera5 || is.ie4) {this.css.pixelLeft=x;this.css.pixelTop=y} 
	else if (is.dom && !is.opera5) {this.css.left=x+"px";this.css.top=y+"px"}
	else {this.css.left=x;this.css.top=y}
}
function mfLayerMoveBy(x,y) {this.moveTo(this.getX()+x,this.getY()+y)}
var centerIntoNegative=false
function mfLayerCenterLayer(centertype, adjust) {// (centertype) 1 = vertical, 2 = horizontal, other = both
  var docH = getInnerWindowHeight();  var docW = getInnerWindowWidth();
  var centerY, centerX;
  if (isNaN(adjust)) adjust = 0;
  if (centertype==1){centerY = (docH/2 + adjust)-parseInt(this.getHeight()/2); centerX = this.getX()}
  else if (centertype==2) {centerY = this.getY(); centerX = (docW/2 + adjust)-parseInt(this.getWidth()/2);}
  else{
    centerY = (docH/2 + adjust)-parseInt(this.getHeight()/2);
    centerX = (docW/2 + adjust)-parseInt(this.getWidth()/2);
  }
  if (!centerIntoNegative){if (centerX<0){centerX=0} if (centerY<0){centerY=0}}
  this.moveTo(centerX, centerY)
}
// Resize functions
mfLayer.prototype.resizeTo = mfLayerResizeTo; mfLayer.prototype.resizeBy = mfLayerResizeBy
function mfLayerResizeTo(w,h){
  if (w<0){w=0}; if (h<0){h=0}; this.css.width = w; this.css.height = h;
  if (is.opera5){this.css.pixelWidth=w; this.css.pixelHeight=h;}
  else {this.clipTo(0,w,h,0)}; this.hasResized = true
}
function mfLayerResizeBy(w,h){
  var newW = parseInt(this.getWidth())+w;  var newH = parseInt(this.getHeight())+h;
  this.css.width = newW; this.css.height = newH; 
  if (is.opera5){this.css.pixelWidth = newW; this.css.pixelHeight = newH;}
  else {this.clipTo(0,newW,newH,0)};  this.hasResized=true
}

