function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) 
{
	var n_result = n_win ? n_win : 0;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function ss_getCurrentYPos() {
	if (document.body && document.body.scrollTop)
		return document.body.scrollTop;
	if (document.documentElement && document.documentElement.scrollTop)
		return document.documentElement.scrollTop;
	if (window.pageYOffset)
		return window.pageYOffset;
	return 0;
}

function ss_getCurrentXPos() {
	if (document.body && document.body.scrollLeft)
		return document.body.scrollLeft;
	if (document.documentElement && document.documentElement.scrollLeft)
		return document.documentElement.scrollLeft;
	if (window.pageXOffset)
		return window.pageXOffset;
	return 0;
}

function ShowWorking()
{
	MoveWorking();	
	$('workingIcon').show();
	
	Event.observe(window, 'scroll', MoveWorking);
	Event.observe(window, 'resize', MoveWorking);
}

function MoveWorking()
{
	var topPos = (ss_getCurrentYPos() + f_clientHeight() - $('workingIcon').getHeight() - 5) + 'px';
	var leftPos = ss_getCurrentXPos() + 'px';
	
	$('workingIcon').setStyle({
		top: topPos,
		left: leftPos
	});
}

function HideWorking()
{
	$('workingIcon').hide();	
	Event.stopObserving(window, 'scroll', MoveWorking);
	Event.stopObserving(window, 'resize', MoveWorking);
}

function CalculatePreviewPosition(mouseX, previewHt, previewWt)
{    	
	var ttY = (f_clientHeight() / 2) + ss_getCurrentYPos() - (previewHt / 2);       	
	var ttX = mouseX + 50;
	var clientWt = f_clientWidth();
	
	if (ttX + previewWt > clientWt) {
		ttX = mouseX - previewWt - 50;    		
	}
	
	return [ttX, ttY];
}
