var stageName = 'media_embed';
var offStage = new Array('nav', 'content', 'pagenav');
var onStage = new Array('media');
var mediaType = "";

// window.alert((window.innerHeight) ? window.innerHeight : ((document.documentElement.clientHeight) ? document.documentElement.clientHeight : ""));

function showFlash(aTag) {
	
	var hrefExt = aTag.href.substring(aTag.href.length-4, aTag.href.length);
	var hrefWOExt = aTag.href.substring(0, aTag.href.length-4);
	// window.alert(hrefExt);
	// window.alert(hrefWOExt);
	
	if (document.getElementById && hrefExt == '.flv') {
		
		for (var i = 0; i < onStage.length; i++) {
			
			document.getElementById(onStage[i]).style.visibility = "visible";
			
		}

		for (var i = 0; i < offStage.length; i++) {
			
			document.getElementById(offStage[i]).style.visibility = "hidden";
			
		}
		
		var flashHtml = AC_FL_GetContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width','592','height','333','id','FLVPlayer','src','../../flash/FLVPlayer_Progressive','flashvars','&MM_ComponentVersion=1&skinName=../../flash/Corona_Skin_3&streamName=' + hrefWOExt + '&autoPlay=true&autoRewind=false','quality','high','scale','noscale','name','FLVPlayer','salign','lt','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','../../flash/FLVPlayer_Progressive' );
		
		// var debugWin = window.open();
		// debugWin.document.writeln('<pre>' + flashHtml + '</pre>');
		// debugWin.document.close();

		document.getElementById(stageName).innerHTML = flashHtml;
				
		mediaType = "flash";
		
	}

}

function hideMedia() {

	switch(mediaType) {
		
		case "flash":
			stopFlash();
			break;
		case "quicktime":
			stopQuicktime();
			break;
		
	}
	
	hideMediaLayers();

}

function stopFlash() {
	
	/*
	
	var playerArgs;
	
	for (prop in document.FLVPlayer) {
	
		playerArgs += prop + ": " + document.FLVPlayer[prop];
			
	}
	
	var debugWin = window.open();
	debugWin.document.write("<pre>" + playerArgs + "</pre>");
	window.close();
	
	if (typeof(document.FLVPlayer.dispatchEvent) == "function") 
		document.FLVPlayer.dispatchEvent("stop",null);
	
	*/
	
	if (typeof(document.FLVPlayer.sendEvent) == "function") 
		document.FLVPlayer.sendEvent("stop");

			
}

function stopQuicktime() {
	
	if (typeof(document.media_movie.Stop) == "function")
		document.FLVPlayer.Stop();
	
}

function hideMediaLayers() {
	
	if (document.getElementById) {
		
		for (var i = 0; i < offStage.length; i++) {
			
			document.getElementById(offStage[i]).style.visibility = "visible";
			
		}

		for (var i = 0; i < onStage.length; i++) {
			
			document.getElementById(onStage[i]).style.visibility = "hidden";
			
		}

		myStage = document.getElementById(stageName);
		document.getElementById(stageName).innerHTML = "&nbsp;";
		
	}
	
}


function showQuicktime(movieSrc) {
	
	if (document.getElementById) {
		
		for (var i = 0; i < offStage.length; i++) {
			
			document.getElementById(offStage[i]).style.visibility = "hidden";
			
		}
		
		document.getElementById(frameName).style.visibility = "visible";
		
		if (is_ie5up) {
			
			document.getElementById(stageName).innerHTML = 
			"<object " + 
			"classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" " + 
			"codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\" " + 
			"height=\"345\" " + 
			"width=\"440\" " + 
			"name=\"media_movie\">" + 
				"<param name=\"enablejavascript\" value=\"true\" />" + 
				"<param name=\"controller\" value=\"true\" />" + 
				"<param name=\"autoplay\" value=\"true\" />" + 
				"<param name=\"src\" value=\"" + movieSrc + "\" />" + 
				"<param name=\"scale\" value=\"aspect\" />" + 
				"<embed name=\"media_movie\" " + 
				"type=\"video/quicktime\" " + 
				"height=\"345\" " + 
				"width=\"440\" " + 
				"scale=\"aspect\" src=\"" + movieSrc + "\" " + 
				"autoplay=\"true\" " + 
				"controller=\"true\" " + 
				"enablejavascript=\"true\">" + 
				"</embed>" + 
			"</object>";
			
			mediaType = "quicktime";
			
		} else {
			
			myObj = document.createElement("object");
			myObj.setAttribute("name", "media_movie");
			myObj.setAttribute("id", "media_movie");
			myObj.setAttribute("classid", "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B");
			myObj.setAttribute("codebase", "http://www.apple.com/qtactivex/qtplugin.cab");
			myObj.setAttribute("width", "440");
			myObj.setAttribute("height", "345");
		
			myParams = new Array();
		
			myParams[myParams.length] = document.createElement("param");
			myParams[myParams.length -1].setAttribute("name", "enablejavascript");
			myParams[myParams.length -1].setAttribute("value", "true");
			myObj.appendChild(myParams[myParams.length -1]);
		
			myParams[myParams.length] = document.createElement("param");
			myParams[myParams.length -1].setAttribute("name", "controller");
			myParams[myParams.length -1].setAttribute("value", "true");
			myObj.appendChild(myParams[myParams.length -1]);
		
			myParams[myParams.length] = document.createElement("param");
			myParams[myParams.length -1].setAttribute("name", "src");
			myParams[myParams.length -1].setAttribute("value", movieSrc);
			myObj.appendChild(myParams[myParams.length -1]);
		
			myParams[myParams.length] = document.createElement("param");
			myParams[myParams.length -1].setAttribute("name", "scale");
			myParams[myParams.length -1].setAttribute("value", "aspect");
			myObj.appendChild(myParams[myParams.length -1]);
		
			myEmbed = document.createElement("embed");
			myEmbed.setAttribute("name", "media_movie");
			myEmbed.setAttribute("src", movieSrc);
			myEmbed.setAttribute("type", "video/quicktime");
			myEmbed.setAttribute("scale", "aspect");
			myEmbed.setAttribute("controller", "true");
			myEmbed.setAttribute("enablejavascript", "true");
			myEmbed.setAttribute("width", "440");
			myEmbed.setAttribute("height", "345");
			myObj.appendChild(myEmbed);
		
			myStage = document.getElementById(stageName);
		
			while (myStage.hasChildNodes())
				myStage.removeChild(myStage.firstChild);
			
			myStage.appendChild(myObj);
			
			mediaType = "quicktime";

		}
				
	}
	
}
