// Create var to tell other Utilities that this one is present
var SWFEMBED = true;

var FLASHCHECKED = false;

function hsEmbedSWF ( tagID, contentPath, w, h, wmode, lockroot, fv1, fv2, fv3, fv4, fv5 ) {
	
	var targetTag			= tagID			? document.getElementById(tagID)	: "";
	lockroot 				= lockroot 		? lockroot 							: false;
	wmode 					= wmode 		? wmode 							: 'transparent';
	fv1 					= fv1 			? fv1 								: '';
	fv2 					= fv2 			? fv2  								: '';
	fv3 					= fv3 			? fv3  								: '';
	fv4 					= fv4 			? fv4  								: '';
	fv5 					= fv5 			? fv5  								: '';
	
	// Target Tag must be a div
	if ( targetTag.nodeName == "DIV" ) {
		// All good.
	} else {
		targetTag.innerHTML = "This Element Must Be &lt;div&gt; rather than "+targetTag.nodeName+" for the SWF to be placed.";
		return false; // << Might cause problems in IE... if Full page is not loaded
	}
	
	var noflash = targetTag.innerHTML;
	
	var fullURL = "pub/util_hs_swfembed/hc.swf?path="+contentPath+"&tid="+tagID+"&lockroot="+lockroot+"&fv1="+fv1+"&fv2="+fv2+"&fv3="+fv3+"&fv4="+fv4+"&fv5="+fv5;
	
	if ( w ) { targetTag.style.width = w+"px"; };
	if ( h ) { targetTag.style.height = h+"px"; };
	
	var injection = "";
	
	injection += '\n\n\t<!-- Javascript Injected: swfEmbed() -->\n';
	injection += '\t\t<object type="application/x-shockwave-flash" data="'+fullURL+'" width="100%" height="100%">\n';
	injection += '\t\t<param name="movie" value="'+fullURL+'" />\n';
	injection += '\t\t<param name="allowScriptAccess" value="always" />\n';
	injection += '\t\t<param name="wmode" value="'+wmode+'" />\n';
	injection += '\t\t'+noflash+'\n';
	injection += '\t\t</object>\n';
	
	targetTag.innerHTML = injection;
	
	//trace(injection);
	
} // hsInjectSWF()

// Filter noflash replacement / Add Generic global noflash message
function noFlash (str) {
	//str = str.replaceAll("&gt;", '>');
	//str = str.replaceAll("&lt;", '<');
	if ( FLASHCHECKED ) {
		return str;
	} else {
		FLASHCHECKED = true;
		str += '\t<div id="divNoFlash" style="position:absolute; overflow:show; width:100%; height:auto; top:0px; left:0px; padding:5px 3px 5px 3px; background-color:#feffb6; border:1px solid #d7d400; font-family: Verdana, Arial, Tahoma; font-size:12px;">';
		str += '<span style="background-color:#feffb6;">The Adobe Flash Player is required to view the full content of this page. ';
		str += '<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank">Install Now &raquo;</a></span>';
		str += '</div>';
		return str;
	}
	
	return str;
}

String.prototype.replaceAll = function(pcFrom, pcTo){
	var i = this.indexOf(pcFrom);
	var c = this;
	
	while (i > -1){
		c = c.replace(pcFrom, pcTo); 
		i = c.indexOf(pcFrom);
	}
	return c;
}

function trace ( str ) {
	document.getElementsByTagName("body")[0].innerHTML += "<br />"+str;
	//window.alert(str);
}









/*
Parses function calls and holds them until [window.onload] is invoked - when the HTML/Images are fully loaded.
- Prevents Javascript functions from stopping the page from loading when called before it is completed ( IE Only)
- To be included fore-most in the HTML header.

Updates:
- checkInit() and checkInitDom() - two ways to check init
- do not allow duplicate array entries for repeat function calls
*/

window.onload = initPage;
var isPageLoaded = false;
var aFstrPage = new Array();

var isDomLoaded = false;
initDomCheck();
var aFstrDom = new Array();

function initPage () {
	if ( !isPageLoaded ) {
		//window.alert("initPage");
		isPageLoaded = true;
		var i;
		for ( i = 0; i < aFstrPage.length; i++ ) {
			//trace("<br />Call: "+aFstrPage[i]);
			eval(aFstrPage[i]);
		}
	}
}

function initDom () {
	// initDom is not currently working in Safari via initDomCheck()
	if ( !isDomLoaded ) {
		//window.alert("initDom");
		isDomLoaded = true;
		var l;
		for ( l = 0; l < aFstrDom.length; l++ ) {
			//trace("<br />Call: "+aFstrDom[l]);
			eval(aFstrDom[l]);
		}
	}
}

function initDomCheck () {
	// Safari/WebKit Engine - Must preceed the W3C test
	if ( /WebKit/i.test(navigator.userAgent) ) { // is WebKit Related...
		//window.alert("WebKit");
		var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
		  clearInterval(_timer);
		  initDom();
		}
		}, 10);
	//W3C
	} else if (document.addEventListener) {
		//window.alert("W3C");
		document.addEventListener("DOMContentLoaded", initDom, false);
	// IE
	} else { 
		//window.alert("IE");
		document.onreadystatechange = initDom;
	}
}

// Executes functions when all of the page content is loaded (including all images, plugin content, swf's, flv's)
function onInitPage (fstr) {
	var j;
	fstr = fstr+"(";
	for ( j = 1; j < arguments.length; j++ ) {
		switch ( typeof(arguments[j]) ) {
			case "string":
			fstr += "'"+arguments[j]+"'";
			break;
			
			case "number":
			case "boolean":
			fstr += arguments[j];
			break;
			
			default:
			//trace("<br />No Type Found for argument: "+j);
		}
		if ( (j+1) < arguments.length ) {
			fstr += ", ";	
		}
	}
	fstr += ")";
	
	if ( isPageLoaded == true ) {
		//trace("<br />Eval: "+fstr);
		eval(fstr);
	} else {
		//trace("<br />Saved: "+fstr);
		aFstrPage.push(fstr);
	}
} // onInitPage()

// Executes function(s) when the Document Object Model is ready.
function onInitDom (fstr) {
	var k;
	fstr = fstr+"(";
	for ( k = 1; k < arguments.length; k++ ) {
		switch ( typeof(arguments[k]) ) {
			case "string":
			fstr += "'"+arguments[k]+"'";
			break;
			
			case "number":
			case "boolean":
			fstr += arguments[k];
			break;
			
			default:
			//trace("<br />No Type Found for argument: "+j);
		}
		if ( (k+1) < arguments.length ) {
			fstr += ", ";
		}
	}
	fstr += ")";
	
	if ( isDomLoaded == true ) {
		//trace("<br />Eval: "+fstr);
		eval(fstr);
	} else {
		//trace("<br />Saved: "+fstr);
		aFstrDom.push(fstr);
	}
} // onInitDom()