// A small API that adds basic dHTML functionality to layers
// Morten Haugaard Jeppesen 1999 (c)

function BrowserCheck() {
	this.ns = ((navigator.appName == 'Netscape' || navigator.appName == 'Mozilla') && parseInt(navigator.appVersion) >= 4);
	this.ie = (navigator.appName == 'Microsoft Internet Explorer' && parseInt(navigator.appVersion) >= 4);
	this.dhtml = (this.ns || this.ie);
	this.win = (/Win/.test(navigator.userAgent));
	this.dom = (document.getElementById);
	this.ns4 = (this.ns && !this.dom);
	this.ns5up = (this.ns && this.dom);
	this.ie4 = (this.ie && !this.dom);
	this.ie5up = (this.ie && this.dom);
	this.iew = (this.ie && this.win);
}
is = new BrowserCheck();

var prefix = (is.ns4) ? 'document.' : '';
var suffix = (is.ns4) ? '' : '.style';
var showVar = (is.ns4) ? 'show' : 'visible';
var hideVar = (is.ns4) ? 'hide' : 'hidden';

function ProtoObj(objName,eleId,nestRef)    {
	this.objName = objName;
	this.eleId = eleId;
	this.flag = 0;
	if (!is.dom)	{
		this.nestRef = (is.ns && nestRef) ? nestRef : '';
		this.css = eval(this.nestRef + prefix + eleId + suffix);
		this.ele = (is.ns) ? this.css : eval(this.eleId);
	}
	else if (is.dom)	{
		this.ele = document.getElementById(eleId);
		this.css = this.ele.style;
	}
	this.xPos = (is.ns4) ? this.css.left : this.ele.offsetLeft;
	this.yPos = (is.ns4) ? this.css.top : this.ele.offsetTop;
}

ProtoObj.prototype.show = function doShow() {this.css.visibility = showVar; if (is.dom) this.css.display = 'block'}
ProtoObj.prototype.hide = function doHide() {this.css.visibility = hideVar; if (is.dom) this.css.display = 'none'}
ProtoObj.prototype.moveTo = function doMoveTo(x,y) {this.xPos = x; this.css.left = this.xPos; this.yPos = y; this.css.top = this.yPos;}
ProtoObj.prototype.moveBy = function doMoveBy(x,y) {this.moveTo(this.xPos + x,this.yPos + y);}
ProtoObj.prototype.clipTo = function doClipTo(t,r,b,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 + ',' +  r + ',' +  b + ',' + l + ')';}

// Not part of the API - it's here because I use it frequently
function loadImgs(imgArray,one,two)	{
	var path = ''; var ext = 'gif';	var imgAr = new Array();
	if (two && one.search('/') < 0) {ext = one; path = two;}
	else if (two) {ext = two; path = one;}
	else if (one && one.search('/') < 0) ext = one;
	else if (one) path = one;
	if (is.ns5up) {writeImgs(imgArray,path,ext); return} // this is a hack dealing with the fact that ns6 can't cache
	for (var i = 0; i < imgArray.length; i++) {
		imgAr[i] = new Image();
		imgAr[i].src = path + imgArray[i] + '.' + ext;
	}
}

function writeImgs(imgArray,path,ext)	{
	document.write('<DIV STYLE="position: absolute; top: -10000px; left: -10000px; width: 10000px; visibility: hidden">');
	for (var i = 0; i < imgArray.length; i++) document.write('<img src="' + path + imgArray[i] + '.' + ext + '">');
	document.write('<\/DIV>')
}

window.offscreenBuffering = true;
