// Script configuration
var title_bg 		= "#1F3A22"; //"#EFBA56";
var title_fg 		= "#FFFFCC";//"#000000";
var table_border 	= "#1F3A22";//"#000000";
var table_bg 		= "#E6FFCC";//"#D8DEC7";
var table_fg 		= "#214321";//"#000000";
var table_width 	= 250;
var timein 		= 700; // time to wait on the link before the window appear and to wait after leaving window to make it disapear (in milliseconds)
var timeout 		= 25000; // time to wait before destroying the window if you never inter it (in milliseconds)
var close_btn 		= "/gbrowse/menu_ggb/close.gif"
var x_offset 		= 5;
var y_offset 		= 5;

var x_pos;
var y_pos;
var draw_win;
var hide_win;

// Function to get the mouse position
function get_mouse(e) { 
	x_pos = (!document.all) ? e.pageX : event.x+document.body.scrollLeft;
	// Adjust x_pos to prevent pop-up menu being displayed beyond right edge of window:
	if (window.innerWidth) {
		theWidth = window.innerWidth
		theHeight = window.innerHeight
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		theWidth = document.documentElement.clientWidth
		theHeight = document.documentElement.clientHeight
	}
	else if (document.body) {
		theWidth = document.body.clientWidth
		theHeight = document.body.clientHeight
	}
	if (x_pos > ((theWidth+document.body.scrollLeft)-260)){
		x_pos = (!document.all) ? (e.pageX-265) : ((theWidth+document.body.scrollLeft)-265);
	}	
	if (!document.all) { y_pos = e.pageY }
	else {
		if (document.documentElement && document.documentElement.scrollTop) { 
			y_pos = event.y + document.documentElement.scrollTop; }
		else if (document.body) { y_pos = event.y + document.body.scrollTop; }
		else { y_pos = event.y + window.pageYOffset; }
	}
//			alert(y_pos+' | '+document.documentElement.scrollTop+' | '+document.body.scrollTop+' | '+window.pageYOffset)
	
}

// Write the style sheet for the window
document.write("<style type=\"text/css\">");
document.write("#description {");
document.write("	position: absolute;");
document.write("	width: "+table_width+"px;");
document.write("  visibility: hidden;");
document.write("}");
document.write(".ggbmenu_title {");
document.write("	font-family: sans-serif;");
document.write("	font-size: 8pt;");
document.write("	text-align: center;");
document.write("	color: " + title_fg + ";");
document.write("	background: " + title_bg + ";");
document.write("}");
document.write(".ggbmenu_button {");
document.write("	text-align: right;");
document.write("	color: "+title_fg +";");
document.write("	background: " + title_bg + ";");
document.write("}");
document.write(".ggbmenu_display {");
document.write("	font-family: sans-serif;");
document.write("	font-size: 10pt;");
document.write("	text-align: left;");
document.write("	padding-left: 2px;");
document.write("	padding-right: 2px;");
document.write("	color: " + table_fg + ";");
document.write("	background: " + table_bg + ";");
document.write("}");
document.write("a.ggbmenu_link:link {");
document.write("	text-decoration: underline;");
document.write("	color: #006699;");
document.write("}");
document.write("a.ggbmenu_link:visited {");
document.write("	text-decoration: underline;");
document.write("	color: #006699;");
document.write("}");
document.write("a.ggbmenu_link:hover {");
document.write("	text-decoration: underline;");
document.write("	color: red;");
document.write("}");
document.write("</style>");

if (document.getElementById) {
	if(navigator.appName.substring(0,3) == "Net")
		document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = get_mouse;
}


// Timout before drawing window
function show_description(title,msg) {
	draw_win = setTimeout("draw_window(\""+title+"\",\""+msg+"\")", timein);
}

// Function to build the window and drawing it
function draw_window(title,msg) {
	out_window(timeout);
	var window_timer = " onmouseover=\"on_window();\" onmouseout=\"out_window(timein);\"";
	var description = "";
	description += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"" + table_border + "\""+window_timer+">";
	description += 	"<tr>";
	description += 		"<td>";
	description += 			"<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\""+window_timer+">";
	description += 				"<tr>";
	description += 					"<td class=\"ggbmenu_title\""+window_timer+">";
	description += 						title;
	description += 					"</td>";
	description += 					"<td class=\"ggbmenu_button\" width=\"11px\""+window_timer+">";
	description += 						"<img src=\""+close_btn+"\" alt=\"close\" onclick=\"hide_description();\" />";
	description += 					"</td>";
	description += 				"</tr>";
	description += 				"<tr>";
	description +=					"<td colspan=\"2\" class=\"ggbmenu_display\""+window_timer+">";
	description += 						msg;
	description += 					"</td>";
	description += 				"</tr>";
	description += 			"</table>";
	description += 		"</td>";
	description += 	"</tr>";
	description += "</table>";
	if (document.getElementById) {
		document.getElementById("description").style.top = y_pos+y_offset+"px";
		document.getElementById("description").style.left = x_pos+x_offset+"px"; 
		document.getElementById("description").innerHTML = description;
		document.getElementById("description").style.visibility = "visible";
	}
}

// Stop the timeout if living before it ends
function out_link() {
	clearTimeout(draw_win);
}

// Destroy the window
function hide_description() {
	if (document.getElementById) {
		document.getElementById("description").style.visibility = "hidden";
	}
}

function on_window() {
	clearTimeout(hide_win);
}

function out_window(time) {
	clearTimeout(hide_win);
	hide_win = setTimeout("hide_description()",time);
}

