var offsetxpoint=-60 //Customize x offset of tooltip
var offsetypoint=20 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["MapFrame"] : document.getElementById? document.getElementById("MapFrame") : ""

var DefaultMapWidth = 250;
var DefaultMapHeight = 125;
var lDocumentBorder = 3;

function Init()
{
for (i=0; i < document.links.length; i++) 
	{ 
	if (document.links[i].getAttribute('rel')=='ShowMap')
		{
		document.links[i].setAttribute("onmouseover","javascript:ShowLocation(this,'" + document.links[i].innerHTML + "');");
		document.links[i].setAttribute("onmouseout","javascript:HideLocation();");
		//document.links[i].style.background="url(http://map.3duniverse.co.za/images/earth12x12.png) no-repeat 0 3";
		//document.links[i].style.paddingLeft=13;
		}
	} 
	var NewDiv=document.createElement('div');
	NewDiv.setAttribute('id','MapFrame');
	NewDiv.style.textAlign='center';
	NewDiv.style.verticleAlign='center';
	NewDiv.style.fontFamily='arial';
	NewDiv.style.fontSize='10px';

	var NewLoadingDiv=document.createElement('div');
	NewLoadingDiv.setAttribute('id','loading');
	NewLoadingDiv.style.width= DefaultMapWidth + (2 * lDocumentBorder) + 'px';
	NewLoadingDiv.style.height= DefaultMapHeight + 60 + (2 * lDocumentBorder) + 'px';
	NewLoadingDiv.style.backgroundColor='#fff';
	NewLoadingDiv.style.textAlign='center';
	NewLoadingDiv.style.verticleAlign='center';
	NewLoadingDiv.style.fontFamily='arial';
	NewLoadingDiv.style.fontSize='10px';
	NewLoadingDiv.style.position='absolute';
	NewLoadingDiv.style.top=0;
	NewLoadingDiv.style.left=0;
	
	var NewLabel=document.createElement('font')
	NewLabel.style.width='330px';
	NewLabel.style.height='226px';
	NewLabel.innerHTML='<br><br><br>locating map position...';
	
	NewDiv.style.visibility='hidden';
	NewDiv.style.position='absolute';
	NewDiv.style.top=0;
	NewDiv.style.left=0;
	NewDiv.style.margin='0px';
	NewDiv.style.padding='0px';
	NewDiv.style.border='solid 1px #999';
	NewDiv.style.width=DefaultMapWidth + (2 * lDocumentBorder) + 'px';
	NewDiv.style.height=DefaultMapHeight + 60 + (2 * lDocumentBorder) + 'px';
	NewDiv.style.zIndex=300;
	NewDiv.style.backgroundColor='#fff';

	var newFrame=document.createElement('iframe');
	newFrame.setAttribute('id','Map');
	newFrame.setAttribute('frameborder','0');
	newFrame.setAttribute('scrolling','no');
	newFrame.style.width='330px';
	newFrame.style.height='226px';
	newFrame.setAttribute("onload","document.getElementById('loading').style.display='none';");
	
	document.body.appendChild(NewDiv);
	NewDiv.appendChild(NewLoadingDiv);
	NewLoadingDiv.appendChild(NewLabel);
	NewDiv.appendChild(newFrame);
} 

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function getScrollBarWidth () 
{
//	if (document.body.scrollHeight>document.body.clientHeight)
//		{
		var inner = document.createElement('p');
		inner.style.width = '100%';
		inner.style.height = '200px';

		var outer = document.createElement('div');
		outer.style.position = 'absolute';
		outer.style.top = '0px';
		outer.style.left = '0px';
		outer.style.visibility = 'hidden';
		outer.style.width = '200px';
		outer.style.height = '150px';
		outer.style.overflow = 'hidden';
		outer.appendChild (inner);

		document.body.appendChild (outer);
		var w1 = inner.offsetWidth;
		outer.style.overflow = 'scroll';
		var w2 = inner.offsetWidth;
		if (w1 == w2) w2 = outer.clientWidth;

		document.body.removeChild (outer);

		return (w1 - w2);
//		}
//	else
//		{return 0;}
}

function getViewportWidth()
{
	var w = 0;

	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			w = document.documentElement.clientWidth;
		}
		//quirks mode
		else
		{
			w = document.body.clientWidth;
		}
	}
	//w3c
	else
	{
		w = window.innerWidth;
	}
	return w;
}

function findPosX(obj)
{
var curleft = 0;
if(obj.offsetParent)
	while(1) 
	{
	  curleft += obj.offsetLeft;
	  if(!obj.offsetParent)
		break;
	  obj = obj.offsetParent;
	}
else if(obj.x)
	curleft += obj.x;
return curleft;
}

function findPosY(obj)
{
var curtop = 0;
if(obj.offsetParent)
	while(1)
	{
	  curtop += obj.offsetTop;
	  if(!obj.offsetParent)
		break;
	  obj = obj.offsetParent;
	}
else if(obj.y)
	curtop += obj.y;
return curtop;
}

function ShowLocation(linkObj,sIP)
{
document.getElementById('loading').style.display='block';
sIP = typeof(sIP) != 'undefined' ? sIP : '';
document.getElementById('Map').src='http://map.3duniverse.co.za?' + sIP;
document.getElementById('MapFrame').style.top=findPosY(linkObj) + linkObj.offsetHeight + 2 +'px';
if (findPosX(linkObj) + document.getElementById('MapFrame').offsetWidth > getViewportWidth())
	{document.getElementById('MapFrame').style.left=getViewportWidth() - document.getElementById('MapFrame').offsetWidth - getScrollBarWidth() - 1 +'px';}
else
	{document.getElementById('MapFrame').style.left=findPosX(linkObj) +'px';}
//document.getElementById('MapFrame').style.display='block';
document.getElementById('MapFrame').style.visibility='visible';
}

function HideLocation()
{
document.getElementById('Map').src='';
//document.getElementById('MapFrame').style.display='none';
document.getElementById('MapFrame').style.left='0px';
document.getElementById('MapFrame').style.top='0px';
document.getElementById('MapFrame').style.visibility='hidden';
}

window.onload=Init;
//document.onmousemove=positionMap;
