//======================================================================================
//  This script Handles Item Pops for pages with item links.
// June 10th 2005
//======================================================================================
var agt = navigator.userAgent.toLowerCase();
var originalFirstChild;

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
  {
  for(var i=0; i<document.images.length; i++)
     {
  var img = document.images[i]
  var imgName = img.src.toUpperCase()
  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
     {
  var imgID = (img.id) ? "id='" + img.id + "' " : ""
  var imgClass = (img.className) ? "class='" + img.className + "' " : ""
  var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
  var imgStyle = "display:inline-block;" + img.style.cssText 
  if (img.align == "left") imgStyle = "float:left;" + imgStyle
  if (img.align == "right") imgStyle = "float:right;" + imgStyle
  if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle  
  var strNewHTML = "<span " + imgID + imgClass + imgTitle
  + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
  + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
  img.outerHTML = strNewHTML
  i = i-1
     }
     }
  }
function getOffsetLeft (el) {
  var ol = el.offsetLeft;
  while ((el = el.offsetParent) != null)
    ol += el.offsetLeft;
  return ol;
}
// GET the offset from the parent. IE needs this. mozilla works with event.pageY
function getOffsetTop (el) {
  var ot = el.offsetTop;
  while((el = el.offsetParent) != null)
   ot += el.offsetTop;
  return ot;
}

function createTitle(which, string,strtitle,stricon, event)
{
	// record the original first child (protection when deleting)
	if (typeof(originalFirstChild) == 'undefined') 
	{
		originalFirstChild = document.body.firstChild;
	}
	// Detect the Browser
	
	switch (navigator.appName)
	{
	    case "Microsoft Internet Explorer":
			var explorer=true;
		    break;
		case "Netscape":
			var explorer=false;
		    break;
		default:
			var explorer=false;
	}
	
	x = document.all ? (event.clientX + document.body.scrollLeft) : event.pageX;
	y = document.all ? (getOffsetTop(which)) : event.pageY;
	element = document.createElement('div');
	element.style.position = 'absolute';
	element.style.zIndex = 1000;
	element.style.visibility = 'hidden';
	excessWidth = 0;
	if (document.all) 
	{
		excessWidth = 50;
	}
	excessHeight = 20;
	element.innerHTML = '<div class="bodyline"><table style="width: 451px; height: 250px; background-image: url(phpbb/templates/Sojourners/images/item_bg.gif);  border: none; overflow: hidden;" cellspacing="1" cellpadding="1"><tr><td style="vertical-align:text-top; text-align: center;white-space: nowrap;" width="451px" height="10px" colspan="3">'+ strtitle +'</td></tr><tr><td width="5px"></td><td style="vertical-align:top; text-align: left;" width="403px">'+ string +'</td><td style="vertical-align:top; white-space: nowrap;" width="48"><img src="phpbb/templates/Sojourners/images/item_icons/item_'+stricon+'.png" alt="Icon" />&nbsp;</td></tr></table></div>';
	renderedElement = document.body.insertBefore(element, document.body.firstChild);
	renderedWidth = renderedElement.offsetWidth;
	renderedHeight = renderedElement.offsetHeight;

	// fix overflowing off the right side of the screen
	overFlowX = x + renderedWidth + excessWidth - document.body.offsetWidth;
	x = overFlowX > 0 ? x - overFlowX : x;
	
	// fix overflowing off the bottom of the screen
	overFlowY = y + renderedHeight + excessHeight - document.body.offsetHeight; 
	y = overFlowY > 0 ? y - overFlowY : y;

	renderedElement.style.top = (y + 15) + 'px';
	renderedElement.style.left = (x + 15) + 'px';

	// windows versions of mozilla are like too fast here...we have to slow it down
	if (agt.indexOf('gecko') != -1 && agt.indexOf('win') != -1) 
	{
		setTimeout("renderedElement.style.visibility = 'visible'", 1);
	}
	else 
	{
		renderedElement.style.visibility = 'visible';
	}
	if (explorer)
	{
	    correctPNG();
	}
}

function destroyTitle()
{
	// make sure we don't delete the actual page contents (javascript can get out of alignment)
	if (document.body.firstChild != originalFirstChild)
	{
		document.body.removeChild(document.body.firstChild);
	}
}
