/*==================================================================
 Copyright (c) Syzygy LTD 1999	(http://www.syzygy.net)
 All rights reserved.

 This program may not be used, copied, modified, distributed or sold
 wholly or as part of any package without explicit consent from 
 Syzygy LTD.
 ===================================================================*/
//	DHTML LAYER INTERFACE
//
//	Docs:		DHTMLAPI_user_guide.doc
//	Requires:	-
//	Language:	Javascript 1.2
//	Version:	3.4.4
//	Modified:	27/09/2000
//	
//	Use: myLayer = new LayerObj("div id"[,"branch"]);
//	where branch is in the form "parent.child.leaf"


//	Global objects //
var UA = new UserAgent();
nsResizeInit();

// Static property
LayerObj.byID = new Object();
LayerObj.error = LayerObj_error;


//	Layer wrapper object
//	Instantiated manually for each layer required
//	Args: div layer id
function LayerObj() {
	if(typeof UA == "undefined") UA = new UserAgent();
	var args = arguments;
	
	//	Create ref to layers, mod 11/01/2000
	var layersAll = null;
	
	if(UA.NS) layersAll = document.layers; // NS4 only collection
	if(UA.IE) layersAll = document.all; // IE4/5 only collection
	
	// resolve ref to layer for passed ID
	var myLayer = eval("layersAll."+resolveNest(args[0],args[1]));
	if(typeof myLayer == "undefined")
		return LayerObj.error(args[0],
		"cannot be found (invalid layer id)");
	this.ID = myLayer.id;
	
	//	create ref to this, for recursive methods
	LayerObj.byID[this.ID] = this;
	
	this.layer = myLayer;

	this.style = (UA.IE)? this.layer.style:this.layer;
	
	return true;
}

//	Assign Methods //
LayerObj.prototype.hide = LayerObj_hide;
LayerObj.prototype.show = LayerObj_show;
LayerObj.prototype.getVisibility = LayerObj_getVisibility;
LayerObj.prototype.getLeft = LayerObj_getLeft;
LayerObj.prototype.getTop = LayerObj_getTop;
LayerObj.prototype.getWidth = LayerObj_getWidth;
LayerObj.prototype.getHeight = LayerObj_getHeight;
LayerObj.prototype.setLeft = LayerObj_setLeft;
LayerObj.prototype.setTop = LayerObj_setTop;
LayerObj.prototype.moveTo = LayerObj_moveTo;
LayerObj.prototype.moveBy = LayerObj_moveBy;
LayerObj.prototype.setZindex = LayerObj_setZindex;
LayerObj.prototype.getZindex = LayerObj_getZindex;
LayerObj.prototype.getLayerDoc = LayerObj_getLayerDoc;
LayerObj.prototype.clipTo = LayerObj_clipTo;
LayerObj.prototype.clipBy = LayerObj_clipBy;
LayerObj.prototype.getClipTop = LayerObj_getClipTop;
LayerObj.prototype.getClipRight = LayerObj_getClipRight;
LayerObj.prototype.getClipBottom = LayerObj_getClipBottom;
LayerObj.prototype.getClipLeft = LayerObj_getClipLeft;
LayerObj.prototype.getClipWidth = LayerObj_getClipWidth;
LayerObj.prototype.getClipHeight = LayerObj_getClipHeight;
LayerObj.prototype.clipInit = LayerObj_clipInit;

LayerObj.prototype.getWinHeight = LayerObj_getWinHeight;
LayerObj.prototype.getWinWidth = LayerObj_getWinWidth;


//	Define methods //
function LayerObj_hide() {
	this.style.visibility = (UA.IE)? "hidden":"hide";
}

function LayerObj_show() {
	this.style.visibility = (UA.IE)? "inherit":"show";
}

function LayerObj_getVisibility() {
	var v = this.style.visibility;
	//	NS-show, IE-visible, All-inherit
	if (v == "show" || v == "visible" || v == "inherit")
		return true;
	else
		return false;
}

function LayerObj_getLeft() {
	if(UA.IE5 && UA.Win) return this.layer.offsetLeft;
	else if(UA.IE) return this.style.pixelLeft;
	else return this.layer.left;
}

function LayerObj_getTop() {
	if(UA.IE5 && UA.Win) return this.layer.offsetTop;
	else if(UA.IE) return this.style.pixelTop;
	else return this.style.top;
}

function LayerObj_setLeft(x) {
	this.style.left = x
}

function LayerObj_setTop(y) {
	this.style.top = y
}

function LayerObj_moveTo(x, y) {
	this.setLeft(x);
	this.setTop(y);
}

function LayerObj_moveBy(x, y) {
	this.setLeft(this.getLeft() + x);
	this.setTop(this.getTop() + y);
}

function LayerObj_setZindex(z) { this.style.zIndex = z }
function LayerObj_getZindex() { return this.style.zIndex }

function LayerObj_getWidth() {
	if(UA.IE5) return this.layer.offsetWidth;
	else if(UA.IE) return this.style.pixelWidth
	else return this.layer.document.width;
}
function LayerObj_getHeight() {
	if(UA.IE5) return this.layer.offsetHeight;
	else if (UA.IE) return this.style.pixelHeight;
	else return this.layer.document.height;
}

function LayerObj_getLayerDoc() {
	var doc = self;
	if (UA.NS) doc = this.layer.document;
	return doc;
}

function LayerObj_getClipTop() {
	if (UA.IE) return stripClip(this.style.clip,0);
	else return this.style.clip.top;
}
function LayerObj_getClipRight() {
	if (UA.IE) return stripClip(this.style.clip,1);
	else return this.style.clip.right;
}
function LayerObj_getClipBottom() {
	if (UA.IE) return stripClip(this.style.clip,2);
	else return this.style.clip.bottom;
}
function LayerObj_getClipLeft() {
	if (UA.IE) return stripClip(this.style.clip,3);
	else return this.style.clip.left;
}

function LayerObj_getClipWidth() {
	if (UA.IE) return this.layer.clientWidth;
	else return this.style.clip.width;
}
function LayerObj_getClipHeight() {
	if (UA.IE) return this.layer.clientHeight;
	else return this.style.clip.height;
}

function LayerObj_clipTo(t,r,b,l) {
	if(UA.IE) {
		var clipStr = "rect("+t+"px,"+r+"px,"+b+"px,"+l+"px)";	
		this.style.clip = clipStr;
	} else {
		this.style.clip.left = l;
		this.style.clip.right = r;
		this.style.clip.top = t;
		this.style.clip.bottom = b;
	}
}

function LayerObj_clipBy(t,r,b,l) {
	var top = this.getClipTop() - t;
	var right = this.getClipRight() - r;
	var bottom = this.getClipBottom() - b;	
	var left = this.getClipLeft() - l;
	this.clipTo(top,right,bottom,left);
}

function LayerObj_clipInit(t,r,b,l) {
	//	Initialise clip values -
	//	if no arguments passed, will clip to layer size
	if (arguments.length < 4) {
		// clip to layer size
		t= 0;
		r= this.getWidth();
		b= this.getHeight();
		l= 0;
	}
	this.clipTo(t,r,b,l)
}

function LayerObj_getWinHeight() {
	if(UA.NS) return self.innerHeight;
	else return self.document.body.clientHeight;
}
function LayerObj_getWinWidth() {
	if(UA.NS) return self.innerWidth;
	else return self.document.body.clientWidth;
}
// catch invalid layer refs and report if debug is enabled
function LayerObj_error(offender, msg) {
	var errMsg = "DHTMLAPI: `"+offender+"` "+msg;
	if(typeof debug != "undefined" && debug) alert(errMsg);
	else self.status = errMsg;
		
	window.onerror = function() { 
		if(typeof debug != "undefined" && debug) return false;
		else return true;
		};
	return false;
}

//	General functions //

// UserAgent constructor
// Use: UA = new UserAgent();
// Version: 2.0 [01/08/2000]
function UserAgent() {
	this.agent = navigator.userAgent.toLowerCase();
	this.vers = parseFloat(navigator.appVersion);
	this.major = parseInt(navigator.appVersion);
	
	this.Mac = (this.agent.indexOf("mac")!=-1);
	this.Win = (this.agent.indexOf("win")!=-1);
	this.Aol = (this.agent.indexOf("aol")!=-1);// does not work on Aol/IE3
	this.Nav = ((this.agent.indexOf('mozilla')!=-1) 
		&& (this.agent.indexOf('spoofer')==-1) 
		&& (this.agent.indexOf('compatible') == -1)
		// these will detect opera / webtv, 
		//	commenting them out will include them as `Nav`
		// && (this.agent.indexOf('opera')==-1) 
		// && (this.agent.indexOf('webtv')==-1)
	);
	this.MSIE = false;
		
	var msver = this.agent.indexOf("msie");
	if (msver != -1) {
		var msver = this.agent.substring(msver+5,this.agent.length);
		this.MSIE = true;
		this.vers = parseFloat(msver);
		this.major = parseInt(msver);
	}
	
	// derived from useragent string
	this.NS4 = (this.Nav && this.major == 4);
	this.IE4 = (this.MSIE && this.major == 4);
	this.IE5 = (this.MSIE && this.major == 5);
	this.NS5 = (this.Nav && this.major == 5);
	
	// derived from objects
	this.DOM1 = (document.getElementById)? true:false;
	this.layer = (document.layers)? true:false;
	this.all = (document.all)? true:false;
	
	//	the following are for kept historic reasons
	//	from original LayerObj implementation
	this.NS = this.layer;
	this.IE = this.all;
}

//	Fixes the NS4 / CSS resize bug.
//	forces a reload of the page if the window is resized
function nsResizeInit() {
	if (UA.NS) {
		if (typeof document.NsResize == 'undefined') {
			document.NsResize = new Object;
			document.NsResize.w = window.innerWidth;
			document.NsResize.h = window.innerHeight;
		}
		window.onresize = nsResizeFix;
	}
}
function nsResizeFix() {
	if (document.NsResize.w != window.innerWidth
	|| document.NsResize.h != window.innerHeight) {
		document.location = document.location;
	}
}

// resolve dot branch to actual NS DOM ref
//	RegExp is NS4+, IE5+ only
function resolveNest(leaf, branch) {
	var result;
	if (UA.NS && branch) {
		branch += '.'+leaf;
		result = branch.replace(/\./g, ".document.");
	} else {
		result = leaf;
	}
	return result;
}

// returns specified index of CSS clip string
function stripClip(clipStr, index) {
	var retval = "";
	var clipArray = clipStr.match(/\d+/g);
	if (clipArray[index] != null) {
		retval = clipArray[index];
	}
	return retval;
}

// LAYEROBJ END


