// Flash function for homepage feature panel

function embedFlashMovie(getPath,getWidth,getHeight,getTransparency,getMode) {
	// embed flash movie
	flashString = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='" + getWidth + "' height='" + getHeight + "'>";
	flashString += "<param name='movie' value='" + getPath + "'><param name='quality' value='high'>";
	if(getTransparency) flashString += "<param name='wmode' value='transparent'>";
	flashString += "<embed src='" + getPath + "' ";
	if(getTransparency) flashString += "wmode='transparent' ";
	flashString += "quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + getWidth + "' height='" + getHeight + "'><\/embed>";
	flashString += "<\/object>";
	// if getMode = 0 return string, else write string to document
	if(getMode == 0) return flashString
	else document.write(flashString);
}

// load flash page title

function fixTagsAndEncodings(srcTxtString) {
	//Fix comment tags
	if(srcTxtString.indexOf("InstanceBeginEditable") > 0) {
		//strip comments tags from text
		srcTxtString = srcTxtString.replace(/<!-- InstanceBeginEditable name="page title" -->/, "");
		srcTxtString = srcTxtString.replace(/<!-- InstanceEndEditable -->/, "");
	}
	//Fix encodings
	srcTxtString = srcTxtString.replace(/&amp;/, "&");
	srcTxtString = srcTxtString.replace(/&pound;/, "£");
	srcTxtString = srcTxtString.replace(/&lsquo;/, "‘");
	srcTxtString = srcTxtString.replace(/&rsquo;/, "’");
	srcTxtString = srcTxtString.replace(/&ldquo;/, "“");
	srcTxtString = srcTxtString.replace(/&rdquo;/, "”");
	srcTxtString = srcTxtString.replace(/&dquo;/, "\"");
	srcTxtString = srcTxtString.replace(/&squo;/, "\'");
	srcTxtString = srcTxtString.replace(/\n;/, "");
	srcTxtString = srcTxtString.replace(/\t;/, "");
	//Escape special characters
	srcTxtString = escape(srcTxtString);
	//Remove encoded spaces,line feeds etc
	while(srcTxtString.indexOf("%0A") > -1) {
		srcTxtString = srcTxtString.replace(/%0A/, "");
	}
	while(srcTxtString.indexOf("%09") > -1) {
		srcTxtString = srcTxtString.replace(/%09/, "");
	}
	while(srcTxtString.indexOf("%20%20") > -1) {
		srcTxtString = srcTxtString.replace(/%20%20/, "%20");
	}
	// remove leading space
	if(srcTxtString.indexOf("%20") == 0) srcTxtString = srcTxtString.substring(3, (srcTxtString.length-3));
	return srcTxtString;
}

function writeFlashTitle() {
	if (flash.ver[8]) {
		//********** Hide H1 ***********
		document.getElementById("pageTitle").style.display = "none";
		//********** Get Title Text **********
		getTitleText = document.getElementById("pageTitle").innerHTML.toString();
		//Fix string
		getTitleText = fixTagsAndEncodings(getTitleText);
		//embedFlashMovie(getPath,getWidth,getHeight,getTransparency)
		document.write("<div id='flashTitle'>");
		embedFlashMovie("\/olivermoon\/flash\/moon_page_title.swf?txt=" + getTitleText,740,100,true,1);
		document.write("<\/div>");
	}
}

function addSpider() {
	if (flash.ver[8]) {
		document.write("<div id='spider'>");
		embedFlashMovie("\/olivermoon\/flash\/moon_spider.swf",40,115,true,1);
		document.write("<\/div>");
	}
}
