// LAYER FUNCTIONS
// See book: Dynamic HTML, page 97

var ns4=(document.layers)? true:false;
var ns6=(document.getElementById)? true:false;
var ie4=(document.all)? true:false;
var ie42=(document.all)? true:false;
var ie5=false;

var layerIDs = new Array()		// fill this with the ID's of the layers to be tabbed in and out



//------------------------------------------
// From book: Dynamic HTML, page 97

// Set some global variables for reference building
var lyrColl = ""
var lyrStyleObj = ""
if (ie4) {
	lyrColl = "all."
	lyrStyleObj = ".style"
}

//Returns the layer object itself
function getLyr(container, lyrID) {
	if (container && container != '')
		return eval(container + ".document." + lyrColl + lyrID)
	else
		return eval("document." + lyrColl + lyrID)
}

//Returns the object for movement
function getObjStyle(container, lyrID) {
	if (container && container != '')
		return eval(container + ".document." + lyrColl + lyrID + lyrStyleObj)
	else
		return eval("document." + lyrColl + lyrID + lyrStyleObj)
}

// Replaces the layer's content with the specified HTML
function setLyrHtml (lyr, myHtml) {		// use getObj() function to get lyr
	if (lyr) {
		if (ns4) {
			lyr.document.write(myHtml)
			lyr.document.close()
		}
		else lyr.innerHTML = myHtml
	}
}

//Returns height of object in pixels
function getObjHeight(obj) {		// use getObjStyle() function to get obj
	if (obj) {
		if (ns4) return obj.clip.height
		else return obj.clipHeight
	}
}

//Returns width of object in pixels
function getObjWidth(obj) {		// use getObjStyle() function to get obj
	if (obj) {
		if (ns4) return obj.clip.width
		else return obj.clipWidth
	}
}

//Returns x coordinate of positional object
function getObjLeft(obj) {		// use getObjStyle() function to get obj
	if (obj) {
		if (ns4) return obj.left
		else return obj.pixelLeft
	}
}

//Returns y coordinate of positional object
function getObjTop(obj) {		// use getObjStyle() function to get obj
	if (obj) {
		if (ns4) return obj.top
		else return obj.pixelTop
	}
}

//Returns available content width space in browser window
function getInsideWindowWidth() {
	if (ns4) return window.innerWidth
	else return document.body.clientWidth
}

//Returns available content height space in browser window
function getInsideWindowHeight() {
	if (ns4) return window.innerHeight
	else return document.body.clientHeight
}

//Position an element at a specific x,y location
function shiftTo(obj, x, y) {		// use getObjStyle() function to get obj
	if (obj) {
		if (ns4) obj.moveTo(x, y)
		else {
			obj.pixelLeft = x
			obj.pixelTop = y
		}
	}
}

//Move an object by x and/or y pixels
function shiftBy(obj, deltax, deltay) {		// use getObjStyle() function to get obj
	if (obj) {
		if (ns4) obj.moveBy(deltax, deltay)
		else {
			obj.pixelLeft += deltax
			obj.pixelTop += deltay
		}
	}
}

// Makes an object visible
function showObj(obj) {		// use getObjStyle() function to get obj
	if (obj) {
		obj.visibility = "visible"
	}
}

// Makes an object hidden
function hideObj(obj) {		// use getObjStyle() function to get obj
	if (obj) {
		obj.visibility = "hidden"
	}
}



//------------------------------------------

// See also, function "getDHTMLObj" in JOUST code
// NOTE: only works if layer is within frame calling this function
function getLayerWithID (layerID) {
	if (ie4) 
		return eval("document.all." + layerID)
	else
		return eval("document." + layerID)
}

function getLayerWithIdInFrame (layerID, frameName) {
	if (ie4) 
		return eval("top." + frameName + ".document.all." + layerID)
	else
		return eval("top." + frameName + ".document." + layerID)
}

function getLayerWithIdInFullFrame (layerID, fullFrameName) {	// eg. fullFrameName = "parent.myFrame"
	if (ie4) 
		return eval(fullFrameName + ".document.all." + layerID)
	else
		return eval(fullFrameName + ".document." + layerID)
}

// NOTE: only works if layer is within frame calling this function
function showLayerWithID (layerID) {
	var myLayer = getLayerWithID(layerID)
	
	if (ns4) myLayer.visibility = "visible"
	else if (ie4) myLayer.style.visibility = "visible"
	else if (ns6) myLayer.style.display = "block"
}

// NOTE: only works if layer is within frame calling this function
function hideLayerWithID (layerID) {
	var myLayer = getLayerWithID(layerID)
		
	if (ns4) myLayer.visibility = "hidden"
	else if (ie4) myLayer.style.visibility = "hidden"
	else if (ns6) myLayer.style.display = "none"
}

// NOTE: only works if layer is within frame calling this function
function tabLayerWithID (layerID) {
	for (i=0; i<layerIDs.length; i++) {
		if (layerID != layerIDs[i]) hideLayerWithID(layerIDs[i])
	}
	showLayerWithID(layerID)
}

// NOTE: only works if layer is within frame calling this function
function setLayerZIndex (layerID, zIndex) {
	if (ie4)
		return eval("document.all." + layerID + ".style.zIndex = " + zIndex)
	else
		return eval("document." + layerID + ".zIndex = " + zIndex)
}

// NOTE: only works if layer is within frame calling this function
// Positions the layer's left/top coordinate over the image's left/top location
function moveLayerToImage (layerObj, imageObj) {
	if (ie4)
		return layerObj.style.pixelLeft = imageObj.xOffset
	else
		return layerObj.x = imageObj.x
}
