
hintArray = new Array();

myHint = new hint(false, '#FFFFE1',300);
myHint2 = new hint(true,'#C0C0C0', 500);


function hint(moveWithMouse, bgColour, delay)
{
	this.id = hintArray.length;
	hintArray[this.id] = this;
	this.CSS = '#hintDiv' + this.id + ' {position:absolute; font-size: 80%; border:1px #000000 solid; visibility:hidden;}';
	this.HTML = '<div id="hintDiv' + this.id + '"> </div>';
	this.div = new divObject('hintDiv' + this.id, 'document.');
	this.activate = new Function("this.div.activate(); this.div.setBgColour(this.backgroundColour);");
	this.show = hintShow;
	this.shown = false;
	this.backgroundColour = bgColour!=null?bgColour:'#FFFFE1';
	this.delay = delay!=null?delay:0;
	this.showTimer = false;
	this.setBackgroundColour = new Function("bgColour", "this.backgroundColour = bgColour; this.div.setBgColour(bgColour);");
	this.move = hintMove;
	this.moveTimer = setInterval('if(hintArray[' + this.id + '].moveWithMouse) hintArray[' + this.id + '].move();', 50);
	this.moveWithMouse = moveWithMouse;
	this.width = 0;
}


function hintShow(message)
{
	if(typeof(message) == 'undefined')
	{
		if(this.showTimer) clearTimeout(this.showTimer);
		this.showTimer = false;
		this.div.hide();
		this.shown = false;
		return;
	}

	this.div.write('<nobr>' + message + '</nobr>');
	this.move();

	if(browserVars.type.ns4) this.width = this.div.div.clip.width;
	else this.width = this.div.baseDiv.offsetWidth;

	this.showTimer = setTimeout('hintArray[' + this.id + '].div.show(); hintArray[' + this.id + '].shown = true;', this.delay);
}


function hintMove()
{
	var scrOfX = 0, scrOfY = 0;

	if( typeof( window.pageYOffset ) == 'number' ) 
	{
		scrOfY = window.pageYOffset; 
		scrOfX = window.pageXOffset;
	} 
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
	{
		scrOfY = document.body.scrollTop; 
		scrOfX = document.body.scrollLeft;
	} 
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
	{
		scrOfY = document.documentElement.scrollTop; 
		scrOfX = document.documentElement.scrollLeft;
	}

        var myWidth = 0, myHeight = 0;

        if( typeof( window.innerWidth ) == 'number' ) 
        {
        	//Non-IE
    		myWidth = window.innerWidth;
    		myHeight = window.innerHeight;
  	} 
  	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
  	{
    		//IE 6+ in 'standards compliant mode'
    		myWidth = document.documentElement.clientWidth;
    		myHeight = document.documentElement.clientHeight;
  	} 
  	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
  	{
    		//IE 4 compatible
    		myWidth = document.body.clientWidth;
    		myHeight = document.body.clientHeight;
  	}

	browserVars.updateVars();
	var screenRight = browserVars.scrollLeft + browserVars.width - 16;
	var screenDown = browserVars.scrollTop + browserVars.height - 16;
	var x = browserVars.mouseX + scrOfX + 16;
	var y = browserVars.mouseY + scrOfY + 16;

	if(browserVars.mouseX + this.width + 16 > myWidth)
	{
		x = myWidth+scrOfX-16 - this.width;
	}
	if (browserVars.mouseY+10+16>myHeight)
	{
		y=browserVars.mouseY + scrOfY - 26; 
	}


	if(x < 0) x = 0;
	if(y < 0) y = 0;

	

/*	this.div.write('<nobr> Alen' + 
	'scr:' + screenRight + ':' + screenDown + 
	' wh:' + myWidth + ':' + myHeight + 
	' sl:' + scrOfX + ':' + scrOfY + 
	' mouse:' + browserVars.mouseX + ':' + browserVars.mouseY + 
	' xy:' + x + ':' + y + 
	'</nobr>');
*/

	this.div.moveTo(x, y);
}


function writeHints()
{
	var CSS = '';
	var HTML = ''
	for(var x=0; x<hintArray.length; x++)
	{
		CSS += hintArray[x].CSS;
		HTML += hintArray[x].HTML;
	}
	return '<style>' + CSS + '</style>' + HTML;
}


function activateHints()
{
	for(var x=0; x<hintArray.length; x++)
		hintArray[x].activate();
}


