//
// Zoo dHTML API
// 2001
//

var windowWidth;
var windowHeight;
var origWidth;
var origHeight;
var xcenter;
var ycenter;
var prefix;
var suffix;
var leftRef;
var topRef;
var is;


// object zoo_browserCheck();

// In order to use any of the functions in the Zoo dHTML API
// zoo_browserCheck must be called first.

// It prepares all of the variables used to differentiate
// between various browsers' implementations of dHTML

// It also creates the "is" object, which at this writing has
// one of three properties: ie, ns6, or ns4.

// Test for a browser thus: 
// if (is.ns4) do something for netscape 4;

// Call zoo_browserCheck like so:
// is = new zoo_browserCheck();


function zoo_browserCheck() {

	var b = navigator.appName;
	
	if (b == "Netscape"){
		this.b = "ns";
	}
	else if (b == "Microsoft Internet Explorer"){
		this.b = "ie";
	}
	else{
		this.b = b;
	}
	
	this.v = parseFloat(navigator.appVersion);

        this.ns61 = (this.b=="ns" && (navigator.userAgent.indexOf('6.1')>0))
	
	// Netscape 4
	if ((this.b=="ns") && (this.v>=4) && (this.v<5)){
		this.ns4 = true;
		windowWidth=window.innerWidth;
		windowHeight=window.innerHeight;
		prefix = 'document.';
		suffix = '';
		leftRef = ".pageX";
		topRef = ".pageY";
	}
	
	// Netscape 6
	if ((this.b=="ns") && (this.v>=5)){
		this.ns6 = true;
		windowWidth=window.innerWidth;
		windowHeight=window.innerHeight;
		prefix = 'document.getElementById("';
		suffix = '").style';
		leftRef = ".left";
		topRef = ".top";
	}
	
	// Explorer
	if (this.b=="ie" && this.v>=4){
		this.ie = true;
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
    	prefix = 'document.all.';
    	suffix = '.style';
		leftRef = ".pixelLeft";
		topRef = ".pixelTop";
	}
	
	this.min = (this.v>=4);
	
	var plat = navigator.platform;
	
	if (plat == "Win32")
		this.win = true;
	
	if (plat == "MacPPC")
		this.mac = true;
}

// FUNCTIONS BEGIN HERE

// zoo_position()
// zoo_getX()
// zoo_setX()
// zoo_getY()
// zoo_setY()
// zoo_getZ()
// zoo_setZ()
// zoo_swapZ()
// zoo_show()
// zoo_hide()
// zoo_getWidth()
// zoo_getHeight()
// zoo_clip()
// zoo_changeImage()
// zoo_getImgX()

// void zoo_position(string id, int x, int y);
function zoo_position(id, x, y){
	zoo_setX(id, x);
	zoo_setY(id, y);
}

// int zoo_getX(string id);
function zoo_getX(id){
	eval("x = "+prefix+id+suffix+leftRef);
	return x;
}

// void zoo_setX(string id, int x);
function zoo_setX(id, x){
	eval (prefix+id+suffix+leftRef+" = "+x);
}

// int zoo_getY(string id);
function zoo_getY(id){
	eval("y = "+prefix+id+suffix+topRef);
	return y;
}

// void zoo_setY(string id, int y);
function zoo_setY(id, y){
	eval (prefix+id+suffix+topRef+" = "+y);
}

// int zoo_getZ(string id);
function zoo_getZ(id){
	eval ("zindex = "+prefix+id+suffix+".zIndex");
	return zindex;
}

// void zoo_setZ(string id, int zindex);
function zoo_setZ(id, zindex){
	eval (prefix+id+suffix+".zIndex = "+zindex);
}

// void zoo_swapZ(string id1, string id2);
function zoo_swapZ(id1, id2){
}

// void zoo_show(string id);
function zoo_show(id){
	eval(prefix+id+suffix+'.visibility = "visible"');
}

// void zoo_hide(string id);
function zoo_hide(id){
	eval(prefix+id+suffix+'.visibility = "hidden"');
}

// string getVisibility(string id)
function getVisibility(id){
	eval("visibility = "+prefix+id+suffix+".visibility");
	if (visibility == "zoo_show"){
		visibility = "visible";
	}
	if (visibility == "zoo_hide"){
		visibility = "hidden";
	}
	return visibility;
}

// int zoo_getWidth(string id);
function zoo_getWidth(id){
	if (is.ns4){
		width = document.layers[id].clip.width;
		}
	else if (is.ns6) { 
		width = document.getElementById(id).offsetWidth;
	} 
	else{
		eval ("width = "+id+".offsetWidth");
		}
	return width;
}

// int zoo_getHeight(string id);
function zoo_getHeight(id){
	if (is.ns4) {
		eval ("height = document.layers."+id+".clip.height");
	} 
	else if (is.ns6) { 
		height = document.getElementById(id).offsetHeight;
	} 
	else {
		eval ("height = "+id+".offsetHeight");
	}
	return height;
}

// void zoo_clip(string id, int top, int right, int bottom, int left);
function zoo_clip(id, top, right, bottom, left){
	if (is.ie || is.ns6) {
		eval(prefix+id+suffix+".clip = 'rect("+top+"px "+right+"px "+bottom+"px "+left+"px)'");
	} 
	else { // ns4
		eval (prefix+id+suffix+".clip.top = "+top);
		eval (prefix+id+suffix+".clip.bottom = "+bottom);
		eval (prefix+id+suffix+".clip.right = "+right);
		eval (prefix+id+suffix+".clip.left = "+left);
	}
}

// void zoo_changeImage(string id, string imgname, string imgobj);
function zoo_changeImage(id, imgname, imgobj){
	if (is.ns4){
		eval ("document.layers."+id+".document."+imgname+".src = "+imgobj+".src");
	}
	else{
		eval ("document."+imgname+".src = "+imgobj+".src");
	}
}

// int zoo_getImgX(string imgName)
// IE code from DHTML Lab http://www.webreference.com/dhtml/diner/realpos1/index.html
var nLeftPos;
var eParElement;
function getImgX(imgName,parentlayer) {

	if (is.ns4) {
		if (parentlayer==null) eval('imgX = document.'+imgName+'.x');        // X REL TO LAYER
		else eval('imgX = document.'+parentlayer+'.document.'+imgName+'.x');        // Y REL TO LAYER
	} else if (is.ns) {
		eval('imgX = document.'+imgName+'.offsetLeft');
		// identify first offset parent element
		eParElement = imgName+".offsetParent";

		// move up through parent element hierarchy
		// appending offsetLeft for each parent
		// until no more offset parents exist
		while (eval('document.'+eParElement) != null) {
			eval('imgX += document.'+eParElement+'.offsetLeft');
			eParElement = eParElement+".offsetParent";
		}
	} else {
		// initialize var to store calculations
		eval('imgX = document.all.'+imgName+'.offsetLeft');

		// identify first offset parent element
		eParElement = imgName+".offsetParent";

		// move up through parent element hierarchy
		// appending offsetLeft for each parent
		// until no more offset parents exist
		while (eval('document.all.'+eParElement) != null) {
			eval('imgX += document.all.'+eParElement+'.offsetLeft');
			eParElement = eParElement+".offsetParent";
		}
	}
	// return sum of element and parent offsets
	return imgX;
}

// getImgY
var nTopPos;
function getImgY(imgName,parentlayer) {
	if (is.ns4) {
		if (parentlayer==null) eval('imgY = document.'+imgName+'.y');
		else eval('imgY = document.'+parentlayer+'.document.'+imgName+'.y');        // Y REL TO LAYER
	} else if (is.ns) {
		eval('imgY = document.'+imgName+'.offsetTop');
		// identify first offset parent element
		eParElement = imgName+".offsetParent";

		// move up through parent element hierarchy
		// appending offsetTop for each parent
		// until no more offset parents exist
		while (eval('document.'+eParElement) != null) {
			eval('imgY += document.'+eParElement+'.offsetTop');
			eParElement = eParElement+".offsetParent";
		}
	} else {
		// initialize var to store calculations
		eval('imgY = document.all.'+imgName+'.offsetTop');

		// identify first offset parent element
		eParElement = imgName+".offsetParent";

		// move up through parent element hierarchy
		// appending offsetTop for each parent
		// until no more offset parents exist
		while (eval('document.all.'+eParElement) != null) {
			eval('imgY += document.all.'+eParElement+'.offsetTop');
			eParElement = eParElement+".offsetParent";
		}
	}
	// return sum of element and parent offsets
	return imgY;
}


function setImgHeight(imgname,parentlayer,num) {
	if (is.ns4) return;
	else eval('document.images["'+imgname+'"].height = '+num);
}

var timeoutID = 0;
var whoshows='';
function hide_menu(unavname) {
	if (prefix=="null") { 
		return;
	} else {
		zoo_hide('menu'+unavname);
		whoshows = '';
	}
}

function show_menu(unavname) {
	if (prefix=="null") {
		return;
	} else {
		if (unavname=='') return;
		if (whoshows == '') {
			zoo_show('menu'+unavname);
			whoshows = unavname;
		} else if (whoshows == unavname) {
			clearTimeout(timeoutID);
		} else {
			clearTimeout(timeoutID);
			hide_menu(whoshows);
			zoo_show('menu'+unavname);
			whoshows = unavname;
		}
	}
}


