var currentActivity;
var currentPath;

function LA_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.LA_p) d.LA_p=new Array();
    var i,j=d.LA_p.length,a=LA_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.LA_p[j]=new Image; d.LA_p[j++].src=a[i];}}
}

function LA_swapImgRestore() { //v3.0
	var i,x,a=document.LA_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  
	if (currentActivity)
	{
		var currentType = "";
		
		if (currentPath.indexOf("Clear") > -1) currentType = "Clear";
		if (currentPath.indexOf("Practice") > -1) currentType = "Practice";
		if (currentPath.indexOf("Input") > -1) currentType = "Input";
		if (currentPath.indexOf("Output") > -1) currentType = "Output";
		
		var imagePath = "../../../images/" + currentType + "_off.gif";
		
		currentActivity.src = imagePath;
		
		currentActivity = null;
		currentPath = null;
	}
}

function LA_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=LA_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function LA_swapImage(image,blank,imageType,number,activityNumber) 
{
	var i,j=0,x,a=LA_swapImage.arguments; document.LA_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=LA_findObj(a[i]))!=null){document.LA_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

	if (image.indexOf("image") > -1)
	{
		image = "activity" + activityNumber;
		
		var imageRef = parent.document.getElementById(image);
		
		if (imageType.indexOf("Clear") > -1) imageType = "Clear";
		if (imageType.indexOf("Practice") > -1) imageType = "Practice";
		if (imageType.indexOf("Input") > -1) imageType = "Input";
		if (imageType.indexOf("Output") > -1) imageType = "Output";
		
		var imagePath = "../../../images/" + imageType + image.replace("activity","") + "_on.gif";
		
		imageRef.src = imagePath;
		currentActivity = imageRef;
		currentPath = imagePath;
	}
}

function OpenFooterAsset(URL)
{
	var newWindow = window.open(URL,"LearnAlberta","toolbar=no,location=yes,directories=no,status=no,menubar=yes,scrollbars=yes,scrolling=yes,resizable=yes,width=750,height=550,left=0,top=0");
	newWindow.focus();
}

function embedHeader(source)
{
	document.write( '<iframe src="' + source + '" height="90" width="100%" scrolling="no"></iframe>' );
}

function embedActivity(source)
{
	document.write( '<iframe src="' + source + '" height="100%" width="100%" scrolling="no"></iframe>' );
}

function embedActivityNavigation(source)
{
	document.write( '<iframe src="' + source + '" height="30" width="100%" scrolling="no"></iframe>' );
}

function embedGroupNavigation(source)
{
	document.write( '<iframe src="' + source + '" height="100%" width="50" scrolling="no"></iframe>' );
}

function embedDescription(source)
{
	document.write( '<iframe src="' + source + '" height="100%" width="100%" scrolling="auto"></iframe>' );
}

function embedIFrame(asset)
{
	var text2 = '<iframe src="' + asset + '" height="100%" width="100%" scrolling="auto" frameborder="0" id="iframeBody"></iframe>';
	
	return text2;
}

function openAsset(source)
{
	var newWindow = window.open("openAsset.html?asset=" + source,"Annie","toolbar=no,location=yes,directories=no,status=no,menubar=yes,scrollbars=yes,scrolling=yes,resizable=yes,width=400,height=300,left=0,top=0");
	newWindow.focus();
}

function resizeTables() 
{
	var getGroupDiv=document.getElementById("groupDiv");
	var getActivityDiv=document.getElementById("activityDiv");
	var getNavDiv=document.getElementById("navDiv");
	var getiFrameBody=document.getElementById("iframeBody");
	
	height = document.body.clientHeight;
	width = document.body.clientWidth;
	
	if (height<minimumGroupHeight) {
		groupHeight = minimumGroupHeight-groupTop;
		groupTop = headerHeight - 20;
		activityHeight = height - headerHeight - activityNavHeight;					
		activityNavTop = activityHeight + headerHeight-20;
	
		getGroupDiv.style.height=minimumGroupHeight-groupTop;					
		getActivityDiv.style.height=minimumGroupHeight-headerHeight;
		getNavDiv.style.top=minimumGroupHeight-20;
		iframeHeight=minimumGroupHeight-headerHeight-25;
		iframeWidth=width-groupHeight-5;					
		getiFrameBody.width=document.body.clientWidth-50-5;
		getiFrameBody.height=iframeHeight;					
	}else{
		groupHeight = height - headerHeight - activityNavHeight + 40;
		activityHeight = height - headerHeight - activityNavHeight;					
		activityNavTop = activityHeight + headerHeight;
		getGroupDiv.style.height=groupHeight;					
		getActivityDiv.style.height=activityHeight;
		getNavDiv.style.top=height-activityNavHeight;					
		iframeHeight=height-headerHeight-activityNavHeight-5;
		iframeWidth=width-60;					
		getiFrameBody.width=iframeWidth;
		getiFrameBody.height=iframeHeight;
		//alert(getiFrameBody.width);
	}
}

function embedResource(asset, height, width, color)
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ');
	document.write('height="' + height + '"');
	document.write('width="' + width + '">');
	document.write('<param name="src" value="' + asset + '">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="align" value="middle">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="bgcolor" value="' + color + '">');
	document.write( '<embed ' );
	document.write( '  src="' + asset + '" ' );
	document.write( '  name="' + name + '"' );
	document.write( '  height="' + height + '" ' );
	document.write( '  width="' + width + '" ' );
	document.write( '  align="middle" ' );
	document.write( '  quality="high" ' );
	document.write( '  allowScriptAccess="sameDomain" ' );
	document.write( '  scale="tofit" ' );
	document.write( '  pluginspage="http://www.macromedia.com/go/getflashplayer" ' );
	document.write( '  bgcolor="' + color + '" ' );
	document.write( '  type="application/x-shockwave-flash">' );
	document.write( '</embed>' );
	document.write('</object>');
}

function embedRecorderApplet()
{
	document.write('<applet ');
	document.write('	id="idrecorderCode" ');
	document.write('	code="es.ua.virtua.RecorderApplet" ');
	document.write('	archive="../../../Global/assets/recorder.jar, ../../../Global/assets/commons-logging.jar" ');
	document.write('	width="1" height="1" mayscript> ');
	document.write('	<PARAM NAME="mayscript" VALUE="true" > ');
	document.write('	<PARAM NAME="target" VALUE="memory" > ');
	document.write('	<PARAM NAME="showgui" VALUE="embedded" > ');
	document.write('	<PARAM NAME="enableJSCallback" VALUE="true" > ');
	document.write('</applet> ');
}