// JavaScript Document

/********************************************************************
* Copyright 2006 by Albertson Consulting Inc.,
* 13 1st Ave SW., Suite 304, Minot ND, 58701 USA
* All rights reserved.
*																	
* This software is the confidential and proprietary information
* of Albertson Consulting Inc. ("Confidential Information").
* You shall not disclose such Confidential Information and shall
* use it only in accordance with the terms of the license
* agreement you entered into with Albertson Consulting Inc.
*********************************************************************/

// add writealbe layer
document.writeln('<div id="detailsLayer" class="details" style="visibility: hidden;position:absolute; "></div>');

document.documentElement.onmousemove = UpdateDetailPosition;
var following = false;
var timer_id = null;
var opac_timer_id = null;
var cur_details_opacity = 0;
hideDetails();

// showDetails
function showDetails(e, t) {
	if (!e) e = window.event;
	var div = document.getElementById('detailsLayer');
	var html = getDetails(t);
	
	div.innerHTML = html;
    div.style.visibility = 'visible';
    
    if(e != null)
	{
	    div.style.left = (GetMouseX(e) - 20) + 'px';
	    div.style.top = (GetMouseY(e) + 30) + 'px';
	}
    
    following = true;
    if(timer_id != null) clearTimeout(timer_id);
    
    fade('detailsLayer', 85);
}

// hideDetails
function hideDetails() {
	fade('detailsLayer', 0);
	timer_id = setTimeout("hideTimeout();", 400);
	following = false;
}

function hideTimeout() {
	var div = document.getElementById('detailsLayer');
	if(following == false) div.style.visibility = "hidden";
	div.style.left = 0;
	div.style.top = 0;
	timer_id = null;
}

// getDetails
function getDetails(t) {

	var retval;

	retval = '<table class="mapTable">';
	retval += '<tr><td class="mapField">'+t+'</td></tr>';
	retval += '</table>';

	return retval;
}

// chadc @ iret
// Added fix for mouse position in browsers other than IE
function GetMouseX(evt) {
	if (evt.clientX != null)
	{
	   return evt.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
	}
	else return 0;
}

function GetMouseY(evt) {
	if (evt.clientY != null)
	{
	   return evt.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	else return 0;
}

//Not working in IE 7
function UpdateDetailPosition(e) {
	var div = document.getElementById('detailsLayer');
	if(e != null)
	{
		if(div != null && div.style.visibility != "hidden") {
			div.style.left = (GetMouseX(e) - 20) + 'px';
	    	div.style.top = (GetMouseY(e) + 30) + 'px';
		}
	}
}

function fade(id, opacEnd) { 
    var steps = 20;
    var opac_step = ((opacEnd - cur_details_opacity) / steps);
    if(opac_timer_id != null) clearTimeout(opac_timer_id);
    changeOpac(cur_details_opacity,id,0,steps,opac_step);
} 

//change the opacity for different browsers 
function changeOpac(opacity, id, cur_step, num_steps, opac_step ) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")";
    
    cur_details_opacity = opacity;
    
    if(cur_step < num_steps)
    {
    	opacity += opac_step;
    	cur_step++;
    	opac_timer_id = setTimeout("changeOpac(" + opacity + ",'" + id + "'," + cur_step + "," + num_steps + "," + opac_step + ");",10);
    }
}

