// zodapi.js version=2.1 - custom API for cross-platform DHTML
// (c) Zero-One Design Limited

// Global variables
var isNav, isIE
var coll = ""
var styleObj = ""
if (parseInt(navigator.appVersion) >= 4) {
	if (navigator.appName == "Netscape") {
		isNav = true
	} else {
		isIE = true
		coll = "all."
		styleObj = ".style"
	}
}

// Convert object name string or object reference into a valid object reference
function getObject(obj) {
	var theObj
	if (typeof obj == "string") {
		theObj = eval("document." + coll + obj + styleObj)
	} else {
		theObj = obj
	}
	return theObj
}

// Positioning an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
	var theObj = getObject(obj)
	if (isNav) {
		theObj.moveTo(x,y)
	} else {
		theObj.pixelLeft = x
		theObj.pixelTop = y
	}
}

// Moving an object by x and/or y pixels
function shiftBy(obj, deltaX, deltaY) {
	var theObj = getObject(obj)
	if (isNav) {
		theObj.moveBy(deltaX, deltaY)
	} else {
		theObj.pixelLeft += deltaX
		theObj.pixelTop += deltaY
	}
}

// Setting the z-order of an object
function setZIndex(obj, zOrder) {
	var theObj = getObject(obj)
	theObj.zIndex = zOrder
}

// Setting the background color of an object
function setBGColor(obj, color) {
	var theObj = getObject(obj)
	if (isNav) {
		theObj.bgColor = color
	} else {
		theObj.backgroundColor = color
	}
}

// Setting the visibility of an object to visible
function show(obj) {
	var theObj = getObject(obj)
	theObj.visibility = "visible"
}

// Setting the visibility of an object to hidden
function hide(obj) {
	var theObj = getObject(obj)
	theObj.visibility = "hidden"
}

// Retrieving the x coordinate of a positionable object
function getObjLeft(obj)  {
	var theObj = getObject(obj)
	if (isNav) {
		return theObj.left
	} else {
		return theObj.pixelLeft
	}
}

// Retrieving the y coordinate of a positionable object
function getObjTop(obj)  {
	var theObj = getObject(obj)
	if (isNav) {
		return theObj.top
	} else {
		return theObj.pixelTop
	}
}

// Get x coordinate of a positionable object relative to page
function getPageLeft(obj)  {
	if (isNav) {
		return obj.pageX
	} else {
		return obj.offsetLeft
	}
}

// Get y coordinate of a positionable object relative to page
function getPageTop(obj)  {
	if (isNav) {
		return obj.pageY
	} else {
		return obj.offsetTop
	}
}


// ******* clipping *********
//set visible region of positionable object
function clipRegion(obj, t, r, b, l) {
	if (isNav) {
		obj.clip.top	= t;
		obj.clip.right	= r;
		obj.clip.bottom	= b;
		obj.clip.left	= l;
	} else {
		obj.clip = 'rect(' + t + 'px ' + r + 'px ' + b + 'px ' + l + 'px ' + ')';
	}
}


// ******* window stuff *********
// Retrieving the available content width space in browser window
function getInsideWindowWidth() {
	if (isNav) {
		return window.innerWidth;
	} else {
		return document.body.clientWidth;
	}
}

// Retrieving the available content height space in browser window
function getInsideWindowHeight() {
	if (isNav) {
		return window.innerHeight;
	} else {
		return document.body.clientHeight;
	}
}

// set the content width in browser window
function setInsideWindowWidth(w) {
	if (isNav) {
		window.innerWidth = w;
	} else {
		document.body.clientWidth = w;
	}
}

// set the content height in browser window
function setInsideWindowHeight(h) {
	if (isNav) {
		window.innerHeight = h;
	} else {
		document.body.clientHeight = h;
	}
}

// Retrieving the width of the browser window
function getOutsideWindowWidth() {
	if (isNav) {
		return window.outerWidth;
	} else {
		return document.body.clientWidth;
	}
}

// Retrieving the height of the browser window
function getOutsideWindowHeight() {
	if (isNav) {
		return window.outerHeight;
	} else {
		return document.body.clientHeight;
	}
}

//*** new stuff ***
var isDHTML = 0;
var isID = 0;
var isAll = 0;
var isLayers = 0;

if(document.getElementById) {
	isID = 1;
	isDHTML = 1;
} else if(document.all) {
	isAll = 1;
	isDHTML = 1;
} else {
	browserVersion = parseInt(navigator.appVersion);

	if((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {
		isLayers = 1;
		isDHTML = 1;
	}
}

//get DOM (required for some newer functions!)
function getDOM(objID) {
	if(isID) {
		return document.getElementById(objID);
	} else if(isAll) {
		return document.all[objID];
	} else if(isLayers) {
		return document.layers[objID];
	}
}

//get DOM (required for some newer functions!)
function getDOMstyle(objID) {
	if(isID) {
		return document.getElementById(objID).style;
	} else if(isAll) {
		return document.all[objID].style;
	} else if(isLayers) {
		return document.layers[objID];
	}
}

//get width of object
function getObjWidth(objID) {
	var dom = getDOM(objID);

	if(dom.offsetWidth) return dom.offsetWidth;
	if(dom.clip.width) return dom.clip.width;
	return (null);
}

//get height of object
function getObjHeight(objID) {
	var dom = getDOM(objID);

	if(dom.offsetHeight) return dom.offsetHeight;
	if(dom.clip.height) return dom.clip.height;
	return (null);
}

//get x coord of mouse
function getXCoord(evt) {
	if(evt.x) return evt.x;
	if(evt.pageX) return evt.pageX;
}

//get y coord of mouse
function getYCoord(evt) {
	if(evt.y) return evt.y;
	if(evt.pageY) return evt.pageY;
}

// Retrieving the x coordinate of a positionable object
function getLeft(objID)  {
	var domStyle = getDOMstyle(objID);
	var dom = getDOM(objID);

	if(domStyle.left)
		return domStyle.left;
	else if(domStyle.pixelLeft)
		return domStyle.pixelLeft;
	else if(dom.offsetLeft)
		return dom.offsetLeft;
	else
		return null;
}

function showObj(objID) {
	var dom = getDOMstyle(objID);
	dom.visibility = "visible";
}

function hideObj(objID) {
	var dom = getDOMstyle(objID);
	dom.visibility = "hidden";
}
