/*******************************************************************************
FILE NAME    :window.js
DEPENDENCIES :browser.js
********************************************************************************
____________________________ API DOCUMENTATION BEGIN ___________________________
````````````````````````````````````````````````````````````````````````````````
Browser window (body/document) and screen functions. 

````````````````````````````````````````````````````````````````````````````````
_____________________________ API DOCUMENTATION END ____________________________
*******************************************************************************/

//------------------------------------------------------------------------------
// BROWSER BODY/DOCUMENT FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- returns height of body
function getBodyHeight() {
 if(gBrowser.ns6 || (gBrowser.isMac && gBrowser.ie)) return document.body.offsetHeight;
 else return document.body.scrollHeight;
}

//FUNCTION-- returns width of body
function getBodyWidth() {
 if(gBrowser.ns6 || (gBrowser.isMac && gBrowser.ie)) return document.body.offsetWidth;
 else return document.body.scrollWidth;
}

//FUNCTION-- returns vertical scroll position
function getScrollPositionV() {
 if(gBrowser.ie) return document.body.scrollTop;
 else return window.pageYOffset;
}

//------------------------------------------------------------------------------
// BROWSER BODY/DOCUMENT FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// BROWSER WINDOW FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- returns height of browser window
function getWindowHeight() {
 if(gBrowser.firefox || gBrowser.ns || gBrowser.safari) return window.innerHeight;
 else return document.body.clientHeight;
}

//FUNCTION-- returns width of browser window
function getWindowWidth() {
 if(gBrowser.firefox || gBrowser.ns || gBrowser.safari) return window.innerWidth;
 else return document.body.clientWidth;
}

//------------------------------------------------------------------------------
// BROWSER WINDOW FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// SCREEN FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- returns screen height
function getScreenHeight() {
 return parseInt(screen.height);
}

//FUNCTION-- returns screen width
function getScreenWidth() {
 return parseInt(screen.width);
}

//FUNCTION-- returns height of working area of system's screen, excluding windows taskbar
function getAvailScreenHeight() {
 return parseInt(screen.availHeight);
}

//FUNCTION-- returns width of working area of system's screen, excluding windows taskbar
function getAvailScreenWidth() {
 return parseInt(screen.availWidth);
}

//------------------------------------------------------------------------------
// SCREEN FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// POSITION FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- returns x position for horizontal centering of an object
function getCenterX(theScreenW, objW) {
 var halfScreenW = parseInt(theScreenW/2);
 var halfObjW = parseInt(objW/2); 
 return (halfScreenW-halfObjW);
}

//FUNCTION-- returns y position for vertical centering of an object
function getCenterY(theScreenH, objH) {
 var verticalScrollPos = getScrollPositionV();
 if(objH >= theScreenH) {return verticalScrollPos;}
	
 var halfScreenH = parseInt(theScreenH/2);
 var halfObjH = parseInt(objH/2); 
 return ((halfScreenH-halfObjH)+verticalScrollPos);
}

//FUNCTION-- validate x and y position
function checkWindowCoords(xPos, yPos, theScreenW, theScreenH, objW, objH) {
 if(xPos < 0 || yPos < 0 || (xPos + objW) > theScreenW || (yPos + objH) > theScreenH) return false;
 else return true;
}

//FUNCTION-- validate x position
function checkWindowCoordsX(xPos, theScreenW, objW) {
 if(xPos < 0 || (xPos + objW) > theScreenW) return true;
 else return false;
}

//FUNCTION-- validate y position
function checkWindowCoordsY(yPos, theScreenH, objH) {
 if(yPos < 0 || (yPos + objH) > theScreenH) return true;
 else return false;
}

//------------------------------------------------------------------------------
// POSITION FUNCTIONS END
//------------------------------------------------------------------------------

//---END

