/**
* Copyright (c) Copyright (c) 2007, Carl S. Yestrau All rights reserved.
* Code licensed under the BSD License: http://www.featureblend.com/license.txt
* Version: 1.0.3
*
* @param {String} source The source location (URL) of the Flash movie to load.
* @param {String || Number} width The width of the movie in either pixels (number) or percentage (string) of the browser window.
* @param {String || Number} height The height of the movie in either pixels (number) or percentage (string) of the browser window.
* @param {Object} (Optional) options Optional constructor arguments in object literal format. See attribute name/values combinations below.
* {String} allowfullscreen (true, false) To enable full-screen mode in Flash movie that can be terminated through ActionScript, keyboard shortcuts, or by the user switching focus to another window. The default Flash movie value is false. See Exploring full-screen mode in Flash Player 9 for more details.
* {String} allowscriptaccess (never, always) Controls the ability to perform outbound scripting from within a Flash movie. See Adobe TechNote AllowScriptAccess for more details.
* {String} allownetworking (all, internal, none) Specifies Flash movie access to network functionality. The default Flash movie value is all. See Restricting networking APIs for more details.
* {String} align (l, t, r, b) Specifies the Flash movie alignment and cropping of the remaining three sides. By default the Flash movie is centered in the browser and the edges are cropped if the window is smaller than the actual movie size.*
* {String} base (".", base directory or URL) Specifies the base directory or URL used to resolve all relative paths in the Flash movie.
* {String} bgcolor (#EFEFEF, hexadecimal RGB color value) Specifies the the background color of the Flash movie. This can be used to overide the background color specified in the Flash movie.
* {String} id The id attribute value for the object element.
* {Object} flashvars Specifies the root level variables for the Flash movie. The format of flashvars follows JavaScript Object Notation ({"name-1":"value-1", "name-n":"value-n"}). Be aware that the maximum size of the total name/value pairs is restricted to 64KB (65535 bytes) in size.
* {String} loop (true, false) Specifies if the Flash movie repeats or stops when it reaches the last frame. The default Flash movie value is true.*
* {String} menu (true, false) Specifies if the Flash movie displays - right-click - the full menu of options to control the Flash movie.*
* {String} play (true, false) Specifies if the Flash movie plays immediately once loaded in the browser. The default Flash movie value is true.*
* {String} quality (low, high, autolow, autohigh, best) Specifies the quality of the Flash movie.*
* {String} salign (l, t, r, b, tl, tr, bl, br) Specifies the Flash movie alignment and cropping of the remaining sides.*
* {String} scale (showall, noborder, exactfit) Specifies the visibility, distortion and aspect ratio of a Flash movie. The default Flash movie value is showall.*
* {String} swliveconnect (true, false) Specifies if Java should start when loading the Flash Player for the first time.*
* {Number} tabindex The tabindex attribute value for the object element.
* {String} wmode (window, opaque, transparent) Specifies the Window Mode property of the Flash movie for transparency, layering, and positioning in a browser.*
*/
function FlashTML(source, width, height){
var self = this;
var baseElement = document.createElement("div");
var options = arguments[3] || {};
var winIE = ((navigator.appVersion.toLowerCase().indexOf("win")!=-1) && (navigator.appName=="Microsoft Internet Explorer"));
var idCount = FlashTML.idCount++;
var namespaceAdded = false;
var namespaceName = "flashtml";
var namespaceURN = "http://www.featureblend.com/2007/flashtml/";
self.domTemplate = "";
self.innerHTML = "";
self.xhtml = "";
self.inDocumentElement = "";
/**
* Gracefully retrieve an options attribute.
*
* @param {String} name A constructor options attribute name.
* @return Either an object from the getNameValueAttributes method OR an empty string.
* @type {Object||String}
*/
var getNameValueAttrFromOptions = function(name){
return (options.hasOwnProperty(name))?getNameValueAttributes(name, options[name].toString()):"";
};
/**
* Create an object denoting a name/value pair following parser conventions.
*
* @param {String} name An arbitrary name.
* @param {String} value An arbitrary value.
* @return An object literal having @name and @value properties.
* @type Object
*/
var getNameValueAttributes = function(name, value){
return {
"@name":name,
"@value":value
};
};
/**
* Create an element following parser conventions.
*
* @param {String} name The element name following parser conventions (eg., #param -> ).
* @param {Object} target The target element to append the newly created element.
* @return The created in memory element using document.createElement.
* @type Object
*/
var createElementFromRule = function(name, target){
var newElement = safeCreateElement(name.replace("#",""));
return target.appendChild(newElement);
};
/**
* Set an attribute value following parser conventions.
*
* @param {String} name The attribute name following parser conventions (eg., @foo -> foo="").
* @param {String} value The desired attribute value to set.
* @param {Object} target The target element to append the newly created attribute.
*/
var setAttributeFromRule = function(name, value, target){
target.setAttribute(name.replace("@",""), value);
};
/**
* Safely create an element either using native XHTML namespace OR namespaceName namespace. This is a workaround for Windows Internet Explorer
* interpreting in memory object elements before they are appended to the DOM.
*
* @param {String} name A valid XHTML element name.
* @return The created in memory element using document.createElement using a custom namespace if required.
* @type Object
*/
var safeCreateElement = function(name){
if((name=="object" || name=="param") && document.namespaces){
if(!namespaceAdded){
document.namespaces.add(namespaceName, namespaceURN);
namespaceAdded = true;
}
return document.createElement(namespaceName + ":" + name);
}else{
return document.createElement(name);
}
};
/**
* Clean namespace and xml declaration from a string. This is a very limited cleanser specific to markup generation for Flash.
*
* @param {String} str A string to perform cleaning routines on.
* @return A string in proper XHTML notation.
* @type String
*/
var htmlTidy = function(str){
str = str.replace(/<\?xml([^>]*)>/, "");
str = str.replace(eval("/"+namespaceName+":/g"),"");
str = str.replace(/><\/param>/g,">");
str = str.replace(/()/g, "");
return str;
};
/**
* General Flash structural rules parser. Takes an object literal following a specific convention and creates
* an appropriate DOM reference.
* NOTE: Due to inconsistencies in how Internet Explorer treats in memory 'object' elements, a namespace is applied.
*
* @param {Object} position An object literal following structural positional rules.
* @param {Object} target A temporary DOM element to peg structural elements too.
*/
var parseRules = function(position, target){
for(var i in position){
if(position.hasOwnProperty(i)){
if(i.charAt(0)=="#"){
var appendedElement;
if(typeof position[i] == "object" && position[i].length){
for(var j=0; j