/**
 * This requires jquery.js
 * @param divId
 * @param config
 * {width,height,alwaysVisible}
 */
function AEVToolTip(divId,conf){
	this.tipBox = $('#'+divId);
	this.iFrame = $('#ifr'+divId);
	this.config = conf;
	this.tipId = divId;
	this.tipBox.css({ left: 0, top: 0 });
}

AEVToolTip.prototype.show = function(){
	var nPosX = posX, nPosY = posY; 
	if(this.config.offsetX) nPosX += this.config.offsetX; 
	if(this.config.offsetY) nPosY += this.config.offsetY;
	
	if(this.config.alwaysVisible){
		var availY = (document.body.clientHeight+document.body.scrollTop) - nPosY;
		var availX = (document.body.clientWidth+document.body.scrollLeft) - nPosX;
		var origY = nPosY;
		var difX = (this.config.width+30) - availX;
		var difY = (this.config.height+30) - availY;
		if( difY > 0 ){
			nPosY = nPosY - difY;
		}
		if( difX > 0 ){
			if( nPosX < (this.config.width+30)) {
				nPosX = nPosX - difX;
				nPosY = origY;
			}
			else{
				nPosX = nPosX - (this.config.width+30);
			}
		}
	}
	this.tipBox.css({ left: nPosX, top: nPosY });
	this.tipBox.fadeIn('fast');
	if( isIE ) this.showIFrame();
};

AEVToolTip.prototype.hide = function(){
	this.tipBox.hide();
	if( isIE ) this.hideIFrame();
};

AEVToolTip.prototype.showIFrame = function(){
	var tipObj = document.getElementById(this.tipId);
	var ifrObj = document.getElementById('ifr'+this.tipId);
	if( ifrObj ){
		ifrObj.style.width = tipObj.offsetWidth;
		ifrObj.style.height = tipObj.offsetHeight;
		ifrObj.style.top = tipObj.style.top;
		ifrObj.style.left = tipObj.style.left;
		ifrObj.style.zIndex = tipObj.style.zIndex + 1; 
		ifrObj.style.display = 'block';
	}
};
AEVToolTip.prototype.hideIFrame = function(){
	var ifrObj = document.getElementById('ifr'+this.tipId);
	if( ifrObj ){ifrObj.style.display = 'none';}
};


//***********************************************************
//Set co-ordinates of click
//***********************************************************
var posX = 0;
var posY = 0;
var isIE = document.all ? true : false;
document.onmousemove = getCursorPosition;
function getCursorPosition(e) {
	var _x;
	var _y;
	if (!isIE) {
		_x = e.pageX;
		_y = e.pageY;
	}
	if (isIE) {
		_x = event.clientX;
		_y = event.clientY;
		if(!document.body.scrollTop){
			_x += document.documentElement.scrollLeft;
			_y += document.documentElement.scrollTop;
		}
		else{
			_x += document.body.scrollLeft;
			_y += document.body.scrollTop;
		}
	}
	posX = _x;
	posY = _y;
	return true;
}