// Getting the mouse position

var posx = 0;
var posy = 0;

var new_event = true;

var window_width = 0;
var window_height = 0;

var timer;

// 1000 = 1 second
var delay_timer = 300;

// Get the size of the browseing window.
set_size(); 

// Start the script that makes JS get the coordonates of the mouse on the window
document.onmousemove = get_position;
function get_position(e) {
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}	
}

function show_tip(eventid) {

	// Figure out if the box is going to run off the side of the screen, if it is... move it so that it doesn't.
	xpos = ((posx + 300) >= window_width ? (posx - (300 - (window_width - posx))) : posx );	
	document.getElementById('popup_window').style.left = (xpos - 100) +"px";
	document.getElementById('popup_window').style.top = (posy - 160) +"px";
	new_event = true;
	
	// This script will force the status to abort and "fail" after 3 seconds of running.
	this.delay_popup = function() { 
		if(new_event == true) {
			set_size();
			document.getElementById('popup_window').innerHTML = document.getElementById('popup_'+eventid).innerHTML;
			document.getElementById('popup_window').style.display = "";

		}
	}
	if(timer == "") {
		timer = setTimeout("delay_popup();", delay_timer);
	}
}

// Hide the box if they leave the event, and wipe the info in it just in case.
function hide_tip() {
	document.getElementById('popup_window').innerHTML = "";
	document.getElementById('popup_window').style.display = "none";
	new_event = false;
	
	clearTimeout(timer);
	timer = "";
}

// Figure out the size of the browesing window
function set_size() {
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		window_width = window.innerWidth;
		window_height = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		window_width = document.documentElement.clientWidth;
		window_height = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		window_width = document.body.clientWidth;
		window_height = document.body.clientHeight;
	}
}

