// HTMLElement ID that serves as a container for the whole player
var containerId = 'media';

// HTMLElement ID that serves as a container for the media
var stageId = 'media_embed';

// Folder of the media relative to the SWF media Player files
var mediaFolder = "movies";

// Propety to store the Type of media that shows ('flash' or 'quicktime')
var mediaType = "";

// HTMLElements ID to show when media plays
var onStage = new Array('media');

// HTMLElements ID to hide when media plays
// var offStage = new Array('content', 'pagetitletext');
var offStage = new Array();

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);
	var swfPath = aTag.href.substring(0, aTag.href.indexOf('/' + mediaFolder + '/'));
	
	if (document.getElementById && hrefExt == '.flv') {
	
		// Center container layer
		// Check for DOM compatibility
		
		var contElement = document.getElementById(containerId);
		
		var winWidth = (window.innerWidth) ? window.innerWidth : ((document.body && document.body.offsetWidth) ? document.body.offsetWidth : 0);
		var winHeight = (window.innerHeight) ? window.innerHeight : ((document.body && document.body.offsetHeight) ? document.body.offsetHeight : 0);
		var newLeft = (winWidth - contElement.offsetWidth) / 2;
		var newTop = ((winHeight - contElement.offsetHeight) / 2) + ((window.pageYOffset) ? window.pageYOffset : ((document.body.scrollTop) ? document.body.scrollTop : 0));
		
		if (newLeft > 0 && newTop > 0) {
		
			contElement.style.left = parseInt(newLeft) + "px";
			contElement.style.top = parseInt(newTop) + "px";
			
		}
		
		// Show and fill stage layer
		
		showMediaLayers();
		
		var stageElement = document.getElementById(stageId)
				
		var flashHtml = AC_FL_GetContent( 'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0', 'width', stageElement.offsetWidth, 'height', stageElement.offsetHeight, 'id', 'FLVPlayer', 'src', swfPath + '/FLVPlayer_Progressive', 'flashvars', '&MM_ComponentVersion=1&skinName=' + swfPath + '/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', swfPath + '/FLVPlayer_Progressive' );
		
		// window.alert(flashHtml);
		
		document.getElementById(stageId).innerHTML = flashHtml;
				
		mediaType = "flash";
		
	}

}

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

}

function stopFlash() {
	
	if (document.FLVPlayer && typeof(document.FLVPlayer.sendEvent) == "function") 
		document.FLVPlayer.sendEvent("stop");

			
}

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

function showMediaLayers() {
	
	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";
    	
    }

}

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(stageId);
		document.getElementById(stageId).innerHTML = "&nbsp;";
		
	}
	
}


function showQuicktime(movieSrc) {
	
	if (document.getElementById) {
		
		showMediaLayers();
		
		if (is_ie5up) {
			
			document.getElementById(stageId).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(stageId);
		
			while (myStage.hasChildNodes())
				myStage.removeChild(myStage.firstChild);
			
			myStage.appendChild(myObj);
			
			mediaType = "quicktime";

		}
				
	}
	
}

