/*
converts 
<div class=help>this function writes hello world</div>
to clickable help button
*/


function getMouseXY(e){
	if (!e) var e = window.event;
	if (document.all) { // grab the x-y pos.s if browser is IE
		tempX = e.clientX + document.body.scrollLeft
		tempY = e.clientY + document.body.scrollTop
	} else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX
		tempY = e.pageY
	}
	var o = new Object();
	o.x = tempX;
	o.y = tempY;
	return o;
  
}

function closeAbleDiv(e,divInnerHTML){
	var div = document.createElement('div');
	div.id = 'help'+parseInt(10000000*Math.random());
	var mouseXY=getMouseXY(e);
	//alert(serialize(mouseXY));
	div.innerHTML = 
		'<div style="text-align:right"><font color="gray">click here to close -&gt;</font>'+
			'<button onclick="$(\'#'+div.id+'\').remove()">&nbsp;X&nbsp;</button><br/>'+
		'</div>'+
		divInnerHTML;
	div.style.position = 'absolute';	
	div.style.top = mouseXY.y;
	div.style.left = mouseXY.x;
	div.style.width = '400px';
	div.style.background='yellow';
	div.style.border='1px solid silver';
	div.style.padding='0 5px 10px 10px';
	document.body.appendChild(div);
	//document.body.removeChild(div);
}




function activateHelps(){
	$('.help').before("<button>&nbsp;?&nbsp;</button>").prev().click(
		function(e){
			closeAbleDiv(e,$(this).next().html());
		}
	).next().hide().removeClass('help');
}

$(document).ready(
	function(){
		activateHelps();
	}
);
