/* 	File: dhtml_api_v3.js
 *	Include: <script language="JavaScript" src="scripts/dhtml_api_v3.js"></script>	
 *	
 *	This code is specific to DOM Level 1, Microsoft Internet Explorer 4+ and Netscape Navigator 4+
 *	Based upon code found in "JavaScript - The Definitive Guide (3rd Edition)" by David Flanagan
 *	O'Reilly Publishing - Chapter 17, Page 326.
 *
 *	Modified for my own style and needs.
 *	April 28, 2000
 */

// LAST MODIFIED 3/15/2002 //

// DEFINE Global Variables//

var DL1 = (document.implementation && document.implementation.hasFeature && document.implementation.hasFeature("html","1.0")) ? true : false;
var IE4 = ((navigator.appName.indexOf("Microsoft") != -1) && document.all) ? true : false;
var NS4 = ((navigator.appName.indexOf("Netscape") != -1) && document.layers) ? true : false;

// For old browsers //
if (!(DL1) && !(IE4) && !(NS4)) {
	alert ("This page contains Dynamic elements that your browser does not support.");
	window.onerror =  function() { return true };
}

// This is for Navigators resize bug. Stolen from Dreamweaver. //
function reloadPage(init) {
  if (init == true) {
	  	if (NS4) {
	    document.pageWidth = innerWidth; 
		document.pageHight = innerHeight; 
		onresize = reloadPage;
		}
	}
  else if (innerWidth != document.pageWidth || innerHeight != document.pageHight) location.reload();
}
reloadPage(true);

// Object constructor. //
// REMEMBER to call the init() method of the dynLayer after the page loads //
function dynLayer(oWin,sName,x,y,w,h,z){
	this.window = oWin;
	this.name = sName;
	this.id = sName.replace(/\W/g,"") + "Id"; 
	this.x = x;
	this.y = y;
	this.w = w;
	this.h = h;
	this.z = z;
}

// This is for outputting the Layer CSS information. //
dynLayer.prototype.outputStyle = function(VISIBLE) {
	var isVisible = (VISIBLE) ? "visible" : "hidden";
	this.window.document.write('<style type="text/css">\n#',this.id,' { position: absolute; left: ',this.x,'px; top: ',this.y,'px; width: ',this.w,'px; height: ',this.h,'px; z-index: ',this.z,'; visibility: ',isVisible,'; }\n</style>');
}

// use this if you want to automatically output the layer //
// IMPORTANT: you can only call this from withing the <body> //
dynLayer.prototype.outputLayer = function(BODY) {
	var bodyHtml = (BODY) ? BODY : "&nbsp;";
	this.window.document.write('<div id="' + this.id + '">' + bodyHtml + '</div>');
}

// DOM Level 1 Portion //
if (DL1) {
	window.status = "Using DOM Level 1";
	dynLayer.prototype.init = function() { 
		var doc = this.window.document;
		this.element = doc.getElementById(this.id);
		this.style = this.element.style;
		this.moveTo(this.x,this.y);
		}
	dynLayer.prototype.moveTo = function(x,y) { 
		this.style.left = x + "px";
		this.style.top = y + "px"; 
	}
	dynLayer.prototype.moveBy = function(x,y) { 
		this.style.left = (this.getX() + x) + "px"; 
		this.style.top = (this.getY() + y) + "px"; 
	}
	dynLayer.prototype.show = function() { this.style.visibility = "visible"; }
	dynLayer.prototype.hide = function() { this.style.visibility = "hidden"; }
	dynLayer.prototype.togVisible = function() { 
		if (this.style.visibility == "hidden") this.style.visibility = "visible";
		else this.style.visibility = "hidden";
	}
	dynLayer.prototype.setZ = function(z) { this.style.zIndex = z.toString(); }
	dynLayer.prototype.setBgColour = function(colour) { this.style.backgroundColor = colour; }
	dynLayer.prototype.setBgImage = function(image) { this.style.backgroundImage = "URL(" + image + ")"; }
	dynLayer.prototype.setWidth = function(value) { this.style.width = value + "px"; }
    dynLayer.prototype.setHeight = function(value) { this.style.height = value + "px"; }
    
	dynLayer.prototype.getX = function() { return parseInt(this.style.left); } 
	dynLayer.prototype.getY = function() { return parseInt(this.style.top); }
    dynLayer.prototype.getWidth = function() { return parseInt(this.style.width); }
    dynLayer.prototype.getHeight = function() { return parseInt(this.style.height); }
    
	dynLayer.prototype.setBody = function() {
		var body = "";
			for (var i = 0; i < arguments.length; i++){ 
				body += arguments[i] + "\n";
			}
			this.element.innerHTML = body;
	}
}


// Netscape 4 portion //
else if (NS4) {
	window.status = "Using Netscape 4 API";
	dynLayer.prototype.init = function() { 
		var doc = this.window.document;
		this.layer = doc[this.id];
		this.moveTo(this.x,this.y);
		}
	dynLayer.prototype.moveTo = function(x,y) { this.layer.moveTo(x,y); }
	dynLayer.prototype.moveBy = function(x,y) { this.layer.moveBy(x,y); }
	dynLayer.prototype.show = function() { this.layer.visibility = "show"; }
	dynLayer.prototype.hide = function() { this.layer.visibility = "hide"; }
	dynLayer.prototype.togVisible = function() { 
		if (this.layer.visibility == "hide") this.layer.visibility = "show";
		else this.layer.visibility = "hide";
	}
	dynLayer.prototype.setZ = function(z) { this.layer.zIndex = z; }
	dynLayer.prototype.setBgColour = function(colour) { this.layer.bgColor = colour; }
	dynLayer.prototype.setBgImage = function(image) { this.layer.background.src = image; }
	dynLayer.prototype.setWidth = function(value) { this.layer.clip.width = value; }
    dynLayer.prototype.setHeight = function(value) { this.layer.clip.height = value; }
    
	dynLayer.prototype.getX = function() { return this.layer.left; } 
	dynLayer.prototype.getY = function() { return this.layer.top; }
    dynLayer.prototype.getWidth = function() { return this.layer.clip.width; }
    dynLayer.prototype.getHeight = function() { return this.layer.clip.height; }
    
	dynLayer.prototype.setBody = function() {
			for (var i = 0; i < arguments.length; i++){
				
				this.layer.document.write(arguments[i]);
			}
			this.layer.document.close();
	}
}

// IE 4 portion //
else if (IE4) {	
	window.status = "Using Internet Explorer 4 API";
	dynLayer.prototype.init = function() { 
		var doc = this.window.document;
		this.element = doc.all[this.id];
		this.style = this.element.style;
		this.moveTo(this.x,this.y);
		}
	dynLayer.prototype.moveTo = function(x,y) { this.style.pixelLeft = x; this.style.pixelTop = y; }
	dynLayer.prototype.moveBy = function(x,y) { this.style.pixelLeft +=  x; this.style.pixelTop += y; } 
	dynLayer.prototype.show = function() { this.style.visibility = "visible"; }
	dynLayer.prototype.hide = function() { this.style.visibility = "hidden"; }
	dynLayer.prototype.togVisible = function() { 
		if (this.style.visibility == "hidden") this.style.visibility = "visible";
		else this.style.visibility = "hidden";
	}
	dynLayer.prototype.setZ = function(z) { this.style.zIndex = z; }
	dynLayer.prototype.setBgColour = function(colour) { this.style.backgroundColor = colour; }
	dynLayer.prototype.setBgImage = function(image) { this.style.backgroundImage = image; }
	dynLayer.prototype.setWidth = function(value) { this.style.width = value; }
    dynLayer.prototype.setHeight = function(value) { this.style.height = value; }
    
	dynLayer.prototype.getX = function() { return this.style.pixelLeft; } 
	dynLayer.prototype.getY = function() { return this.style.pixelTop; }
    dynLayer.prototype.getWidth = function() { return this.style.pixelWidth; }
    dynLayer.prototype.getHeight = function() { return this.style.pixelHeight; }
    
	dynLayer.prototype.setBody = function() {
		var body = "";
			for (var i = 0; i < arguments.length; i++){ 
				body += arguments[i] + "\n";
			}
			this.element.innerHTML = body;
	}
}

// TOOLS //
function getWindowHeight() {
    if (NS4) return window.innerHeight;
    else if (IE4) return document.body.scrollHeight; //REMEMBER use <table width="100%" height="100%"> for IE height detect.
    return 0;
}

function getWindowWidth() {
	if (NS4) return window.innerWidth;
    else if (IE4) return document.body.scrollWidth;
    return 0;
}

function getTopOffset() {
    if (NS4) return window.pageYOffset;
    else if (IE4) return document.body.scrollTop;
}

function getLeftOffset() {
    if (NS4) return window.pageXOffset;
    else if (IE4) return document.body.scrollLeft;
}

// place in body tag: onResize="reloadResize();"
function reloadResize() {
    if (IE4) window.location.reload();
	else if (NS4) reloadPage();
}

//DEFINE API
var dhtml_api = true;

//uncommment this and paste this into your page - fixes yet another bug in Netscrap.
//if (typeof dhtml_api == "undefined") window.location.reload();
