var debug=true;

function debugAlert(message)
{
	//if (debug == true)
	//{
	//	alert(message);
	//}
}

function Test2Init()
{
	if (!document.getElementById)
	{ 
		return; 
	}

	var iframe	= document.getElementById("iframeFixup");

	if ( iframe)
	{
		var lastIndexOfQuestionMark = document.URL.lastIndexOf('?');
		var lastIndexOfForwardSlash = document.URL.lastIndexOf('/');
		var lastIndexOfDot = document.URL.lastIndexOf('.');
		var lastIndexOfPercent = document.URL.lastIndexOf('%');

		if ( lastIndexOfQuestionMark != -1 && lastIndexOfForwardSlash != -1 && lastIndexOfDot != -1 )
		{
			var name = "gallery_recent";
			if ( lastIndexOfQuestionMark < lastIndexOfDot || lastIndexOfQuestionMark < lastIndexOfForwardSlash )
			{
				debugAlert("NO");
			}
			else if ( lastIndexOfPercent != -1 && ( lastIndexOfPercent > lastIndexOfForwardSlash || lastIndexOfPercent > lastIndexOfQuestionMark ) )
			{
				debugAlert("STILL NO");
			}
			else
			{
				name = document.URL.substring( lastIndexOfQuestionMark +1 );
				
				//var newIframeElement = iframe.cloneNode( true );
				//newIframeElement.src = document.URL.substring( 0, lastIndexOfForwardSlash ) + '/' + name + '.html';
				//newIframeElement.href = newIframeElement.href;
				//iframe.parentNode.replaceChild( newIframeElement, iframe );
				
				//newIframeElement.contentWindow.location.reload();
				//iframe.location.reload(true);
				//debugAlert("newIframeElement.src : " + newIframeElement.src );	

				iframe.src = document.URL.substring( 0, lastIndexOfForwardSlash ) + '/' + name + '.html';
			}
		}
	}
}

function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}

addLoadEvent(Test2Init);
