

/**
 * @author Mark Cassar
 * @version 1.0.0 
 * @lastmodified 12/03/08
 */


if (!com) var com = new Object();
if (!com.cs) com.cs = new Object();
if (!com.cs.util) com.cs.util = new Object();
if (!com.cs.util.General) com.cs.util.General = new Object();


com.cs.util.General.getPageHeight = function() {
    if( window.innerHeight && window.scrollMaxY ) { // Firefox {    
        pageHeight = window.innerHeight + window.scrollMaxY;
    }
    else if( document.body.scrollHeight > document.body.offsetHeight ) // all but Explorer Mac
    {        
        pageHeight = document.body.scrollHeight;
    }
    else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    { 
     pageHeight = document.body.offsetHeight + document.body.offsetTop;
    }
    return pageHeight;
}

com.cs.util.General.getPageWidth = function() {
    if( window.innerWidth && window.scrollMaxX ) {// Firefox {    
        pageWidth = window.innerWidth + window.scrollMaxX;
    }
    else if( document.body.scrollWidth > document.body.offsetWidth ) // all but Explorer Mac
    {        
        pageWidth = document.body.scrollWidth;
    }
    else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    { 
     pageWidth = document.body.offsetWidth + document.body.offsetLeft;
    }
    return pageWidth;
}


com.cs.util.General.getScrollX = function() {
    if (window.pageXOffset) return window.pageXOffset; //All but IE			
	if (document.documentElement && document.documentElement.scrollLeft) return document.documentElement.scrollLeft; // IE6 with doctype	
	if (document.body.scrollLeft) return document.body.scrollLeft; //	IE other
	return 0;
}
com.cs.util.General.getScrollY = function() {
    if (window.pageYOffset) return window.pageYOffset; //All but IE
	if (document.documentElement && document.documentElement.scrollTop) return document.documentElement.scrollTop; // IE6 with doctype
	if (document.body.scrollTop) return document.body.scrollTop; //	IE other
	return 0;
}

com.cs.util.General.getWindowWidth = function() {
		    
	if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth; // IE6 with doctype
	
	if (window.innerWidth) return window.innerWidth; //All but IE
	if (document.body.clientWidth) return document.body.clientWidth; //	IE other
	return 0;
}
com.cs.util.General.getWindowHeight = function() {
	if (window.innerHeight) return window.innerHeight; //All but IE
	if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight; // IE6 with doctype
	if (document.body.clientHeight) return document.body.clientHeight; // IE other
	return 0;
}

com.cs.util.General.getWindowX = function() {
	if (window.screenLeft) return window.screenLeft; //IE and others 
	if (window.screenX) return window.screenX; //Firefox and others
	return 0;
}
com.cs.util.General.getWindowY = function() {
	if (window.screenTop) return window.screenTop; //IE and others
	if (window.screenY) return window.screenY; //Firefox and others
	return 0;
}

com.cs.util.General.getMouseX = function(event) { //e must be the event of a mousemove function to extract data

	mouse = event || window.event;
	return (mouse.clientX + com.cs.util.General.getScrollX());
	
}

com.cs.util.General.getMouseY = function(event) { //e must be the event of a mousemove function to extract data

	mouse = event || window.event;
	return (mouse.clientY + com.cs.util.General.getScrollY());
}

com.cs.util.General.scrollWindowToCenterWidth = function() {
    var f = window.scroll || window.scrollTo;
    var windowWidth = com.cs.util.General.getWindowWidth();
    var pageWidth = com.cs.util.General.getPageWidth();
    if (pageWidth > windowWidth) {
        var scrollOffset = (pageWidth - windowWidth) / 2;    
        f(scrollOffset, com.cs.util.General.getScrollY());    
    }
	
}

com.cs.util.General.scrollWindowToCenterHeight = function() {
    var f = window.scroll || window.scrollTo;
    var windowHeight = com.cs.util.General.getWindowHeight();
    var pageHeight = com.cs.util.General.getPageHeight();
    if (pageHeight > windowHeight) {
        var scrollOffset = (pageHeight - windowHeight) / 2;
        f(com.cs.util.General.getScrollX(), scrollOffset);    
    }	
}

com.cs.util.General.scrollWindowToCenter = function() {
    com.cs.util.General.scrollWindowToCenterHeight();
    com.cs.util.General.scrollWindowToCenterWidth();
}