/***********************************************
* Freejavascriptkit.com
* Visit http://www.freejavascriptkit.com for more free Javascripts source code
***********************************************/

var offsetxpoint=10 //Customize x offset of tooltip
var offsetypoint=10 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
var lastevent

var g_PopupIFrame_tip;

if (ie||ns6)
	var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth){
	if (ns6||ie){
		if (typeof thewidth!="undefined") 
			tipobj.style.width=thewidth+"px"
		tipobj.style.backgroundColor=document.body.bgColor
		tipobj.innerHTML=thetext
		enabletip=true
		return false
	}
}

function updatepos() {
	positiontip(lastevent);
}

function positiontip(e){
	lastevent = e;
	if(enablestip){
		checktip(e);
	}

	if(enabletip){
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
		var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20
		var winY=ie&&!window.opera? event.clientY : e.clientY

		var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth)
			//move the horizontal position of the menu to the left by it's width
			tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth-5+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth-5+"px"
			//tipobj.style.left=ie? ietruebody().scrollLeft-tipobj.offsetWidth-45+"px" : window.innerWidth-tipobj.offsetWidth-45+"px"
		else if (curX<leftedge)
			tipobj.style.left="5px"
		else
			tipobj.style.left=curX+offsetxpoint+"px"

		//same concept with the vertical position
		if ((tipobj.offsetHeight<(winY))&&(bottomedge<tipobj.offsetHeight))
			tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
		else
			tipobj.style.top=curY+offsetypoint+"px"
		tipobj.style.visibility="visible"

		if(ie) {
                	g_PopupIFrame_tip.style.left = tipobj.offsetLeft + 'px';
                	g_PopupIFrame_tip.style.top = tipobj.offsetTop + 'px';
                	g_PopupIFrame_tip.style.width = tipobj.offsetWidth + 'px';
                	g_PopupIFrame_tip.style.height = tipobj.offsetHeight + 'px';
			g_PopupIFrame_tip.style.zIndex = tipobj.style.zIndex - 1;
		}
	}
}

function hideddrivetip(){
	if (ns6||ie){
		enabletip=false
		tipobj.style.visibility="hidden"
		tipobj.style.left="-1000px"
		//tipobj.style.height=""
		tipobj.style.backgroundColor=''
		tipobj.style.width=''
	}

        if(ie) {
		document.body.removeChild(g_PopupIFrame_tip);
               	g_PopupIFrame_tip=null;
       	}
}

function miniddrivetip(miniid,epic){
	thewidth="455";
	if (ns6||ie){
		if (typeof thewidth!="undefined") 
			tipobj.style.width=thewidth+"px"
		tipobj.innerHTML="Laddar mini: " + miniid + "<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>";
		enabletip=true
		new Ajax.Updater('dhtmltooltip', '/minitip.php?miniid=' + miniid + '&epic=' + epic, {asynchronous:true, evalScripts:true});
		if(ie) {
			var iFrame = document.createElement("IFRAME");
			iFrame.setAttribute("src", "");

                	iFrame.style.position = "absolute";
                	iFrame.style.left = tipobj.offsetLeft + 'px';
                	iFrame.style.top = tipobj.offsetTop + 'px';
                	iFrame.style.width = tipobj.offsetWidth + 'px';
                	iFrame.style.height = tipobj.offsetHeight + 'px';
			iFrame.style.zIndex = tipobj.style.zIndex - 1;

			document.body.appendChild(iFrame);

			g_PopupIFrame_tip=iFrame;
		}
		return false
	}
}

function popupmini(miniid,epic,version){
	thewidth="570";
	if (ns6||ie){
		if (typeof thewidth!="undefined") 
			tipobj.style.width=thewidth+"px"
		//tipobj.style.height="370px";
		tipobj.innerHTML="Laddar mini: " + miniid + "<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>";
		new Ajax.Updater('dhtmltooltip', '/minitiptest.php?miniid=' + miniid + '&epic=' + epic + '&ddmver=' + version, {asynchronous:true, evalScripts:true});
		if(ie) {
			tipobj.style.zIndex = 1000;
			
			var iFrame = document.createElement("IFRAME");
			iFrame.setAttribute("src", "");

                	iFrame.style.position = "absolute";
                	iFrame.style.left = tipobj.offsetLeft + 'px';
                	iFrame.style.top = tipobj.offsetTop + 'px';
                	iFrame.style.width = tipobj.offsetWidth + 'px';
                	iFrame.style.height = tipobj.offsetHeight + 'px';
			iFrame.style.zIndex = tipobj.style.zIndex - 1;

			document.body.appendChild(iFrame);

			g_PopupIFrame_tip=iFrame;
		}
		sleep(500);
		enabletip=true;
		return false;
	}
}

function wbddrivetip(wbid){
	thewidth="250";
	if (ns6||ie){
		if (typeof thewidth!="undefined") 
			tipobj.style.width=thewidth+"px"
		tipobj.innerHTML="Laddar warband: " + wbid + "<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>";
		enabletip=true
		new Ajax.Updater('dhtmltooltip', '/wbtip.php?wbid=' + wbid, {asynchronous:true, evalScripts:true});
		if(ie) {
			var iFrame = document.createElement("IFRAME");
			iFrame.setAttribute("src", "");

                	iFrame.style.position = "absolute";
                	iFrame.style.left = tipobj.offsetLeft + 'px';
                	iFrame.style.top = tipobj.offsetTop + 'px';
                	iFrame.style.width = tipobj.offsetWidth + 'px';
                	iFrame.style.height = tipobj.offsetHeight + 'px';
			iFrame.style.zIndex = tipobj.style.zIndex - 1;

			document.body.appendChild(iFrame);

			g_PopupIFrame_tip=iFrame;
		}
		return false
	}
}

function sleep(delay) {
    var start = new Date().getTime();
    while (new Date().getTime() < start + delay);
}

document.onmousemove=positiontip

