var IE = document.all?true:false;
var tempX = 0;
var tempY = 0;
var tt_el = false;
var tt_id = 1;
var tt;
var tm;
var dimBody=null;
var dimTool=null;
/*************************** NEW TOOLTIP *****************************/

function Tip(ret, width){

	tt = $('tooltip_new');
	ttc = $('tooltip_content');

	if(!tt){ return; }

	dimBody = $(document.body).getDimensions();


	if(Prototype.Browser.IE){
		dimBody['height'] = document.body.clientHeight;
	}else{
		dimBody['height'] = window.innerHeight;
	}

	if(typeof(width)=='undefined'){
    	ret = '<div style="padding: 5px;">' + ret + '</div>';
	}else{
		ret = '<div style="padding: 5px;width: ' + width + 'px;">' + ret + '</div>';
	}
    ttc.innerHTML = ret;
	tt.style.display = "block";

	dimTool = $('tooltip_new').getDimensions();

  	if (!IE) document.captureEvents(Event.MOUSEMOVE);
   	document.onmousemove = moveTooltip;

}

function moveTooltip(e) {
	e = e || window.event;
	tt_over = e.target || e.srcElement;

	if(tt_el==false){
		if(!tt_over.id){
			tt_id++;
			id = "ttelm" + tt_id;
			tt_over.id = id;
		}
		tt_el = tt_over.id;
	}

	if(tt_over.id == tt_el){
		mo = tt_over.getAttribute('_onmouseout');
		tt_over.onmouseout = function(){
			document.onmousemove = null;
			ttc = $('tooltip_content');
			tt = $('tooltip_new');
			ttc.innerHTML = "";
			tt.style.display = "none";
			tt_el = false;

			if(mo){
				eval(mo);
			}
		}
	}

	if (Prototype.Browser.IE) {
		tempX = event.clientX;
		tempY = event.clientY;
	}else{
	  tempX = e.pageX;
	  tempY = e.pageY;
	}

	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}


	tempX = parseInt(tempX);
	tempY = parseInt(tempY);

	if(typeof(flashElms)=='object')
		for(var i=0; i<flashElms.length; i++)
			if ( ( ( tempY + 10) > flashElms[i].offsety ) && ( ( tempY + 10) < (flashElms[i].offsety + flashElms[i].h + dimTool['height']) ) && ( (flashElms[i].offsetx - (tempX + 10)) < dimTool['width'] ) && ( (flashElms[i].offsetx - (tempX + 10)) > 0 )  )
				var XCheck = true;

	if( (tempX + 10 + dimTool['width']) > dimBody['width'] )
		var XCheck = true;

	if(XCheck){
		tempX = tempX - 10 - dimTool['width'];
	}else{
		tempX = tempX +10;
	}

	if ( (tempY + 10 + dimTool['height']) > dimBody['height'] )
		var YCheck = true;


	if(YCheck){
		tempY = tempY - 10 - dimTool['height'];
	}else{
		tempY = tempY + 10;
	}

	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}

	if(Prototype.Browser.IE){
		var scrX = document.body.scrollLeft;
		var scrY = document.body.scrollTop;
	}else{
		var scrX = window.pageXOffset;
		var scrY = window.pageYOffset;
	}

	if(scrY>tempY){
		tempY = scrY + 10;
	}

	tt.style.top  = tempY+'px';
	tt.style.left = tempX+'px';

	if(tt.style.display != "block"){
		tt.style.display = "block";
	}

	return true;
}

function hideTooltip(){
	document.onmousemove = null;
	tt = $('tooltip_new');
	ttc = $('tooltip_content');
	if($(ttc)) ttc.innerHTML = "";
	if($(tt)) tt.style.display = "none";
	tt_el = false;
}

//'pp1', WIDTH, 220, CENTERMOUSE, true, OFFSETY, 20

function TagToTip(el_id, width, height, padding){

    tt = $('tooltip_new');
    ttc = $('tooltip_content');
    el = $(el_id);
    css_height = (height!=false)?'height: ' + height + 'px;':'';
    if(!padding){
    	padding = 0;
    }
    ret = '<div style="display: table; width: ' + width + ';' + css_height + 'padding: ' + padding + ';">' + el.innerHTML + '</div>';
    ttc.innerHTML = ret;
    tt.style.display = "block";

  	if (!IE) document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = moveTooltip;
}

