/*-------------------------------------------------------//
//
//	Object.js
//	Nathan Shower (based on examples from
//		"CSS, DHTML & AJAX" by Jason Cranford Teague)
//
//	February 2007
//
//	These functions return various aspects of a given object or result from an event.
//	Included are finding the location, size, visibility, id and various other style properties.
//
//-------------------------------------------------------*/
//-------------------------------------------------------//
// return the ID of an object based on a given event
function findObjectId(evt) {
	var objectId = (evt.target) ? evt.target.id : ((evt.srcElement) ? evt.srcElement.id : null);
	return objectId;
}
//-------------------------------------------------------//
// finds the target of an event (www.quirksmode.org)
function findEventTarget(e) {
	var targ;
	if (!e) { var e = window.event;}
	if (e.target) { targ = e.target;}
	else if (e.srcElement) { targ = e.srcElement;}
	else { targ = e; }
	if (targ.nodeType && targ.nodeType == 3) { targ = targ.parentNode; } // defeat safari bug
	
	return targ;
}
//-------------------------------------------------------//
// find the width of a given object based on the ID
function findWidth(objectId) {
	var object = document.getElementById(objectId);
	if (object.offsetWidth) {
		return object.offsetWidth;
	} 
	return (null);
}
//-------------------------------------------------------//
// find the height of a given object based on the ID
function findHeight(objectId) {
	var object = document.getElementById(objectId);
	if (object.offsetHeight) {
		return object.offsetHeight;
	}
	return (null);
}
//-------------------------------------------------------//
// find the pixel value of the top of a given object based on the ID
function findTop(objectId) {
	var object = document.getElementById(objectId);
	if (object.offsetTop) {
		return object.offsetTop;
	}
	return (null);
}
//-------------------------------------------------------//
// find the pixel value of the bottom of a given object based on the ID
function findBottom(objectId) {
	var object = document.getElementById(objectId);
	if (object.offsetBottom) {
		return object.offsetBottom;
	}
	return (null);
}
//-------------------------------------------------------//
// find the pixel value of the left of a given object based on the ID
function findLeft(objectId) {
	var object = document.getElementById(objectId);
	if (object.offsetLeft) {
		return object.offsetLeft;
	}
	return (null);
}
//-------------------------------------------------------//
// find the pixel value of the right of a given object based on the ID
function findRight(objectId) {
	var object = document.getElementById(objectId);
	if (object.offsetRight) {
		return object.offsetRight;
	}
	return (null);
}
//-------------------------------------------------------//
// find the horizontal (x) location of the cursor in the browser window
function findBrowserX(evt) {
	var evt = (evt) ? evt : ((window.event) ? window.event : null);
	if (evt.clientX) {
		return evt.clientX;
	}
	return (null);
}
//-------------------------------------------------------//
// find the vertical (y) location of the cursor in the browser window
function findBrowserY(evt) {
	var evt = (evt) ? evt : ((window.event) ? window.event : null);
	if (evt.clientY) {
		return evt.clientY;
	}
	return (null);
}
//-------------------------------------------------------//
// find the horizontal (x) location of the cursor on the screen
function findScreenX(evt) {
	var evt = (evt) ? evt : ((window.event) ? window.event : null);
	if (evt.screenX) {
		return evt.screenX;
	}
	return (null);
}
//-------------------------------------------------------//
// find the vertical (y) location of the cursor on the screen
function findScreenY(evt) {
	var evt = (evt) ? evt : ((window.event) ? window.event : null);
	if (evt.clientY) {
		return evt.screenY;
	}
	return (null);
}


//-------------------------------------------------------//
// find the visibility of a given object based on the ID
function findVisibility(objectID) {
	var object = document.getElementById(objectID);
	if (object.style.visibility) {
		return object.style.visibility;
	}
	return (null);
}
//-------------------------------------------------------//
// set the visibility of an object given an ID and a state
function setVisibility(objectID, state) {
	document.getElementById(objectID).style.visibility = state;
}
//-------------------------------------------------------//
// toggles an object between visible and invisible
function toggleVisibility(objectID) {
	var object = document.getElementById(objectID);
	var state = object.style.visibility;
	if (state == 'visible') {
		object.style.visibility = 'hidden';
	} else {
		object.style.visibility = 'visible';
	}
}
//-------------------------------------------------------//
// find the display property of a given object based on the ID
function findDisplay(objectID) {
	var object = document.getElementById(objectID);
	if (object.style.display) {
		return object.style.display;
	}
	return (null);
}
//-------------------------------------------------------//
// set the display of an object given an ID and a state
function setDisplay(objectID, state) {
	document.getElementById(objectID).style.display = state;
}
//-------------------------------------------------------//
// toggles an object between block display and no display
function toggleDisplay(objectID) {
	var object = document.getElementById(objectID);
	var state = object.style.display;
	if (state == 'none') {
		object.style.display = '';
	} else if (state != 'none') {
		object.style.display = '';
	}
}
//-------------------------------------------------------//
// find the width of the usable browser space
function findPageWidth() {
	if (window.innerWidth) {
		return window.innerWidth;
	}
	if (document.body.clientWidth) {
		return document.body.clientWidth;
	}
	return (null);
}
//-------------------------------------------------------//
// find the height of the usable browser space
function findPageHeight() {
	if (window.innerHeight) {
		return window.innerHeight;
	}
	if (document.body.clientHeight) {
		return document.body.clientHeight;
	}
	return (null);
}
//-------------------------------------------------------//
// find the width of the browser
function findBrowserWidth() {
	if (window.outerWidth != null) {
		return window.outerWidth;
	}
	return (null);
}
//-------------------------------------------------------//
// find the width of the browser
function findBrowserHeight() {
	if (window.outerHeight != null) {
		return window.outerHeight;
	}
	return (null);
}
//-------------------------------------------------------//