
/* ************************************************************ */	
// STENSTROM.NET.JavaScript.Utils.Layout
/* ************************************************************ */
// *** Global variables ***
// Object contains the current X,Y coordinates of the mouse.
    var gMouseCoords   = null;
	var gWindowDim	= null;

// assign global event handlers which will initialize and assign values to the 
// gMouseCoords and gWindowDim variables
	if(window.addEventListener)
	{
		document.addEventListener("mousemove", stenstrom_net_document_onmousemove, false);
		document.addEventListener("load", stenstrom_net_document_onload, false);
	}
	else	
	{
	    document.attachEvent("onmousemove", stenstrom_net_document_onmousemove);
	    document.attachEvent("onload", stenstrom_net_document_onload);
	}
		
/* ************************** */
/* OBJECTS                    */
/* ************************** */	
/*  OBJECT : GetMouseCoords(evt)
	PARAM	 : evt (window.event) - The mouse event. 			   
	RETURN	 : A javascript object with "x" and "y" properties identifying the 
			   position of the mouse. The X and Y are calculated taking into 
			   consideration the variations between the different browsers.
	PROPERTIES
		.x		- gets the X coordinate of the mouse
		.y		- gets the Y coordinate of the mouse
	EXAMPLE
		var gMouseCoords = getMouseCoords(evt);
*/
    function GetMouseCoords(evt)
    {
    // Mozilla browsers
        if(evt.pageX || evt.pageY)
            return{ x:evt.pageX, y:evt.pageY};
        else
        {
    // Internet Explorer
            return{
                x:evt.clientX + document.body.scrollLeft - document.body.clientLeft,
                y:evt.clientY + document.body.scrollTop - document.body.clientTop
            };
        }
    }

/*  OBJECT 	 : GetMouseOffset(target, evt)
	PARAM	 : target (html element) - the element within which the mouse is clicked.
	PARAM	 : evt (window.event) - The mouse event. 			   
	RETURN	 : A javascript object with "x" and "y" properties identifying the 
			   position of the mouse in relation to the target. 
	PROPERTIES
		.x		- gets the X coordinate of the mouse within the target
		.y		- gets the Y coordinate of the mouse within the target
	EXAMPLE
		var gMouseOffset = GetMouseOffset( <div>, evt);
*/
	function GetMouseOffset(target, evt)
	{
		ev = evt || window.event;		
		
		var targetPos = GetObjPosition(target);
		var mousePos  = (gMouseCoords == null)? mouseCoords(evt) : gMouseCoords;
		
		return{ x:mousePos.x-targetPos.x, y:mousePos.y-targetPos.y};
	}
	
/*  OBJECT 	 : GetObjPosition(target)
	PARAM	 : target (html element) - the element whose position is requested   
	RETURN	 : A javascript object with "x" and "y" properties identifying the 
			   position of the target on the page. 
	PROPERTIES
		.x		- gets the X coordinate of the target in relation to the document
		.y		- gets the Y coordinate of the target in relation to the document
	EXAMPLE
		var gObjPosition = GetObjPosition( <div> );
*/
	function GetObjPosition(target)
	{
		var left = 0;
		var top  = 0;
		
		while(target.offsetParent)
		{
			left += target.offsetLeft;
			top  += target.offsetTop;
			target = target.offsetParent;
		}
		
		left += target.offsetLeft;
		top  += target.offsetTop;
		
		return{ x:left, y:top };
	}

/*  OBJECT 	 : GetWindowDimensions()
	RETURN	 : A javascript object properties identifying the height and width of the 
			   body tag in the window/frame.
	PROPERTIES
		.height	- gets the X coordinate of the target in relation to the document
		.width	- gets the Y coordinate of the target in relation to the document
	EXAMPLE
		var gObjPosition = GetObjPosition( <div> );
*/
	function GetWindowDimensions()
	{
		var nHeight	= 0;
		var nWidth 	= 0;
		if(window.screen) // NS/Firefox
		{
			nHeight = window.screen.availHeight;
			nWidth  = window.screen.availWidth;
		}
		else				// MSIE
		{
			nHeight = document.body.offsetHeight;
			nWidth  = document.body.offsetWidth;
		}
		
		return{ height:nHeight, width:nWidth };
	}
	
	
	
	
/* ************************** */
/* EVENT HANDLERS             */
/* ************************** */
/* 	EVENT 		: document_onmousemove(evt)
	PARAM		: evt (window.event) - The OnMouseMove event
	RETURN		: N/A
	DESCRIPTION	: Assigns X and Y properties to the gMouseCoords from the 
				  onmousemove event passed in as the parameter.
	NOTES		: If the developer wants to add functionality to the document
				  onmouseover event then s/he must implement the function ...
				  doc_onmouseover(evt).  If the method is discovered to exist then 
				  it will be executed.
*/
	function stenstrom_net_document_onmousemove(evt)
	{
		evt	= evt || window.event;	// if evt is NULL then use IE's window.event object
		gMouseCoords	= GetMouseCoords(evt);
	}
	
/* EVENT		: stenstrom_net_document_onload(evt 
*/
	function stenstrom_net_document_onload(evt)
	{
		evt	= evt || window.event;	// if evt is NULL then use IE's window.event object
		gWindowDim	= GetWindowDimensions();
	}
	
	
	
	