var UA = ( "" + window.navigator.userAgent );
var MSIE = UA.indexOf("MSIE") > 0;
var MSIE6 = UA.indexOf("MSIE 6") > 0;
var Safari = UA.indexOf("Safari") > 0;

var Cur;
function Show(id)
{
	if(Cur)
		Cur.style.display="none";
	Cur = document.getElementById(id);
	Cur.style.display="block";
	document.getElementById("UILink").style.display="";
}


function OIFL()
{
	try
	{
		var D, O = document.getElementById("Overlay");
		if(MSIE)
			D = document.frames("OverlayF").document;	//	T.document;
		else
		{
			var T;
			T = O.childNodes[2];
			D = T.contentWindow.document;
		}

	//	alert( D.title );
		O.childNodes[1].childNodes[0].innerHTML = D.title;
	}
	catch(e)
	{
		// probably just a foreign page blocked by security
	}
}

var AE;
if( window.attachEvent )
	AE = function( name, hdlr )
	{
		this.attachEvent( "on" + name, hdlr );
	};
else
	AE = function( name, hdlr )
	{
		this.addEventListener( name, hdlr, true );
	};

function OnOLLClick()
{
	var E;
	if(MSIE)
		E = window.event.srcElement;
	else
		E = this;
	alert( E.getAttribute("orig_href") + "\n" + E.getAttribute("title") );
	ShowOverlay(E.getAttribute("orig_href"),E.getAttribute("title"));
	return false;
}

function OPL()
{
	var HasOLL;
	var As = document.getElementById("moretext").getElementsByTagName("A"), L = As.length;
	for( var i=0; i < L; i++ )
	{
		var A = As[i];
		if( A.className == "OverlayLink" )
		{
			A.setAttribute("orig_href",A.href);
			A.href="#";
			A.target = null;
			
			if( A.getAttribute("sample") != null )
				AE.call( A, "click", OnSampleClick );
			else
				AE.call( A, "click", OnOLLClick );
			HasOLL = true;
		}
	}
	if( HasOLL )
	{
		AE.call( document.getElementById("Overlay").childNodes[2], "load", OIFL );
	}
}

AE.call( window, "load", OPL );

/*
<div id="Overlay">
	<div class="SneezeGuard">&nbsp;</div>
	<div class="TitleBar">
		<span>Title</span>
		<img src="/common/images/CloseX-grey.gif" onclick="HideOverlay()" />
	</div>
	<iframe src="about:blank"></iframe>
</div>
*/
function ShowOverlay(url,title)
{
	var O = document.getElementById("Overlay");
	O.childNodes[3].style.display="none";
	var OF = O.childNodes[2];
	OF.src = url;
	OF.style.display="block";
	
	O.childNodes[1].childNodes[0].innerHTML = title ? title : "Course sample";
		
	O.style.display="block";

	if(Safari)	// odd little bug(?): IFrame doesn't respond to right and bottom CSS props
	{
		var W = O.clientWidth;
		OF.style.width = (W - 64) + "px";
		OF.style.height = ( O.clientHeight - 80) + "px";
		OF.style.border = "0px";
	}
	O = OF = null;
	return false;
}

function HideOverlay()
{
	document.getElementById("Overlay").style.display="none";
	return false;
}

////////////////////////////////////////////////////////////////////////////////

function OnSampleClick()
{
	var E;
	if(MSIE)
		E = window.event.srcElement;
	else
		E = this;
	ShowCourseSample(E.getAttribute("orig_href"),E.getAttribute("title"));
	return false;
}

function ShowCourseSample(url,title)
{
	var O = document.getElementById("Overlay");
	O.childNodes[2].style.display="none";
	O.childNodes[1].childNodes[0].innerHTML = title ? title : "Course sample";
	
	var CS = O.childNodes[3];
	CS.style.display="block";
	
	var URL = url.substr( 0, url.lastIndexOf(".") ) + ".jar";
	
	CS.innerHTML = '<APPLET CODE = "com.impatica.v302.ImPlayerConsole.class"' +
        ' ARCHIVE = "http://uofthenet.org/alliant/ImPlayer302.jar" WIDTH = 720 HEIGHT = 564>' +
        '<PARAM NAME = "ARCHIVE" VALUE = "http://uofthenet.org/alliant/ImPlayer302.jar">' +
        '<PARAM NAME = "COLOR0" VALUE = "000066">' +
        '<PARAM NAME = "COLOR1" VALUE = "CCCCFF">' +
        '<PARAM NAME = "FILE" VALUE = "' + URL + '">' +
        '<PARAM NAME = "BGCOLOR" VALUE = "FFFFFF">' +
      '</APPLET>';
	
	O.style.display="block";
		
	O = CS = null;
	return false;
}
/*
<APPLET CODE = "com.impatica.v302.ImPlayerConsole.class"
        ARCHIVE = "http://uofthenet.org/alliant/ImPlayer302.jar" WIDTH = 720 HEIGHT = 564>
        <PARAM NAME = "ARCHIVE" VALUE = "http://uofthenet.org/alliant/ImPlayer302.jar">
        <PARAM NAME = "COLOR0" VALUE = "000066">
        <PARAM NAME = "COLOR1" VALUE = "CCCCFF">
        <PARAM NAME = "FILE" VALUE = "Sexuality1c-Sample-imp.jar">
        <PARAM NAME = "BGCOLOR" VALUE = "FFFFFF">
      </APPLET>
*/
