/**********************************************************
 *
 *	Persistent_Image.js
 *
 *	By: SvenL on 2003-11-03
 *
 ***/


/*
 *
 *
 *	[SL:20040609]:	Exit function for browser who have no support for getBoundingClientRect
 */
function placePIMG(oObj)
{
	if(!oObj)
		return false;

	var oPIMG = getPIMG();

	if(!oPIMG)
		return false;

	if((oObj.id == '') || (!oObj.id))
	{
		// zonder ID werkt het niet.
		clsCookie('KRMenu').removeKey('PIMG_Target');
		return false;
	}

	clsCookie('KRMenu').setValue('PIMG_Target', oObj.id);

	if(typeof(oObj.getBoundingClientRect) == 'undefined')
	{
		//Voor nu werkt het alleen met getBoundingClientRect :(
		return false;
	}

	var oRect	= oObj.getBoundingClientRect();
	var posX	= clsCookie('KRMenu').getValue('Width');
	posX		= (posX)?(posX):(oRect.right);
	var posY	= oRect.top;

	oPIMG.style.visibility	= 'hidden';
	oPIMG.style.display	= 'inline';

	oRect = oPIMG.getBoundingClientRect();

	oPIMG.style.display	= 'none';
	oPIMG.style.visibility	= 'visible';

	var diffX	= (oRect.right - oRect.left);
	var diffY	= (oRect.bottom - oRect.top);
	//				  A		TD				TR			TBODY			TABLE			DIV
	var oPosParent	= oObj.parentElement.parentElement.parentElement.parentElement.parentElement;
	var posY2		= parseInt(oPosParent.currentStyle.top, 10);
//window.alert('1: ' + posY + '\nT: ' + oPosParent.tagName + '\n2: ' + posY2);

	oPIMG.style.top		= (isNaN(posY2))?(posY):(posY2);
	oPIMG.style.left	= posX - diffX;
	oPIMG.style.display	= 'inline';

	return true;
}



function getPIMG()
{
	var oIMG = null;
	
	if(document.getElementById)
	{
		oIMG = document.getElementById("PIMG_v1_0")
	}
	else
	{
		if(document.all)
		{
			oIMG = document.all["PIMG_v1_0"]
		}
		else
		{
			if(document.layers)
			{
				oIMG = document.layers["PIMG_v1_0"]
			}
			else
			{
				return null;
			}
		}
	}

	if(!oIMG)
	{
		oIMG = window.document.createElement('img');

		if(!oIMG)
		{
			oIMG = null;
		}
		else
		{
			oIMG.id				= 'PIMG_v1_0';
			oIMG.name			= 'PIMG_v1_0';
			oIMG.className		= 'clsPIMG';

			var stdPath = clsCookie('KRMenu').getValue('stdPath');
			
			if(stdPath)
			{
				oIMG.src		= unescape(stdPath) + 'images/menu/arrow.gif';
			}
			else
			{
				if(typeof(szPAHT_Siteroot) != 'undefined')
				{
					oIMG.src	= szPATH_Siteroot + 'images/menu/arrow.gif'
				}
				else
				{
					oIMG.src	= '../images/menu/arrow.gif';
				}
			}

			oIMG.style.visibility	= 'hidden';
			oIMG.style.display		= 'inline';
			oIMG.style.position		= 'absolute';
			oIMG.style.zIndex		= 16382; // Mega on top (maar onder een eventuele Tooltip.

			window.document.body.appendChild(oIMG);
		}
	}
	
	return oIMG;
}



function initPIMG()
{
	var szTargetID = clsCookie('KRMenu').getValue('PIMG_Target');
	
	var oMI = null;

	if(document.getElementById)
	{
		oMI = document.getElementById(szTargetID)
	}
	else
	{
		if(document.all)
		{
			oMI = document.all[szTargetID]
		}
		else
		{
			if(document.layers)
			{
				oMI = document.layers[szTargetID]
			}
			else
			{
				return null;
			}
		}
	}

	placePIMG(oMI);
}



if(window.attachEvent)
{
	if(!window.attachEvent('onload', initPIMG))
		window.setTimeout('initPIMG();', 10000);
}
else
{
	// 
	window.setTimeout('initPIMG();', 10000);
}
