    htmlControls = new Array();

    function fcAddChild(o) {
    	var movie = fcGetMovieById(o.movieId);
    	htmlControls.movieId = o.movieId;
    	
    	if (o.type=="division") {
    		fcAddChildDivision(o);
    		movie.htmlCreationComplete(o.id);
    	}
    	else if (o.type=="iframe") {
    		fcAddChildIFrame(o);
    	}
    	else if (o.type=="editor") {
    		fcAddChildEditor(o);
    	}
    }
    
    function fcAddChildDivision(o) {
		fcGetIncludes(o.includesBefore);
		var newElement = document.createElement("div");
		newElement.id = o.id;
		newElement.name = o.name;
		newElement.movieId = o.movieId;
		
		newElement.style.position = o.position;
		fcSetSize(newElement,o.width,o.height);
		fcMoveElementTo(newElement,o.x,o.y);
		newElement.style.backgroundColor = "#" + o.backgroundColor;
		newElement.style.padding = "0px";
		newElement.style.margin = "0px";
		// always 0px - do not add a border to the container div tag
		// add a border in mxml or add a child div tag in the htmlText property and add a border to that
		newElement.style.border = o.border;
		newElement.innerHTML = o.htmlText;
		
		document.body.appendChild(newElement);
		
		fcAddToGlobalArray(newElement, o.type);
		fcSetScrollPolicyById(o.id, o.htmlScrollPolicy);
		
		fcGetIncludes(o.includesAfter);
		
		if (!o.visible) {
			//fcHide(o.id,true,false);
		}
    }

    function fcAddChildEditor(o) {
		
		fcGetIncludes(o.includesBefore);
		var editorName = o.name + "Editor";
		var newElement = document.createElement("div");
		newElement.id = o.id;
		newElement.name = o.name;
		newElement.movieId = o.movieId;
		
		newElement.style.position = o.position;
		fcSetSize(newElement,o.width,o.height);
		fcMoveElementTo(newElement,o.x,o.y);
		newElement.style.backgroundColor = "#" + o.backgroundColor;
		newElement.style.padding = "0px";
		newElement.style.margin = "0px";
		newElement.style.border = o.border;
		
		var textareaElement = document.createElement("textarea");
		textareaElement.id = editorName;
		textareaElement.name = editorName;
		textareaElement.value = o.htmlText;
		fcSetSize(textareaElement,"100%","100%");
		newElement.appendChild(textareaElement);
		
		document.body.appendChild(newElement);
		fcSetScrollPolicyById(o.id, o.htmlScrollPolicy);

		if (o.editorType=="fckeditor") {
			// Create an instance of FCKeditor (using the target textarea as the name).
			var oFCKeditor = new FCKeditor( editorName ) ;
			oFCKeditor.BasePath = o.editorPath;
			if (o.configPath) {
				oFCKeditor.Config["CustomConfigurationsPath"] = o.configPath +"?" + ( new Date() * 1 ) ;
			}
			oFCKeditor.Width = '100%' ;
			oFCKeditor.Height = '100%' ;
			oFCKeditor.ReplaceTextarea() ;
		}
		else if (o.editorType=="tinymce") {
		    var elm = document.getElementById(o.id);
		    var movie = fcGetMovieById(o.movieId);
		    movie.htmlCreationComplete(o.id);
		    
			if (typeof o.editorOptions == "string") {
				// crashes firefox???
				//tinyMCE.init({mode:"exact",theme:"simple"});
			}
			else {
				tinyMCE.init(o.editorOptions);
			}
			
			if (tinyMCE.getInstanceById(editorName) == null) {
			}
		}
		
		fcAddToGlobalArray(newElement, o.type);
		
		if (!o.visible) {
		}
		
    }

    function fcAddChildIFrame(o) {
		var newElement = document.createElement("iframe");
		newElement.id = o.id;
		newElement.name = o.name;
		newElement.movieId = o.movieId;
		newElement.width = o.width;
		newElement.height = o.height;		
		newElement.frameBorder = o.frameborder;
		newElement.style.position = o.position;
		fcSetSize(newElement,o.width,o.height);
		fcMoveElementTo(newElement,o.x,o.y);
		newElement.style.border = o.border;
		newElement.src = o.source;
		
		document.body.appendChild(newElement);
		
		newElement.onload = new function() {
			var movie = fcGetMovieById(o.movieId);
			movie.htmlCreationComplete(o.id);
		}
		
		newElement.onunload = new function() {
			var movie = fcGetMovieById(o.movieId);
			movie.htmlCreationComplete(o.id);
		}
		
		if (!o.visible) {
		}
    }
	
	function fcAddToGlobalArray(el, elementType) {
		var newElement = new Object();
		newElement.element = el;
		newElement.id = el.id;
		newElement.loaded = false;
		newElement.type = elementType;
		newElement.editor = "";
		if (elementType == "editor") {
			newElement.editor = document.getElementById(el.id + "Editor");
		}
		htmlControls[el.id] = newElement;
	}
	
	function fcCallScript(str) {
		try {
			var something = eval(str);
			return something;
		}
		catch(e) {
			return false;
		}
	}
	
	function fcDefocus(movieId) {
		var movie = fcGetMovieById(movieId);
		window.focus();
		movie.focus();
	}
    
	function FCKeditor_OnComplete( editorInstance ) {
		var editor = document.getElementById( editorInstance.Name );
		if (editor) {
			htmlControls[editor.parentNode.id].loaded = true;
    		var movie = fcGetMovieById(editor.parentNode.movieId);
			movie.htmlCreationComplete(editor.parentNode.id);
		}
	}
	
	function fcGetElement(id) {
		return document.getElementById(id);
	}
	
 
	function fcGetElementHeight(id){
		var el = fcGetElement(id);
		moz = (document.getElementById && !document.all);
		
		if (el){
		
			// check the height value
			try {
			
				/*** return div height ***/
				if (el.nodeName.toLowerCase()=="div") {
					var scrollHeight = el.scrollHeight;
					var divHeight = el.style.height;
					divHeight = (scrollHeight > parseInt(divHeight)) ? scrollHeight : divHeight;
					return divHeight;
				}
				
				/*** return iframe height ***/
				//moz
				if (moz) {
					return el.contentDocument.body.scrollHeight;
				}
				else if (el.Document) {
					return el.Document.body.scrollHeight;
				}
			}
			catch(e)
			{
				return -1;
			}
		}
	}

	function fcGetElementValue(id, elProperty){
		
		if (id.indexOf('.')!=-1) {
			var newArr = id.split('.');
			var elValue = "";
			
			try {
				el = window;
				for (var i=0;i < newArr.length;i++) {
					el = el[newArr[i]];
				}
				return el;
			}
			catch (e) {
				return -1;
			}
		}
		else {
			try {
				var el = fcGetElement(id);
				var elValue = el[elProperty];
				return elValue;
			}
			catch(e) {
				return -1;
			}
		}
	}
	
	// get HTML content
	function fcGetHTML(id, elementType, editorType) {
		var el = fcGetElement(id);
		if (el!=null) {
			
			if (elementType =="division") {
				return el.innerHTML;
			}
			else if (elementType == "editor") {
				var oEditor;
				
					// add additional editor support here
				if (editorType=="fckeditor") {
					if ( typeof( FCKeditorAPI ) != 'undefined' ) {
						oEditor = FCKeditorAPI.GetInstance( id + "Editor" );
						if ( oEditor )	{
							// Get the current text in the editor.
							return oEditor.GetXHTML();
						}
					}
				}
				else if (editorType=="tinymce") {
					return tinyMCE.getContent(id);
				}
				
				
			}
		}
		return "";
	}
	
	function fcGetIncludes(includes) {
		var len = includes.length;
		//var head = document.getElementsByTagName("head");
		// sometimes this doesn't work. possibly browser issues. in those cases add includes directly to the html page
		for (var i=0;i<len;i++) {
			var el = document.createElement("script");
			//el.onload = onload2;
			el.setAttribute("src",includes[i]);
			el.setAttribute("type","text/javascript");
			document.body.appendChild(el);
		}
	}

	function fcGetMovieById(id) {
		if (navigator.appName.indexOf ("Microsoft") !=-1) {
			return window[id];
		} else {
			return window.document[id];
		}
	}
	
	function fcHide(id, hideOffscreen, offscreenOffset) {
		var el = fcGetElement(id);
		if (hideOffscreen) {
			el.style.width = "0px";
			el.style.height = "0px";
		}
		el.style.visibility = "hidden";
	}
	
	function fcMoveElementTo(el,x,y) {
		el.style.left = parseInt(x) + "px";
		el.style.top = parseInt(y) + "px";
	}
	
	function fcRefresh(id) {
		var el = fcGetElement(id);
		el.style.cssText = el.style.cssText;
	}
	
	function fcRemove(id) {
		//fcHide(id, true);
		var el = fcGetElement(id);
		var elParent = el.parentNode;
		elParent.removeChild(el);
	}
    
    function fcSetDocumentTitle(title) {
        window.document.title = title;
        return 1;
    }
	
	function fcSetHTML(id, htmlText, elementType, editorType) {
		var el = fcGetElement(id);
		if (el!=null) {
		
			if (elementType =="division") {
				el.innerHTML = htmlText;
			}
			else if (elementType == "editor") {
				var oEditor;
				
				// add additional editor support here
				if (editorType == "fckeditor") {
					if ( typeof( FCKeditorAPI ) != 'undefined' ) {
						oEditor = FCKeditorAPI.GetInstance( id + "Editor" );
						if ( oEditor )	{
							// Set the text in the editor.
							oEditor.SetHTML( htmlText ) ;
						}
					}
				}
				else if (editorType=="tinymce") {
					var editor = tinyMCE.getInstanceById(id+"Editor");
					editor.setHTML(htmlText);
				}
			}
		}
	}
	
	function fcSetPosition(id,x,y) {
		var el = fcGetElement(id);

		if (x != undefined) {
			el.style.left = x + "px";
		}

		if (y != undefined) {
			el.style.top = y + "px";
		}
	}
	
	function fcSetScrollPolicy(el, overflow) {
		if (overflow != "resize") {
			el.style.overflow = overflow;
		}
	}
	
	function fcSetScrollPolicyById(id, overflow) {
		var el = fcGetElement(id);
		
		// setting this to anything other than auto in ff fails it
		if (overflow != "resize") {
			el.style.overflow = overflow;
		}
	}
	
	function fcSetSize(el,w,h) {
		// WIDTH
		if (w != undefined) {
			if (String(w).indexOf("%")!=-1) {
				el.style.width = w;
			}
			else {
				el.style.width = parseInt(w) + "px";
			}
		}
		
		if (h!=undefined) {
			if (String(h).indexOf("%")!=-1) {
				el.style.height = h;
			}
			else {
				el.style.height = parseInt(h) + "px"; 
			}
		}
	}
	
	function fcSetSizeByValue(id,w,h) {
		var el = fcGetElement(id);
		if (el.style.visibility=="hidden") { return; }
		
		if (w != undefined) {
			// if width is a percentage pass in the string as is
			if (String(w).indexOf("%")!=-1) {
				el.style.width = w;
			}
			else {
				el.style.width = parseInt(w) + "px";
			}
		}
		
		if (h!=undefined) {
			if (String(h).indexOf("%")!=-1) {
				el.style.height = h;
			}
			else {
				el.style.height = parseInt(h) + "px"; 
			}
		}
	}
	
	function fcSetSource(id,source){
		var el = fcGetElement(id);
		el.src = source;
	}
	
	function fcShow(id, hideOffscreen, left, width, height) {
		var el = fcGetElement(id);
		el.style.visibility = "visible";
		if (hideOffscreen) {
			el.style.width = parseInt(width) + "px";
			el.style.height = parseInt(height) + "px";
		}
	}

	function fcFlexOnload(movieId) {
		// calling callback is unreliable - movie may not be loaded yet
		//movie.onLoadComplete();
		htmlControls.pageLoaded = "true";
	}
