/*
 * PREPARES OUR OBEJECT KNOW OUR CURSORS POSITION
 */

// Set Netscape up to run the "captureMousePosition" function whenever
// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
// the movement a little easier.
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position
        // reflects the position from the top/left of the screen the
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}

/**
 * Class used to generate tool tips for the end user, please ensure you object pass a url and the object its self
 * @classDescription: Created Tool tips near object
 * @author: Daniel
 * @return {Object}
 */
oToolTip = function()
{

	this.reference_object = null;
	this.template = null;
	this.dom_element = null;

	this.oToolTip = function()
	{
		this.http_request = new oHTTP();
		//Create Response Event Hander
		this.http_request.onreadystatechange = function ()
		{
			if(toolTips.http_request.readyState==4)
			{
				toolTips.template = toolTips.http_request.responseText;
			}
		};
		//Create Request
		this.http_request.open('GET', 'http://www.french-property.com/toolTips/gif.html', true);
		//Send Request
		this.http_request.send(null);
		//SEND MUST BE NULL IF NOT BEING USED, some browser throw exceptions other wise
		return true;
	};

	/**
	 * gets the tooltip template from the server, runs a string replace on the return text, the places it in the dom
	 *
	 * @param {Object} object
	 * @param {String} title_string
	 * @param {String} text_string
	 * @return {Bool}
	 */
	this.show = function(object_, title_string, text_string)
	{
		//hide any other tool tips
		while(document.getElementById('ToolTips'))
		{
			toolTips.hide();
		}
		//str replace the message n title
		tmp_tip = toolTips.template.replace(/{message}/, text_string);
		tmp_tip = tmp_tip.replace(/{title}/, title_string);

		tool_tip_div = document.createElement('div');

		curleft = 0;
		curtop = 0;
		cur = object_;
		if (object_ == null) {
			curleft = xMousePos;
			curtop = yMousePos;
		}
		else
		{
			if (cur.offsetParent) {
				do
				{
					curleft += cur.offsetLeft;
					curtop += cur.offsetTop;
				} while (cur = cur.offsetParent);
			}
			curtop += 16;
		}
		document.body.appendChild(tool_tip_div);

		tool_tip_div.id = 'ToolTips';
		tool_tip_div.style.position = 'absolute';
		tool_tip_div.style.visibility = 'visible';
		tool_tip_div.innerHTML = tmp_tip;
		tool_tip_div.style.width = 'auto';
		tool_tip_div.style.left = (curleft - 16) +'px';
		tool_tip_div.style.top = (curtop - tool_tip_div.clientHeight - 16) +'px';
	};


	this.hide = function()
	{
		try
		{
			document.body.removeChild(document.getElementById('ToolTips'));
		}
		catch(e)
		{

		}
	};

};

var toolTips = new oToolTip();
toolTips.oToolTip();