//	LayerLite
//	Syzygy Ltd 07/01/2002
//	Lightweight API, provides hide show and replace methods
//	Requires:	-
//	Language:	Javascript 1.2
//	Version $Name:  $ [1.2]
//	$Author: tbrown $
//	$Date: 2002/07/15 13:55:15 $
//	$Revision: 1.1.1.1 $


// LayerLite constructor
function LayerLite(id, win) {
	this.ID = id;	
	this.layer = null;
	this.unit = "px";// for NS6
	win = (win)? win: self;
	var d = win.document;
	if(d.layers) {
		this.isNS4 = true;
		this.layer = getNsLayer(id, win);
	}
	else if(d.all) {
		this.isAll = true;
		this.layer = d.all[id];
	}
	else if(d.getElementById) {
		this.isDOM = true;
		this.layer = d.getElementById(id);
	}
	if(!this.layer) {
		if(typeof debug != "undefined" && debug)
			alert("LayerLite layer not found for "+id);
		return;
	} 
	this.style = (this.isNS4)? this.layer: this.layer.style;
	return;
}

// Methods:
LayerLite.prototype.show = function () {
	if(this.isNS4) this.style.visibility = "show";
	else this.style.visibility = "visible";
}
LayerLite.prototype.hide = function () {
	if(this.isNS4) this.style.visibility = "hide";
	else this.style.visibility = "hidden";
}
LayerLite.prototype.setLeft = function (x) {
	if(this.isDOM) x += this.unit;
	this.style.left = x;
}
LayerLite.prototype.setTop = function (y) {
	if(this.isDOM) y += this.unit;
	this.style.top = y;
}
LayerLite.prototype.moveTo = function (x, y) {
	this.setLeft(x);
	this.setTop(y);
}
LayerLite.prototype.replace = function (content) {
	if (this.isNS4) {
		this.layer.document.open();
		this.layer.document.write(content);
		this.layer.document.close();
	}
	else if (this.isAll) {
		this.layer.innerHTML = content;
	}
	else if (this.isDOM) {
		var r = this.layer.ownerDocument.createRange();
		r.selectNodeContents(this.layer);
		r.deleteContents();
		var df = r.createContextualFragment(content);
		this.layer.appendChild(df);
	}
}

function getNsLayer(id, el) {
	el = (el)? el:self;
	var layers = el.document.layers;
	if(layers[id]) return layers[id];
	for(var i=0; i<layers.length; i++) {
		return getNsLayer(id, layers[i]);
	}
	return null;
}

//	Fixes the NS4 / CSS resize bug.
nsResizeInit();
function nsResizeInit() {
	if (document.layers) {
		if (typeof document.NsResize == 'undefined')
			document.NsResize = {w:window.innerWidth, h:window.innerHeight}
		window.onresize = nsResizeFix;
	}
}
function nsResizeFix() {
	if (document.NsResize.w != window.innerWidth
	|| document.NsResize.h != window.innerHeight) {
		document.location = document.location;
	}
}

