captureMouse();

var v_divname;
var v_img;
var xoffset;
var yoffset;
var tipBgcolour;
var tipBorderCol;
var tipWidth;
var tipBorderWidth;
var tipPadding

//SYSTEM
var v_xcoordinate = 0;
var v_ycoordinate = 0;
var v_visible = 0;
var v_havemouse=0;
var v_layer = null;

var startStr = '<table width="100%" cellspacing="0" cellpadding="0"><tr><td style="padding:5px" align="center"><img src="';
var midStr = '" alt="Downloading..." border="0"></td></tr>';
var endStr = '</table>';

function initTip()
{
	
	v_divname='tipDiv';
	v_img="";
	
	//UI Vars
	xoffset=2;
	yoffset=18;
	tipBgcolour="#FFF";
	tipBorderCol="#A2A2A2";
	tipWidth=110;
	tipBorderWidth=1;
	tipPadding=2;

	//SYSTEM Vars
	v_visible = 0;
	v_layer = null;
}


function doTooltip(img)
{
	//Reset
	initTip();
	
	v_img=img;

	if (v_layer)
		v_layer=getLayer(v_divname); 
	
	if(!(v_layer=getPLayer()))
		return false;

	doTip();
}

function hideTip()
{
	if (v_visible == 1) 
	{
		if(v_layer!=null)
		{
			v_layer.style.visibility = 'hidden';
			v_visible = 0
		}
	}
	return true;
}

function doTip() {
	var html;	
	v_visible = 0;
	
	html = makeHTML(v_img);	
	createPopup(html);
	if(v_havemouse==1);
	{	
		positionLayer();
		v_layer.style.visibility = 'visible';
		v_visible=1;
	}
	
}
function makeHTML(img) {

	var txt = '<table id="tipTable" style="background-color:white;border:solid 1px ' + tipBorderCol + ';width:' + tipWidth + 'px" cellpadding="' + 
	tipPadding + '" border="0"><tr><td align="center">' + startStr + img + midStr + endStr + '</td></tr></table>';
	return txt;
}

//Positions popup according to mouse
function positionLayer() {
	
	var placeX;
	var placeY;
	
	//get final pos
	placeX= horizontalPlacement();
	placeY= verticalPlacement();
	
	//Move the layer
	v_layer.style.left = placeX+'px';
	v_layer.style.top = placeY+'px';

}

function mouseMoveHandler(e) {
	
	//for IE in standards mode
	var dsocleft;
	var dsoctop;

	if (document.all){
		var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
		dsocleft= iebody.scrollLeft;
		dsoctop = iebody.scrollTop;
	}
	else
	{
		dsocleft=self.document.body.scrollLeft;
		dsoctop=self.document.body.scrollTop;
	}
	if(!e)
		e=event;
	if (e.clientX) 
	{
	    
		v_xcoordinate = e.clientX+dsocleft;
		//window.status  =e.clientX + ':' +v_xcoordinate;
		v_ycoordinate = e.clientY+dsoctop;	
		v_havemouse=1;
	}
	if (v_visible == 1)
		positionLayer();	
}

function captureMouse() {
	document.onmousemove = mouseMoveHandler;
}

function createPopup(input) {

	var popupwidth=tipWidth;
	var text;
	var zindex;
	
	text='';
	text =  createBackLayer(popupwidth,zindex++);
	text += '<div style="position: absolute; top: 0; left: 0; width: '+ popupwidth+'px; z-index: ' + zindex + ';">' + input + '</div>';
	
	if (typeof v_layer.innerHTML != 'undefined') {
		v_layer.innerHTML = text;
	} 
	
	var backlayer=self.document.getElementById("iBack");
	var tiptable=self.document.getElementById("tipTable");
	backlayer.height=tiptable.offsetHeight;
}

//prevents forms from showing through
function createBackLayer(width, Z)
{
	//Create iBack with 0 height
	return '<iframe id="iBack" frameborder="0" scrolling="no" width="' + width + '" height="0" style="z-index: ' + Z + '; filter: Beta(Style=0,Opacity=0);"><p></iframe>';
}

//get horizontal box placement
function horizontalPlacement() {
	placeX = v_xcoordinate+xoffset;
	return placeX;
}

//get vertical box placement
function verticalPlacement() {
	return v_ycoordinate+yoffset;
}

function getPLayer() {
	var divContainer = self.document.getElementById(v_divname);
	return divContainer;
}