function browser(){
	var sUA=navigator.userAgent.toLowerCase();
	this.compatible = (sUA.indexOf('compatible')!=-1);	
	this.ns  = (!this.compatible && sUA.indexOf('mozilla')!=-1); 	
	this.ge = (this.ns && sUA.indexOf('gecko')!=-1);
	this.geNs = (sUA.indexOf('gecko')!=-1 && sUA.indexOf('netscape')!=-1);
	this.ie = (sUA.indexOf("msie") != -1);			
	this.opera = (sUA.indexOf("opera") != -1);

	iAdd = 0
	if (this.compatible || this.geNs || this.ge){		
			if (this.opera){
				reApp = /opera.([0-9\.]+)/
				this.ie = false
			} else if (this.ie) {
				reApp = /msie.([0-9\.]+)/
			} else if (this.geNs){
				reApp = /gecko\/.+\/([0-9\.]+)/
			} else if (this.ge) {
				reApp = /rv\:([0-9\.]+)/
				iAdd = 6
				
			}

		aRes = reApp.exec(sUA)

		this.appVersion = aRes[1]
	} else {
		this.appVersion = navigator.appVersion
	}

	this.major = parseInt(this.appVersion)+iAdd; 
    this.minor = parseFloat(this.appVersion)+iAdd;

    this.ns5 = this.ns6 = (this.ge && this.major==6);
    this.ns5up = this.ns6up = (this.ge && this.major>=6);
	this.ns7 = (this.ge && this.major==7);
	this.ns7up = (this.ge && this.major>=7);

    this.ns4 = (this.ns && (this.major == 4)); 
    this.ns4up = (this.ns && (this.ns4 || this.ns6 || this.ns6up)); 
    this.nsOnly  = (this.ns && ((sUA.indexOf(";nav") != -1) || (sUA.indexOf("; nav") != -1)));
	
	this.ie3down = (this.ie && (this.major < 4)); 
    this.ie4  = (this.ie && (this.major == 4)); 
    this.ie4up  = (this.ie && (this.major >= 4)); 
    this.ie5  = (this.ie && (this.major == 5)); 
    this.ie5up  = (this.ie && (this.major >= 5));
	this.ie5_5 = (this.ie && (this.minor == 5.5));	
	this.ie5_5up = (this.ie && this.minor >= 5.5);
    this.ie6  = (this.ie && (this.major == 6));
    this.ie6up  = (this.ie && (this.major >= 6));

	this.op5 = (this.opera && this.major==5) 
	this.op5up = (this.opera && this.major>=5) 	
	this.op6 = (this.opera && this.major==6) 	
	this.op6up = (this.opera && this.major>=6)
	
	this.dom = (this.ie5up || this.ns5up || this.op5up)
	
	this.win   = ((sUA.indexOf("win")!=-1) || (sUA.indexOf("16bit")!=-1));
	this.mac    = (sUA.indexOf("mac")!=-1);
	window.oClient = this
}

function wrapLayer(sDiv,sDivObj,sNest){
	bODiv =  (typeof(sDiv)=="object")
	bObjNest =  (typeof(sNest)=="object")
	
	if (bODiv) {
		this.layer = sDiv
	} else if (oClient.dom){
		this.layer = document.getElementById(sDiv)		
	} else if (oClient.ie4) {
		this.layer = document.all[sDiv];
		
	} else if (oClient.ns4) {
		if (sNest){
			this.layer = (bObjNest)?sNest.layer.document.layers[sDiv]:eval(sNest).document[sDiv];
		} else {
			this.layer = document[sDiv];
		}
	}

	if (!this.layer){
		//alert("Layer "+sDiv+"\nDoes not exist")
	}
	if (oClient.ns4){
		this.layer.style = this.layer
	}
	
	this.obj = sDivObj

	var bReadProps = true
	if (oClient.ie4){
		if (!this.layer.tagName){
			alert("can't read those props")
			bReadProps = false
		}
		
	}

	if (oClient.dom && bReadProps){
		this.id = this.layer.id;
		this.w = (!oClient.opera)?this.layer.offsetWidth:this.layer.style.pixelWidth;
		this.h = (!oClient.opera)?this.layer.offsetHeight:this.layer.style.pixelHeight;
	    this.xpos = (!oClient.opera)?this.layer.offsetLeft:this.layer.style.pixelLeft;

		this.ypos =  (!oClient.opera)?this.layer.offsetTop:this.layer.style.pixelTop;
		this.z = this.layer.style.zIndex;
	} else if (bReadProps) {
		this.id = (oClient.ns4)?this.layer.id:this.layer.id;
		this.w = (oClient.ns4)?this.layer.clip.width:this.layer.style.pixelWidth; // use offset with IFRAME
		this.h = (oClient.ns4)?this.layer.clip.height:this.layer.style.pixelHeight;
	    this.xpos = (oClient.ns4)?this.layer.left:this.layer.style.pixelLeft;
		this.ypos = (oClient.ns4)?this.layer.top:this.layer.style.pixelTop;
		
		this.z = this.layer.style.zIndex;
	}
}
{
p 					= wrapLayer.prototype
p.writeIntoLayer 	= writeIntoLayer
p.layerVis 			= layerVis
p.setLayerPixel		= wrapLayer_setPixel
p.setPixel			= wrapLayer_setPixel
p.nudge				= setRelativePixel
p.setZ				= setLayerZindex
p.setClip 			= setLayerClip
p.getClip			= wrapLayer_getClip
p.raiseTop			= raiseLayerToTop
p.comparePos 		= compareObjPositions
p.load_open			= load_open
p.addCover			= addCover
p.addEvent			= wrapLayer_addEvent
p.clearEvent		= wrapLayer_clearEvent
p.getOffsetWidth	= wrapLayer_getOffsetWidth
p.getOffsetHeight	= wrapLayer_getOffsetHeight
p.getDim			= wrapLayer_getDim
p.getOffsetLeft		= wrapLayer_getOffsetLeft
p.getOffsetTop		= wrapLayer_getOffsetTop		
p.setWidth			= wrapLayer_setWidth
p.setHeight			= wrapLayer_setHeight
}

function makeLayer(zindex,left,top,width,height,bgcolor,show,content,nestref,sId,bForceClip){
	if (oClient.opera){ return false }

	sId = sId || getUniqueID("MakeLayer")
	if (oClient.ie5up) {
		a = document.getElementById(sId)
		if (a) alert("suggested id already exists!\n"+sId+"\n"+a.id)
	}
	if (!content) content = ""
	if (show && show==true) sVis = "visible";
	else if (show) sVis = show;
	else sVis = "hidden"
			
	if (oClient.ns4){
		if (nestref) oDiv = new Layer(zindex, nestref.layer);
		else oDiv = new Layer(zindex);
		oDiv.left = left;
		if (isNaN(top)) alert(top+","+left+","+width+"\n"+makeLayer.caller+"\n"+oClient.ns4up)
		oDiv.top = top;
		oDiv.clip.width = width;
		oDiv.clip.height = height;
		oDiv.zIndex = zindex;
		if (bgcolor  && bgcolor!="transparent") oDiv.bgColor = bgcolor
		if (content){
			oDiv.document.open("text/html");
			oDiv.document.write(content);
			oDiv.document.close();
		}
		oDiv.visibility = sVis
		return oDiv
	} else {

			if (!content) content = ""
			if (show && show==true) vis = "visible";
			else if (show) vis = show;
			else vis = "hidden"
		if (oClient.ie4 || (oClient.mac && oClient.ie5up)){
			var createStr = '<DIV ID="'+sId+'" STYLE="position: absolute;">'+content+'</DIV>'

			if (nestref) nestref.layer.insertAdjacentHTML("BeforeEnd", createStr)
			else document.body.insertAdjacentHTML("BeforeEnd", createStr)
			oDiv = document.all[sId]
		} else {
			var oDiv=document.createElement("DIV");
			if (nestref) nestref.layer.appendChild(oDiv);			
			else document.body.appendChild(oDiv)
			
			oDiv.id = sId
			oDiv.style.position = "absolute"			
			oDiv.innerHTML = content			
		}	
		if (!oDiv.style) alert("Unique ID problem! DAPI CALLING\n"+oDiv.id+"\n"+createStr+"\n"+sId)
		oDiv.style.visibility = sVis;
		oDiv.style.zIndex = zindex;
		if (bgcolor) oDiv.style.backgroundColor = bgcolor
		oDiv.style.left = left+"px";
		oDiv.style.top = top+"px";
	
		oDiv.style.width = width+"px";
		oDiv.style.height = height+"px";
		if (!bForceClip) oDiv.style.clip =  "rect(auto auto auto auto)"	
		else oDiv.style.clip =  "rect("+0+"px "+width+"px "+height+"px "+0+"px)"	
		return oDiv
	}
}

function getUniqueID(sPrefix){
	sId = sPrefix || ""
	if (oClient.ie4 || (oClient.mac && oClient.ie5up)){
		do { a = (sId + Math.round(Math.random()*99999))} while (document.all[a])
		sId = a
	} else if (oClient.ie5up && !oClient.opera){
		sId += document.uniqueID
	} else if (oClient.ns5up || oClient.opera){
		do { a = (sId + Math.round(Math.random()*99999))} while (document.getElementById(a))
		sId = a
	} 
	return sId
}

function wrapLayer_addEvent(sEvent,oFunction,bUseCapture,bIgnoreCoverNS){

	if (oClient.ns5up){
		this.layer.addEventListener(sEvent.substring(2),oFunction,bUseCapture)
	} else if (oClient.pc && oClient.ie5up){	
		this.layer.attachEvent(sEvent,oFunction)
	} else {
		var addCover = (oClient.ns4 && !bIgnoreCoverNS && this.cover)?".cover":"";
		oSetEventTo = (oClient.ns4)?this.obj+addCover+".layer":this.obj+".layer";
		eval(oSetEventTo+"."+ sEvent +"="+ oFunction)
		if (oClient.ns4){
			sCapture = sEvent.substring(2).toUpperCase()
	 		eval(oSetEventTo+".captureEvents(Event."+sCapture+")")
		}
	}
}

function wrapLayer_clearEvent(nEvent){
	argLen = wrapLayer_clearEvent.arguments.length
	args = wrapLayer_clearEvent.arguments
	igCoverPassed = (typeof(args[argLen-1])=="boolean")?true:false;
	ignoreCover = (igCoverPassed)?args[argLen-1]:false;
	var addCover = (oClient.ns4up && !ignoreCover && this.cover)?".cover":"";
	iRunTo = (igCoverPassed)?argLen-1:argLen;
	for (e = 0;e<iRunTo;e++){
		oSetEventTo = (oClient.ns4)?this.obj+addCover+".layer":this.obj+".layer.access";
		sEvent = args[e]
		eval(oSetEventTo+"."+ sEvent +"= null")
		if (oClient.ns4){
			sCapture = sEvent.substring(2).toUpperCase()
 			eval(oSetEventTo+".releaseEvents(Event."+sCapture+")")
		}
	 }
}

function addCover(noWrap){
	var oCoverTemp = new makeLayer(this.z+1,0,0,this.w,this.h,null,"inherit",null,this,this.obj+"cover")
	this.cover	= new wrapLayer(oCoverTemp,this.obj+".cover");
}

function load_open(url,bMultiple) {
	if (this.hasScroll){
		this.reset()	
	}
	if (oClient.ns4){
			this.layer.load(url,this.layer.clip.width)
	} else {
		window.recipLayer = this
		if (bMultiple){
			sId = getUniqueID("ieBufferFrame")
			document.body.insertAdjacentHTML("BeforeEnd","<iframe id=\""+sId+"\" style=\"position: absolute; display: none; visibility: hidden;\" onload=\"transfer('"+sId+"',true)\"></iframe>")
		} else if (!document.all["ieBufferFrame"]){
			sId = "ieBufferFrame"
			document.body.insertAdjacentHTML("BeforeEnd","<iframe id=\"ieBufferFrame\" style=\"position: absolute; display: none; visibility: hidden;\" onload=\"transfer()\"></iframe>")
		}
		document.all[sId].src = url
	}
}

function transfer(sObjBuffer,bAdd) {
	if (recipLayer) {
		if (oClient.ie4up){
			oBuffer = (sObjBuffer)?eval(sObjBuffer):ieBufferFrame;
			if (!bAdd) recipLayer.writeIntoLayer(oBuffer.document.body.innerHTML)
			else {
				recipLayer.layer.insertAdjacentHTML("BeforeEnd",oBuffer.document.body.innerHTML)
			}
		}
		if (typeof(recipLayer.calibrate)!="undefined") recipLayer.calibrate()
		if (typeof(recipLayer.onLoadAction)!="undefined") eval(recipLayer.onLoadAction)
	}
}

function compareObjPositions(request,xpos,ypos,extra){
	if (request == "inside"){
		if (xpos>=this.xpos && xpos<=(this.xpos+this.w) && ypos>=this.ypos && ypos<=(this.ypos+this.h)) return true
		else return false
	}
	if (request == "closeTo"){
		var extra = extra || 15
		if (xpos+extra>=this.xpos && xpos-extra<=(this.xpos+this.w) && ypos+extra>=this.ypos && ypos-extra<=(this.ypos+this.h)) return true
		else return false
	}
	return false
}


function wrapLayer_setWidth(iWidth) {
        if (oClient.ns4) this.layer.clip.right = iWidth
        else this.layer.style.width = iWidth
}

function wrapLayer_setHeight(iHeight) {
        if (oClient.ns4) this.layer.clip.bottom = iHeight
        else this.layer.style.height = iHeight
}

function setLayerClip(clipTop,clipRight,clipBottom,clipLeft){
		clipTop 	= (clipTop!=null)?clipTop:this.getClip('t');
		clipRight 	= (clipRight!=null)?clipRight:this.getClip('r');
		clipBottom 	= (clipBottom!=null)?clipBottom:this.getClip('b');
		clipLeft	= (clipLeft!=null)?clipLeft:this.getClip('l');
	if (oClient.ns4){
		this.layer.clip.top		= clipTop 	
		this.layer.clip.right 	= clipRight	
		this.layer.clip.bottom 	= clipBottom
		this.layer.clip.left 	= clipLeft
	 } else {
		this.layer.style.clip = "rect("+clipTop+"px "+clipRight+"px "+clipBottom+"px "+clipLeft+"px)"
	 }
}

function wrapLayer_getOffsetTop() {
        if (oClient.ns4) rVal = this.layer.top
        else rVal = this.layer.offsetTop
		return rVal
}

function wrapLayer_getOffsetLeft() {
        if (oClient.ns4) rVal = this.layer.left
        else rVal = this.layer.offsetLeft
		return rVal
}

function wrapLayer_getOffsetHeight(bContentHeight) {
        if (oClient.ns4) rVal = (bContentHeight)?this.layer.document.height:this.layer.clip.height;
        else if (oClient.opera) rVal = this.layer.style.pixelHeight
		else rVal = this.layer.offsetHeight
		return rVal
}

function wrapLayer_getDim(vWhich){
	bH = (vWhich == 1 || vWhich == "height")
	if (oClient.ns4) rVal = (bH)?this.layer.document.height:this.layer.document.width;
    else if (oClient.opera) rVal = (bH)?this.layer.style.pixelHeight:this.layer.style.pixelWidth;
	else rVal = (bH)?this.layer.offsetHeight:this.layer.offsetWidth;
	rVal = parseInt(rVal)
	return rVal
}

function wrapLayer_getClip(vWhich,bForceRead) {
		if (!oClient.ns4 && (!this.clip || bForceRead)){
			sClip = this.layer.style.clip
			aClip = sClip.match(/-?[0-9]+/g) //+[a-zA-Z]+
			if (!aClip){ 
				 aClip = [0,this.getDim("width"),this.getDim("height"),0] 
			}
			this.clip = new Object()
			this.clip.top = parseInt(aClip[0])
			this.clip.right = parseInt(aClip[1])
			this.clip.bottom = parseInt(aClip[2])
			this.clip.left = parseInt(aClip[3])
			this.clip.width =this.clip.right - this.clip.left
			this.clip.height =  this.clip.bottom - this.clip.top
		} else if (oClient.ns4 && !this.clip){
			this.clip = this.layer.clip
		}
		oClip = this.clip
		vType = typeof(vWhich)
		if (vType=="string"){
			iRet = this.clip[vWhich]		
		} else {
			aClip = [this.clip.top,this.clip.right,this.clip.bottom,this.clip.left,this.clip.width,this.clip.height]
			if (vType == "undefined") iRet = aClip
			else iRet = aClip[vWhich]
		}
		return iRet
        if (oClient.ns4) aClip = this.layer.clip.height
		else {
			aRe = /([0-9]+)/
			hasClip = aRe.test(this.layer.style.clip)
			if (hasClip){
				aClip = this.layer.style.clip.split("rect(")[1].split(")")[0].split("px")
				rVal = aClip[2]
			} else {
				rVal = this.getDim(0)
			}

		}
		rVal = parseInt(rVal)
		return rVal
}

function wrapLayer_getOffsetWidth(bContentWidth) {
        if (oClient.ns4) rVal = (bContentWidth)?this.layer.document.width:this.layer.clip.width;
        else rVal = this.layer.offsetWidth
		return rVal
}

function raiseLayerToTop(){
	var atZ = this.z
	if (oClient.ns4up) for (i=0;i<document.layers.length;i++){
		if (document.layers[i].zIndex>atZ) atZ=document.layers[i].zIndex
	} else {
		eZ=document.all.tags("DIV")
		for (i=0;i<eZ.length;i++) if (eZ[i].style.zIndex>atZ) atZ = eZ[i].style.zIndex
	}
	this.setZ(atZ+1)
}

function setLayerZindex(z){
	this.layer.zIndex = this.z = z
}

function setRelativePixel(pLeft,pTop){
	if (oClient.ie4 || oClient.ns4){
		if (pLeft!=null) this.layer.left = this.xpos += pLeft
		if (pTop!=null) this.layer.top = this.ypos += pTop
	}
}

function wrapLayer_setPixel(pLeft,pTop){
	if (pLeft!=null) this.layer.style.left = this.xpos = pLeft
	if (pTop!=null) this.layer.style.top = this.ypos = pTop
}

function layerVis(visible){
	if (visible && visible==true) vis = "visible";
	else if (visible) vis = visible;
	else vis = "hidden";
	this.layer.style.visibility = vis
}

function writeIntoLayer(htmlContent){
	if (oClient.ns4) {
		this.layer.document.open("text/html")
		this.layer.document.write(htmlContent)
		this.layer.document.close()
	} else {
		this.layer.innerHTML = htmlContent
	}
}
