function getStyleObject(objectId){if(document.getElementById && document.getElementById(objectId)){return document.getElementById(objectId).style;} else if (document.all && document.all(objectId)){return document.all(objectId).style;} else if (document.layers && document.layers[objectId]){return document.layers[objectId];}else{return false;}} 
function changeObjectVisibility(objectId, newVisibility,newDisplay){var styleObject = getStyleObject(objectId);if(styleObject){styleObject.visibility=newVisibility;styleObject.display=newDisplay;return true;}else{return false;}}
function moveObject(objectId,newXCoordinate,newYCoordinate){var styleObject=getStyleObject(objectId);if(styleObject){styleObject.left = newXCoordinate;styleObject.top = newYCoordinate;return true;}else{return false;}} 
function getX(obj){return( obj.offsetParent==null ? obj.offsetLeft : obj.offsetLeft+getX(obj.offsetParent));}
function getY(obj){return( obj.offsetParent==null ? obj.offsetTop : obj.offsetTop+getY(obj.offsetParent) );}


function getXYcoord (nvn)
{
	var elm = document.images[nvn];
	if (elm == null)
	{
		rd = getAnchorPosition(nvn);
		return rd;
	}
	if(document.layers)
	return elm;
	var rd={x:0,y:0};
	do
	{
		rd.x+=parseInt(elm.offsetLeft);
		if(document.all)
		{
			rd.y+=parseInt(elm.offsetTop-elm.scrollTop);
			if ((navigator.appVersion.indexOf('MSIE') != '-1') && (navigator.platform.indexOf('Mac') !='-1'))
			{
				rd.x-=elm.offsetLeft;
				rd.x-=parseInt(elm.scrollLeft);
			}
		}
		else
		{
			rd.y+=parseInt(elm.offsetTop);
		}
		elm = elm.offsetParent;
	}
	while(elm);
	return rd;
}

var xOffset = 0;
var yOffset = 0;
function showImageMenuPopup (targetObjectId, eventObj,xpos,ypos,thesource,nohideexisting)
{
	if (targetObjectId != window.currentlyVisiblePopup)
    	{
		if(eventObj)
		{
			if (!nohideexisting)
			{
				hideCurrentPopup();
			}
			eventObj.cancelBubble = true;
			var img = document.images[thesource];
			var pos = getXYcoord(thesource);
			if (xpos == -1)
			{
				var newXCoordinate = (eventObj.pageX)?eventObj.pageX + xOffset:eventObj.x + xOffset + ((document.body.scrollLeft)?document.body.scrollLeft:0);
			}
			else
			{
				var newXCoordinate = (eventObj.pageX)?xpos + pos.x :xpos + pos.x + ((document.body.scrollLeft)?document.body.scrollLeft:0);
			}
			if (ypos == -1)
			{
				var newYCoordinate = (eventObj.pageY)?eventObj.pageY + yOffset:eventObj.y + yOffset + ((document.body.scrollTop)?document.body.scrollTop:0);
			}
			else
			{
				var newYCoordinate = (eventObj.pageY)?ypos + pos.y :ypos + pos.y  + ((document.body.scrollTop)?document.body.scrollTop:0);
			}
			if (document.images[thesource] == null)
			{
				newXCoordinate = pos.x + xpos;
				newYCoordinate = pos.y + ypos;
			}
			moveObject(targetObjectId, newXCoordinate, newYCoordinate);
			if( changeObjectVisibility(targetObjectId, 'visible','block')) 
			{
				window.currentlyVisiblePopup = targetObjectId;
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
}
function hideCurrentPopup()
{
    if(window.currentlyVisiblePopup)
	{
		changeObjectVisibility(window.currentlyVisiblePopup, 'hidden','none');
		window.currentlyVisiblePopup = false;
    }
}
//window.addOnload(initializeHacks);
document.onclick = hideCurrentPopup;
function initializeHacks()
{
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) && (navigator.platform.indexOf('Mac') != -1)	&& getStyleObject('blankDiv')) { window.onresize = explorerMacResizeFix; }
    resizeBlankDiv();
    createFakeEventObj();
}
function createFakeEventObj() {if (!window.event) { window.event = false; } }
function resizeBlankDiv()
{
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) && (navigator.platform.indexOf('Mac') != -1)	&& getStyleObject('blankDiv'))
	{
		getStyleObject('blankDiv').width = document.body.clientWidth - 20;
		getStyleObject('blankDiv').height = document.body.clientHeight - 20;
    }
}
function explorerMacResizeFix () { location.reload(false); }
