// Show controls class
var ShowControlsGlobalTimeout = null;
var ShowControlsGlobalPrev = null;
var ShowControls = 
{
	Control : null,
	ActionShow : false,
	
	OnTimeout : function()
	{
		if(this.ActionShow)
		{
			if(this.Control != null)
				this.Control.style.display = "";
		}
		else
		{
			if(this.Control != null)
				this.Control.style.display = "none";
		}
	}
}

ShowControls.Start = Class.create();
ShowControls.Start.prototype = ShowControls.extend
(
	{
		initialize : function(elem, show)
		{
			this.Control = elem;
			this.ActionShow = show;
			if(ShowControlsGlobalTimeout != null)
				clearTimeout(ShowControlsGlobalTimeout);
			if(ShowControlsGlobalPrev != null && ShowControlsGlobalPrev != elem)
				ShowControlsGlobalPrev.style.display = "none";
			ShowControlsGlobalPrev = elem;
			ShowControlsGlobalTimeout = setTimeout(this.OnTimeout.bind(this), show ? 500 : 100);
		}
	}
)


// Get mouse position
function GetCoordinates(elem)
{
	// Find coordinates
	var objItem = $(elem);
	var objParent = null;
	var intX = 0;
	var intY = 0;
	do
	{	// Walk up our document tree until we find the body
		// and add the distance from the parent to our counter.
		intX += objItem.offsetLeft;
		intY += objItem.offsetTop;
		objParent = objItem.offsetParent.tagName;
		objItem = objItem.offsetParent;
	}
	while(objParent != 'BODY');
	var result = { x: intX, y : intY };
	return result;
}

var mouseX, mouseY;

function getMousePos(e)
{
	if(!e)
		e = window.event||window.Event;
	
	if('undefined'!=typeof e.pageX)
	{
		mouseX = e.pageX;
		mouseY = e.pageY;
	}
	else
	{
		mouseX = e.clientX + document.body.scrollLeft;
		mouseY = e.clientY + document.body.scrollTop;
	}
}

// You need to tell Mozilla to start listening:
if(window.Event && document.captureEvents)
 	document.captureEvents(Event.MOUSEMOVE);

// Then assign the mouse handler
document.onmousemove = getMousePos;


function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
		curleft += obj.offsetLeft
		obj = obj.offsetParent;
		}
	}
	else if (obj.x)
	curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
		curtop += obj.offsetTop
		obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	curtop += obj.y;
	return curtop;
}
