/*
 * THIS FILE CONTAINS ALL FUNCTIONS FOR THE POPUP DIV
 */

function showPopup( sHtml, sImg, iHeight, iWidth )
{
	if( sHtml != null )
	{
		setPopupContent( sHtml );
	}
	else if( sImg != null )
	{
		if( iHeight > iWidth )
		{
			sHtml = '<img onclick="javascript:hidePopup();" src="' + sImg + '" height="' + iHeight*0.8 + '" />';
		}
		else
		{
			sHtml = '<img onclick="javascript:hidePopup();" src="' + sImg + '" width="' + iWidth*0.9 + '" />';
		}
		setPopupContent( sHtml );
	}
	
	if( iHeight != null )
	{
		$('popup_window').style.height = iHeight + 'px';
	}
	
	if( iWidth != null )
	{
		$('popup_window').style.width = iWidth + 'px';
	}
	window.setTimeout("doShowPopup()", 300);
}

function hidePopup()
{
	new Effect.Fade('popup_window',{	duration: '0.2'});
	setTimeout("Effect.Fade('popup',{duration: '0.08'})",400);
}

function doShowPopup( )
{
	$('popup').style.display ='block';

	var iHeight = $('popup_window').getHeight();
	var iWidth = $('popup_window').getWidth();

	$('popup_window').style.marginLeft = '-'+ iWidth / 2 + 'px';
	$('popup_window').style.marginTop = '-'+ iHeight / 2 + 'px';

	$('popup').style.display ='none';

	new Effect.Appear('popup',{	duration: '0.08'});
	setTimeout("Effect.Appear('popup_window',{duration: '0.2'})",400);
}

function setPopupContent( sHtml )
{
	for( i = 0; i < $('popup_window').childNodes.length; i++ )
	{
		if( $('popup_window').childNodes[i].className == 'popup_window_content' )
		{
			$('popup_window').childNodes[i].innerHTML = sHtml;
		}
	}
}
