// JavaScript Document
var img_loading = new Image();
img_loading.src = 'images/loading.gif';
var LOADING = '<img src='+img_loading.src+' align=absmiddle>';
var SMALL_LOADING = '<img src="images/loading1.gif" align=absmiddle>';

var IE = document.all?true:false;
var tempX = 0;
var tempY = 0;
var context_info = {};

// get Mouse XY
function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		if (document.documentElement)
		{
			tempX = event.clientX + document.documentElement.scrollLeft;
			tempY = event.clientY + document.documentElement.scrollTop;
		}
		else
		{
			tempX = event.clientX + document.body.scrollLeft;
			tempY = event.clientY + document.body.scrollTop;
		}
	}
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}

	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}
	return true;
}

document.onmousemove = getMouseXY;

function show_context_menu(div_id)
{
	if (IE) { // grab the x-y pos.s if browser is IE
   		$(div_id).css({'left': ((document.body.scrollLeft)+tempX) + 'px'});
		$(div_id).css({'top': ((document.body.scrollTop)+tempY) + 'px'});
  } else {  // grab the x-y pos.s if browser is NS
    	$(div_id).css({'left': (tempX) + 'px'});
		$(div_id).css({'top': (tempY) + 'px'});
  }

	$(div_id).show();

	$('#ul_menu').mouseout(function() {
		context_info.timer = setTimeout('hide_context_menu(\''+$(div_id).attr('id')+'\')', 100);
	});

	$('#ul_menu').mousemove(function() {
		if (context_info.timer!=undefined) clearTimeout(context_info.timer);
		context_info.timer = undefined;
	});
	return false;
}

function hide_context_menu(div_id)
{
	try{
        $('#ul_menu').unbind('mouseout');
		$('#ul_menu').unbind('mousemove');
	}catch(ex){

	}

	$('#'+div_id).hide();
}

function int(expr)
{
	expr = new String(expr).replace(/,/g, '');
	var i = parseInt(expr);
	if (isNaN(i))
	    return 0;
	else
	    return i;
}

function center_div(div){
    var height_window = $(window).height();
	var width_window = $(window).width();
	var scrollLeft = $(window).scrollLeft();
	var scrollTop = $(window).scrollTop();
    $(div).css('top', int(scrollTop + (height_window-int($(div).height()))/2));
	$(div).css('left', int(scrollLeft + (width_window-int($(div).width()))/2));
}
