/*
	Filename         :	mt.lib.flash.js
	Created by       :	Mark Thomas
	Last modified by :	Mark Thomas
	Created          :	24 April 2006 13:22:52
	Last Updated     :	25 April 2006 13:23:37
	Comments         :	
	usage			 : 
			MTFlashText.add({
				oHTML : "div#a2 h2", 
				sSwf : "lib/caecilia_bold.swf", 
				sBgColour : "#ffffff",
				sLinkColour : "#ff0000", //optional
				sHoverColour : "#ff0000", //optional
				bUnderline : true //optional
			});
*/


var MTFlashText = {
	add		: function(o){
		var sID = "FlashText" + MTFlashText._nInc++;
		this._aItems[this._aItems.length] = [o.oHTML, o.sSwf, sID, o.sBgColour, o.sLinkColour, o.sHoverColour, o.bUnderline];
		document.write("<style>#" + sID + " {position:absolute;} " + o.oHTML + "{visibility:hidden;}</style>");
	},
	_build	: function(){
		for(var i=0; i<this._aItems.length; i++){
			this._flashText(oMTLib.utils.getFromSelector(this._aItems[i][0]), this._aItems[i][1], this._aItems[i][2], this._aItems[i][3], this._aItems[i][4], this._aItems[i][5], this._aItems[i][6]);
		};
	},
	_nInc 	: 0,
	_aItems	: [],
	aElementCache	: [],
	_flashText : function(aObj, sSwf, sID, sBgColour, sLinkColour, sHoverColour, bUnderline){
		if(!aObj) return;
		if(!oMTLib.utils.flashCheck()) return;
		var sHTML, sColour, nPaddingHor, nPaddingVert, nWidth, nHeight, aColour;
		for(var i=0; i<aObj.length; i++){
			if(document.defaultView){
				sColour = document.defaultView.getComputedStyle(aObj[i], null).getPropertyValue("color");
				sBgColour = sBgColour || oMTLib.utils.rgbToHex(document.defaultView.getComputedStyle(aObj[i], null).getPropertyValue("background-color"));
				nPaddingHor = parseInt(document.defaultView.getComputedStyle(aObj[i], null).getPropertyValue("padding-left")) + parseInt(document.defaultView.getComputedStyle(aObj[i], null).getPropertyValue("padding-right"));
				nPaddingVert = parseInt(document.defaultView.getComputedStyle(aObj[i], null).getPropertyValue("padding-top")) + parseInt(document.defaultView.getComputedStyle(aObj[i], null).getPropertyValue("padding-bottom"));
			}else if(aObj[i].currentStyle){
				sColour = aObj[i].currentStyle["color"];
				sBgColour = sBgColour || aObj[i].currentStyle["backgroundColor"];
				nPaddingHor = parseInt(aObj[i].currentStyle["paddingLeft"]) + parseInt(aObj[i].currentStyle["paddingRight"]);
				nPaddingVert = parseInt(aObj[i].currentStyle["paddingTop"]) + parseInt(aObj[i].currentStyle["paddingBottom"]);
			};
			sBgColour = sBgColour.replace("transparent", "#ffffff");
			nWidth = aObj[i].offsetWidth - nPaddingHor;
			nHeight = aObj[i].offsetHeight - nPaddingVert;
			aObj[i].oFlash = new JSFlashObject(sSwf, sID, nWidth, nHeight, 5);
			if(sBgColour){
				aObj[i].oFlash.addParam("bgcolor", sBgColour);
			};
			aObj[i].oFlash.addParam("wmode", "");
			aObj[i].oFlash.addParam("menu", "false");
			if(sColour.indexOf("rgb") != -1){
				aColour = sColour.split("(")[1].split(")")[0].replace(/ /g, "").split(",");
				sColour = ["#", oMTLib.utils.decimalToHex(aColour[0]), oMTLib.utils.decimalToHex(aColour[1]), oMTLib.utils.decimalToHex(aColour[2])].join("");
			};
			if(sColour.length == 4){
				sColour = ["#", sColour.charAt(1), sColour.charAt(1), sColour.charAt(2), sColour.charAt(2), sColour.charAt(3), sColour.charAt(3)].join("");
			};
			sHTML = aObj[i].innerHTML.replace(/\+/g, "%2B").replace(/&/g, "%26").replace(/\"/g, "%22");
			if(aObj[i].tagName == "A"){
				sHTML = "<a href=%22" + aObj[i].href + "%22>" + sHTML + "</a>";
			};
			aObj[i].oFlash.addParam("flashvars", "textcolor=" + sColour + "&linkcolor=" + sLinkColour + "&hovercolor=" + sHoverColour + "&underline=" + bUnderline + "&w=" + nWidth + "&h=" + nHeight + "&txt=" + sHTML);
			aObj[i].innerHTML = "<em class=\"mtFlashText\">" + aObj[i].oFlash.getXHTML() + "</em>" + aObj[i].innerHTML;
			aObj[i].style.visibility = "visible";
			aObj[i].style.width = nWidth + "px";
			aObj[i].style.height = nHeight + "px";
			if(!(navigator.userAgent.toLowerCase().indexOf("mac") != -1 && navigator.userAgent.toLowerCase().indexOf("msie") != -1)){
				aObj[i].style.overflow = "hidden";
			}
		};
	}
}; mtLibAddEvent(function(){MTFlashText._build();}, "load");

document.write("<style>@media print {em.mtFlashText {display:none !important;height:0 !important;width:0 !important;position:absolute !important;overflow:hidden !important;}}</style>");

/*********************************************************************************/
function JSFlashObject(sPath, sID, nW, nH, nVersionRequired){
	this.sPath 				= sPath;
	this.sID 				= sID;
	this.nW 				= nW;
	this.nH 				= nH, 
	this.nVersionRequired 	= nVersionRequired || 6;
	this.sParamsIE 			= "";
	this.sParamsOther 		= "";
	this.sAltHTML			= "";
	this.addParam = function(sName, sValue){
		this.sParamsIE 		+= "<param name=\"" + sName + "\" value=\"" + sValue + "\" />"
		this.sParamsOther 	+= " " + sName + "=\"" + sValue + "\"";
	};
	this.bFlash = oMTLib.utils.flashCheck();
	this.getXHTML = function(){
		var sReturn = new String();
		if(this.bFlash >= this.nVersionRequired){
			if(window.ActiveXObject && navigator.userAgent.toLowerCase().indexOf('mac') == -1){
				sReturn += "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"" + this.nW + "\" height=\"" + this.nH + "\" id=\"" + this.sID + "\">";
				sReturn += "<param name=\"movie\" value=\"" + this.sPath + "\" />";
				sReturn += this.sParamsIE;
		        sReturn += "</object>";
			}else{
				sReturn += "<embed type=\"application/x-shockwave-flash\" src=\"" + this.sPath + "\" width=\"" + this.nW + "\" height=\"" + this.nH + "\" id=\"" + this.sID + "\"" + this.sParamsOther + "></embed>";
			};
		}else{
			sReturn += this.sAltHTML;	
		};
		return sReturn;		
	};
	this.addNonFlashHTML = function(sHTML){
		this.sAltHTML += sHTML;
	};
};



oMTLib.add("utils");
oMTLib.utils.flashCheck = function(nVersion){
	if(this.nFlash){
		return this.nFlashVersion
	};
	this.nFlashVersion = 0;
	if(navigator.plugins && navigator.plugins.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x){
			if(x.description){
				var y = x.description;
	   			this.nFlashVersion = y.charAt(y.indexOf('.')-1);
			};
		};
	}else{
		result = false;
	    for(var i=10; i>=3 && result != true; i--){
   			execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
   			this.nFlashVersion = i;
   		};
	};
	return this.nFlashVersion;
};