//=============================================================================================
/*

The default easing functions are methods of the Tween.as class.

		Tween.regularEaseIn
		Tween.regularEaseOut
		Tween.regularEaseInOut
		Tween.strongEaseIn
		Tween.strongEaseOut
		Tween.strongEaseInOut
		Tween.backEaseOut
		Tween.backEaseIn
		Tween.backEaseInOut
		Tween.bounceEaseOut
		Tween.bounceEaseIn
		Tween.bounceEaseInOut
		Tween.elasticEaseIn
		Tween.elasticEaseOut
		Tween.elasticEaseInOut
		

*/

//=============================================================================================

function include(filename)
{
	var head = document.getElementsByTagName('head')[0];
	
	script = document.createElement('script');
	script.src = filename;
	script.type = 'text/javascript';
	
	head.appendChild(script)
}

function aniObject()
{
	var	sID;
	var	obj;
}

function actorClass()
{
	var	xNode;
	var	sID;
	var	sHTML;
	var	sStyle;
}


function jScroller()
{
	this.scrollercontent;
	this.scrollerwidth="50px";
	this.scrollerheight="100px";
	this.scrollerspeed=1;
	this.scrollercontent = "";
	this.pauseit=1;
	this.copyspeed=this.scrollerspeed;
	this.actualheight='';
	this.cross_scroller;
	this.pausespeed=(this.pauseit==0)? this.copyspeed: 0;
	this.sName;
	this.sHandler;
	this.nInterval;
	
	this.populate		= populate;
	this.scrollscroller	= scrollscroller;
	this.scrollerHTML	= scrollerHTML;
	this.onMouseOver	= onMouseOver;
	this.onMouseOut		= onMouseOut;
	this.setSpeed		= setSpeed;
	this.start			= start;
	this.stop			= stop;
	this.rewind			= rewind;
	
	function populate()
	{
		var sObj = this.sName + "_scroller";
		this.cross_scroller				= document.getElementById? document.getElementById(sObj) : document.all.iescroller;
		this.cross_scroller.style.top	= parseInt(this.scrollerheight)+8+"px";
		this.cross_scroller.innerHTML	= this.scrollercontent;
		
		if (this.actualheight == null)
			this.actualheight = this.scrollerheight;
	}
	
	function stop()
	{
		if (this.nInterval != null)
		{
			clearInterval(this.nInterval);
			this.nInterval = null;
		}
	}
	
	function rewind()
	{
		this.cross_scroller.style.top	= parseInt(this.scrollerheight)+8+"px";
	}
	
	function start()
	{
		if (this.nInterval == null)
		{
			this.nInterval = setInterval(this.sHandler + ".scrollscroller()",40);		
		}
	}	
	
	function setSpeed(nSpeed)
	{
		this.scrollerspeed = nSpeed;
		this.copyspeed=this.scrollerspeed;
	}
	function scrollscroller()
	{
		if (parseInt(this.cross_scroller.style.top) > (this.actualheight*(-1)+8))
		{
			this.cross_scroller.style.top=parseInt(this.cross_scroller.style.top) - this.copyspeed + "px"			
		}
		else
		{
			this.cross_scroller.style.top = parseInt(this.scrollerheight) + 8 + "px"
		}
	}

	function onMouseOver()
	{
		this.copyspeed=this.pausespeed;
	}
		
	function onMouseOut()
	{
 		this.copyspeed=this.scrollerspeed;
 	}
	
	function scrollerHTML(sName,sHandler)
	{
		var sHTML;
		var sMouseOver=  sHandler + '.onMouseOver();';
		var sMouseOut =  sHandler + '.onMouseOut();';
		
		this.sName = sName;
		this.sHandler = sHandler;
		var sObj = this.sName + "_scroller";
		sHTML = '<div style="position:relative;width:' + this.scrollerwidth + ';height:' + this.scrollerheight+';overflow:hidden" onMouseover="' + sMouseOver+ '" onMouseout="' + sMouseOut + '">';
		sHTML += '<div id="' + sObj + '" style="position:absolute;left:0px;top:0px;width:100%;">';
		sHTML += '</div></div>';
		return sHTML;
	}
}

function jflashClass()
{
	this.objects = new Array();
	this.aCast = new Array();
	this.xmlDoc;
	this.xScenes;
	this.xCast;
	this.xEquipment;
	this.xActs;
	this.xPerformances;
	this.xMovements;
	this.xEvents;
	this.xScript;
	this.xCurrentAct;
	this.xCurrentScene;
	this.xCurrentSet;
	this.xCurrentPerformers;
	this.sStage;
	this.sequence 		= new Sequence();
	this.nActions 		= 0;
	this.bSceneChange 	= false;
	this.bHandlingEvent	= false;
	this.startdelay 	= 500;
	this.sc 			= new jScroller();
	this.stage;
	this.sLastType;
	this.sShow;				

	// Set public methods
	
	this.addObject			= addObject;
	this.removeObject		= removeObject;
	this.findObject			= findObject;
	this.moveTo				= moveTo;
	this.setWidth			= setWidth;
	this.adjustWidth		= adjustWidth;
	this.setOpacity			= setOpacity;
	this.adjustOpacity		= adjustOpacity;
	this.show				= show;
	this.hide				= hide;
	this.setCostume			= setCostume;
	this.setText			= setText;
	this.adjustBorderColor	= adjustBorderColor;
	this.adjustColor		= adjustColor;
	this.adjustBackColor	= adjustBackColor;
	this.adjustDocumentBackColor = adjustDocumentBackColor;
	this.adjustDocumentColor = adjustDocumentColor;
	this.adjustBorderWidth	= adjustBorderWidth;
	this.setBorderColor		= setBorderColor;
	this.setBorderWidth		= setBorderWidth;
	this.rotateImage		= rotateImage;
	this.getActionStyle		= getActionStyle;
	this.ExecuteMovement	= ExecuteMovement;
	this.RunPerformance		= RunPerformance;
	this.ActivateEvent		= ActivateEvent;
	this.addTheSet			= addTheSet;
	this.actorHTML			= actorHTML;
	this.parseXML			= parseXML;
	this.startAct			= startAct;
	this.startShow			= startShow;
	this.curtainsup			= curtainsup;
	this.handleEvents		= handleEvents;
	this.getValue			= getValue;
	this.hasPerformance		= hasPerformance;
	this.SceneChange		= SceneChange;
	this.onActionStart		= onActionStart;
	this.onActionFinish		= onActionFinish;
	this.pieceHTML			= pieceHTML;
	this.OnResize			= OnResize;
	this.createElement		= createElement;
	this.fetchCastMember	= fetchCastMember;
	this.installNewActor	= installNewActor;
	this.addElement			= addElement;
	
	///////////////////////////////////////////////////////////////////////////
	function addObject(sID)
	{
		if (this.findObject(sID) != null)
		{
			return;
		}

		var obj = document.getElementById(sID);
		var newobj = new aniObject();
		var cnt = this.objects.length;
		
		newobj.sID = sID;
		newobj.obj = obj;
	
		this.objects[cnt] = newobj;
		
		return true;
	}
	
	function findObject(sID)
	{
		for (var i = 0;i < this.objects.length;i++)
		{
			if (this.objects[i] != null)
			{
				if (this.objects[i].sID == sID)
				{
					return this.objects[i].obj;
				}
			}
		}
		return null;
	}
	
	function removeObject(sID)
	{
		if (sID = "")
			return;
		if (!this.objects)
			return;
		for (var i = 0;i < this.objects.length;i++)
		{
			if (this.objects[i].sID == sID)
			{
				var obj = this.objects[i];
				
				delete obj;
				this.objects[i] = null;
				return ;
			}
		}
		
	}
	
	function moveTo(sID,x,y,duration,fn,onXFinish,onYFinish)
	{
		obj = this.findObject(sID);
		if (obj)
		{
			if (!duration) duration = 1;
			if (!fn) fn = Tween.regularEaseOut;
			if (!obj.style.top) obj.style.top = 0;
			if (!obj.style.left) obj.style.left = 0;
			
			if (!x)
				x = parseInt(obj.style.left);
			if (!y)
				y = parseInt(obj.style.top);
				
			var twLeft,twTop;

			if (parseInt(obj.style.left) != x)
				twLeft = new Tween(obj.style,'left','',parseInt(obj.style.left),10,1,'px');
			if (parseInt(obj.style.top) != y)
				twTop = new Tween(obj.style,'top','',parseInt(obj.style.top),10,1,'px');

			if (parseInt(obj.style.left) != x)
			{
				if (onXFinish)
					twLeft.onMotionFinished = onXFinish;
				twLeft.func = fn;
				twLeft.continueTo(x,duration);
			}
			if (parseInt(obj.style.top) != y)
			{
				if (onYFinish)
					twTop.onMotionFinished = onYFinish;
				twTop.func = fn;
				twTop.continueTo(y,duration);
			}
		}
	}

	function setWidth(sID,sValue)
	{
		obj = document.getElementById(sID);
		if (obj && sValue)
		{
			sValue = sValue.replace("[STAGEWIDTH]",this.stage.offsetWidth);
			sValue = sValue.replace("[STAGEHEIGHT]",this.stage.offsetHeight);	
			value = eval(sValue);
			obj.style.width = value;
		}
	}

	
	function adjustWidth(sID,w,duration,fn,sw,onFinish)
	{
		obj = this.findObject(sID);
		if (obj)
		{
			if (!duration) duration = 1;
			if (!fn) fn = Tween.regularEaseOut;
			if (!sw) sw = 72;
					
			var twWidth;
			
			twWidth = new Tween(obj.style,'width',fn,sw,10,1,'px');
			if (onFinish)
				twWidth.onMotionFinished = onFinish;
			twWidth.continueTo(w,duration);
		}
	}
	
	function adjustHeight(sID,h,duration,fn,sw,onFinish)
	{
		obj = this.findObject(sID);
		if (obj)
		{
			if (!duration) duration = 1;
			if (!fn) fn = Tween.regularEaseOut;
			if (!sh) sh = 72;
			
			var twHeight;
			
			twHeight = new Tween(obj.style,'height',fn,sh,10,1,'px');
			if (onFinish)
				twHeight.onMotionFinished = onFinish;
			twHeight.continueTo(h,duration);
		}
	}
	
	function adjustSize(sID,w,h,duration,fn,sw,sh,onFinish)
	{
		obj = this.findObject(sID);
		if (obj)
		{
			if (!duration) duration = 1;
			if (!fn) fn = Tween.regularEaseOut;
			if (!sh) sh = 72;
			if (!sw) sw = 72;
			
			var twHeight,twWidth;
			
			twWidth = new Tween(obj.style,'width',fn,sw,10,1,'px');
			twWidth.continueTo(w,duration);
			twHeight = new Tween(obj.style,'height',fn,sh,10,1,'px');
			twHeight.continueTo(h,duration);
			if (onFinish)
				twHeight.onMotionFinished = onFinish;
		}
	}
	
	function setOpacity(sID,value)
	{
		obj = this.findObject(sID);
		if (obj)
		{
			if (value < 1) value *= 100;
			obj.style['opacity'] = value / 100;
			obj.style['-moz-opacity'] = value / 100;
			if(obj.filters) obj.filters.alpha['opacity'] = value;
		}		
	}
	
	function adjustOpacity(sID,sop,eop,duration,fn,onFinish)
	{
		obj = this.findObject(sID);
		if (obj)
		{
			var twOpacity;

			if (!duration) duration = 1;
			if (!fn) fn = Tween.regularEaseIn;
			if (sop < 1) sop *= 100;
			if (eop < 1) eop *= 100;
			
			twOpacity = new OpacityTween(obj,fn,sop,eop,duration);
			if (onFinish)
				twOpacity.onMotionFinished = onFinish;
			twOpacity.start();
			
		}		
	}

	function adjustColor(sID,sColor,eColor,duration,fn,onFinish)
	{
		obj = this.findObject(sID);
		if (obj)
		{
			var twColor;

			if (!duration) duration = 1;
			if (!fn) fn = Tween.regularEaseIn;
			
			twColor = new ColorTween(obj.style,"color",fn,sColor,eColor,duration);
			if (onFinish)
				twColor.onMotionFinished = onFinish;
			twColor.start();			
		}		
	}

	function adjustBackColor(sID,sColor,eColor,duration,fn,onFinish)
	{
		obj = this.findObject(sID);
		if (obj)
		{
			var twColor;

			if (!duration) duration = 1;
			if (!fn) fn = Tween.regularEaseIn;
			
			twColor = new ColorTween(obj.style,"backgroundColor",fn,sColor,eColor,duration);
			if (onFinish)
				twColor.onMotionFinished = onFinish;
			twColor.start();		
		}		
	}

	function adjustDocumentColor(sColor,eColor,duration,fn,onFinish)
	{
		obj = this.stage;
		if (obj)
		{
			var twColor;

			if (!duration) duration = 1;
			if (!fn) fn = Tween.regularEaseIn;
			
			twColor = new ColorTween(obj.style,"color",fn,sColor,eColor,duration);
			if (onFinish)
				twColor.onMotionFinished = onFinish;
			twColor.start();			
		}		
	}

	function adjustDocumentBackColor(sColor,eColor,duration,fn,onFinish)
	{
		obj = this.stage;
		if (obj)
		{
			var twColor;

			if (!duration) duration = 1;
			if (!fn) fn = Tween.regularEaseIn;
			
			twColor = new ColorTween(obj.style,"backgroundColor",fn,sColor,eColor,duration);
			if (onFinish)
				twColor.onMotionFinished = onFinish;
			twColor.start();			
		}		
	}
	
	function show(sID)
	{
		obj = this.findObject(sID);
		if (obj)
		{
			obj.style.display = "block";
		}
	}
	
	function hide(sID)
	{
		obj = this.findObject(sID);
		if (obj)
		{
			obj.style.display = "none";
		}
	}
	
	function setCostume(sID,sHTML)
	{
		obj = this.findObject(sID);
		if (obj && sHTML)
		{
			obj.innerHTML = sHTML;
		}
	}

	function setText(sID,sText,duration,fn,onFinish)
	{
		obj = this.findObject(sID);
		if (obj && sText)
		{
			var twText;

			if (!duration) duration = 1;
			if (!fn) fn = Tween.regularEaseIn;
			
			twText = new TextTween(obj,"value",sText,fn,duration);
			if (onFinish)
				twText.onMotionFinished = onFinish;
			twText.start();
		}
	}

	function setBorderColor(sID,sColor)
	{
		obj = this.findObject(sID);
		if (obj && sColor)
		{
			obj.style.borderColor = sColor;
		}
	}

	function setBorderWidth(sID,w)
	{
		obj = this.findObject(sID);
		if (obj && w)
		{
			obj.style.borderWidth = w;
		}
	}

	function adjustBorderColor(sID,sColor,eColor,duration,fn,onFinish)
	{
		obj = this.findObject(sID);
		if (obj && sColor && eColor)
		{
			var twColor;

			if (!duration) duration = 1;
			if (!fn) fn = Tween.regularEaseIn;
			
			twColor = new ColorTween(obj.style,"borderColor",fn,sColor,eColor,duration);
			if (onFinish)
				twColor.onMotionFinished = onFinish;
			twColor.start();
		}
	}

	function adjustBorderWidth(sID,w,duration,fn,onFinish)
	{
		obj = this.findObject(sID);
		if (obj && w)
		{
			var twBorder;

			if (!duration) duration = 1;
			if (!fn) fn = Tween.regularEaseIn;
			
			sw = parseInt(obj.style.borderWidth);
			twBorder = new Tween(obj.style,'borderWidth',fn,sw,w,1,'px');
			if (onFinish)
				twBorder.onMotionFinished = onFinish;
			twBorder.start();
		}
	}
	
	function rotateImage(sImage,p_deg) 
	{
		if (!sImage) return;
		image = this.findObject(sImage);
		if (!image)
			return;
		
		if(document.getElementById('canvas')) 
		{
			/*
			Ok!: Firefox 2, Safari 3, Opera 9.5b2
			No: Opera 9.27
			*/
			var image = document.getElementById('image');
			var canvas = document.getElementById('canvas');
			var canvasContext = canvas.getContext('2d');
			
			switch(p_deg) {
				default :
				case 0 :
					canvas.setAttribute('width', image.width);
					canvas.setAttribute('height', image.height);
					canvasContext.rotate(p_deg * Math.PI / 180);
					canvasContext.drawImage(image, 0, 0);
					break;
				case 90 :
					canvas.setAttribute('width', image.height);
					canvas.setAttribute('height', image.width);
					canvasContext.rotate(p_deg * Math.PI / 180);
					canvasContext.drawImage(image, 0, -image.height);
					break;
				case 180 :
					canvas.setAttribute('width', image.width);
					canvas.setAttribute('height', image.height);
					canvasContext.rotate(p_deg * Math.PI / 180);
					canvasContext.drawImage(image, -image.width, -image.height);
					break;
				case 270 :
				case -90 :
					canvas.setAttribute('width', image.height);
					canvas.setAttribute('height', image.width);
					canvasContext.rotate(p_deg * Math.PI / 180);
					canvasContext.drawImage(image, -image.width, 0);
					break;
			};
			
		} else 
		{
			/*
			Ok!: MSIE 6 and 7
			*/
			switch(p_deg) {
				default :
				case 0 :
					image.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(rotation=0)';
					break;
				case 90 :
					image.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(rotation=1)';
					break;
				case 180 :
					image.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(rotation=2)';
					break;
				case 270 :
				case -90 :
					image.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(rotation=3)';
					break;
			};
			
		};
	};

	function fetchCastMember(sCastMember)
	{
		try //Internet Explorer
	  	{
	  		xCastMember = new ActiveXObject("Microsoft.XMLDOM");
	  	}
		catch(e)
	  	{
	  		try //Firefox, Mozilla, Opera, etc.
	    	{
	    		xCastMember = document.implementation.createDocument("","",null);
	    	}
	  		catch(e)
   			{
	    		alert(e.message);
	    		return null;
	    	}
	  	}
		xCastMember.async=false;
		if (xCastMember.load(sCastMember))
			return xCastMember;

		var myErr = xCastMember.parseError;
		alert("You have error " + myErr.reason);
		return null;
	}

	function parseXML()
	{
		try //Internet Explorer
	  	{
	  		this.xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	  	}
		catch(e)
	  	{
	  		try //Firefox, Mozilla, Opera, etc.
	    	{
	    		this.xmlDoc=document.implementation.createDocument("","",null);
	    	}
	  		catch(e)
   			{
	    		alert(e.message);
	    		return false;
	    	}
	  	}
		this.xmlDoc.async=false;
		if (this.xmlDoc.load(this.sShow))
			return true;

		var myErr = this.xmlDoc.parseError;
		alert("You have error " + myErr.reason);
		return false;
	}
	
	function getActionStyle(sStyle)
	{
		switch(sStyle)
		{
			case "quickEaseIn":
				return Tween.quickEaseIn;
				break;
			case "strongEaseIn":
				return Tween.strongEaseIn;
				break;
			case "strongEaseOut":
				return Tween.strongEaseOut;
				break;
			case "strongEaseInOut":
				return Tween.strongEaseInOut;
				break;
			case "elasticEaseIn":
				return Tween.elasticEaseIn;
				break;
			case "elasticEaseOut":
				return Tween.elasticEaseOut;
				break;
			case "backEaseIn":
				return Tween.backEaseIn;
				break;
			case "backEaseOut":
				return Tween.backEaseOut;
				break;
			case "backEaseInOut":
				return Tween.backEaseInOut;
				break;
			case "elasticEaseInOut":
				return Tween.elasticEaseInOut;
				break;
			case "bounceEaseOut":
				return Tween.bounceEaseOut;
				break;
			case "bounceEaseIn":
				return Tween.bounceEaseIn;
				break;
			case "bounceEaseInOut":
				return Tween.bounceEaseInOut;
				break;
			case "regularEaseIn":
				return Tween.regularEaseIn;
				break;
			case "regularEaseOut":
				return Tween.regularEaseOut;
				break;
			case "regularEaseInOut":
				return Tween.regularEaseInOut;
				break;
		}
		return Tween.regularEaseIn;		
	}
	
	function getValue(sValue,nDefault,pos)
	{
		if (!nDefault)
			nDefault = 0;
		if (sValue == null)
			return nDefault;
			
		if (sValue.indexOf('[') == -1)
		{
			var value =  parseInt(sValue);

			if (!isIE())
			{
				if (this.sStage != "document.body" && pos == "L" && value >= 0)
				{
					value += parseInt(this.stage.offsetLeft);
				}			
				if (this.sStage != "document.body" && pos == "T" && value >= 0)
				{

					value += parseInt(this.stage.offsetTop);
				}
			}
			return value;
		}
		if (!isIE())
		{
			sValue = sValue.replace("[STAGEWIDTH]",this.stage.offsetWidth);
			sValue = sValue.replace("[STAGEHEIGHT]",this.stage.offsetHeight);	
			value = eval(sValue);
		}
		else
		{
			sValue = sValue.replace("[STAGEWIDTH]",this.stage.clientWidth);
			sValue = sValue.replace("[STAGEHEIGHT]",this.stage.clientHeight);	
			value = eval(sValue);
		}
		if (!isIE())
		{
			if (this.sStage != "document.body" && pos == "L")
			{
				value += parseInt(this.stage.offsetLeft);
			}			
			if (this.sStage != "document.body" && pos == "T")
			{
				value += parseInt(this.stage.offsetTop);
			}			
		}
		return value;
	}
	
	function addElement(sHTML)
	{
		if(isIE())
		{
			el = document.createElement(sHTML);
				
			jflash.stage.appendChild(el);			
		}
		else
		{
			var range = document.createRange();
			range.selectNode(document.body);
			el = range.createContextualFragment(sHTML);
			jflash.stage.appendChild(el);			
		}	
	}

	function ExecuteMovement(sMovement)
	{
		if (this.xPerformances == null)
		{
			alert("Scene Performances No Defined");
			return;
		}
		var sChoreography;
		
		for (var i = 0;i < this.xPerformances.childNodes.length;i++)
		{
			xMovement =  getChildNode(this.xPerformances,i);
			if (xMovement == null)
				break;
			sName = xMovement.getAttribute('name');	
			if (sName == sMovement)
			{
				sChoreography = xMovement.getAttribute('choreography');	
				if (!sChoreography)
					sChoreography = ""; 
				if (sChoreography == "")
					sChoreography = "parallel";
				
				var	actions = new Array();
				
				for (var a = 0;a < xMovement.childNodes.length;a++)
				{
					xAction = getChildNode(xMovement,a);
					if (xAction == null)
						break;
					sActor = xAction.getAttribute('actor');	
					sRoll = xAction.getAttribute('effect');	
					sStyle = xAction.getAttribute('actionstyle');	
					
					if (sActor == null || sActor == "")
					{
						switch(sRoll)
						{
							case "startscrolling":
								var twTask = new TaskTween(this,"startscrolling","",1);
								actions[actions.length] = twTask;										
								break;
							case "stopscrolling":
								var twTask = new TaskTween(this,"stopscrolling","",1);
								actions[actions.length] = twTask;										
								break;
							case "execute":
								if (xAction.getAttribute('script'))
								{
									var twTask = new TaskTween(this,"execute",xAction.getAttribute('script'),1);
									actions[actions.length] = twTask;
								}
								else
									alert("Action Execute Needs Script Property");										
								break;
							case "openwindow":
								if (xAction.getAttribute('url'))
								{
									var sUrl = xAction.getAttribute('url');
									var sWindowName;
									var sProperties;
									
									if (xAction.getAttribute('windowname'))
										sWindowName = xAction.getAttribute('windowname');
									if (xAction.getAttribute('properties'))
										sProperties = xAction.getAttribute('properties');
									window.open(sUrl,sWindowName,sProperties);
								}
								else
									alert("Action OpenWindow Needs URL Property");										
								break;
							case "showdialog":
								if (xAction.getAttribute('type'))
								{
									var sType = xAction.getAttribute('type');
									var sTitle = "Message";
									var sHTML = "";
									
									if (xAction.getAttribute('title'))
										sTitle = xAction.getAttribute('title');
									
								 	var xHTML = getChildNode(xAction,0);
								 	if (xHTML)
								 	{
										sHTML = getNodeXML(xHTML);
										sHTML = sHTML.replace("<costume>","");
										sHTML = sHTML.replace("</costume>","");		 		
								 	}
									showDialog(sTitle,sHTML,sType);
								}
								else
									alert("Action Dialog Needs Type Property");										
								break;
							case "hidedialog":
								hideDialog();
								break;
						};
					}
					else
					{
						obj = this.findObject(sActor);
						if (obj)
						{
							nDuration = 1;
							if (xAction.getAttribute('duration'))
								nDuration = parseInt(xAction.getAttribute('duration'));
							if (!isIE())
							{
								nStartX = this.getValue(obj.style.left,0);
								nStartY = this.getValue(obj.style.top,0);	
							}
							else
							{
								nStartX = this.getValue(obj.style.left,0,"L");
								nStartY = this.getValue(obj.style.top,0,"T");					
							}
							nStartW = this.getValue(obj.style.width);
							nStartH = this.getValue(obj.style.height);
							switch(sRoll)
							{
								case "moveto":
									nX = this.getValue(xAction.getAttribute('left'),nStartX,"L");
									nY = this.getValue(xAction.getAttribute('top'),nStartY,"T");
									
									var twMove = new MoveTween(obj,'',nStartX,nStartY,nX,nY,nDuration);
									twMove.func = this.getActionStyle(sStyle);
									twMove.onMotionStarted = this.onActionStart;
									twMove.onMotionFinished = this.onActionFinish;
									
									actions[actions.length] = twMove;								
									break;
								case "stretch":
									nFrom = this.getValue(xAction.getAttribute('from'),0);
									nTo = this.getValue(xAction.getAttribute('to'),100);
									
									var twStretch = new StretchTween(obj,'',nFrom,nTo,nDuration);
									twStretch.func = this.getActionStyle(sStyle);
									twStretch.onMotionStarted = this.onActionStart;
									twStretch.onMotionFinished = this.onActionFinish;
									
									actions[actions.length] = twStretch;								
									break;
								case "contract":
									nFrom = this.getValue(xAction.getAttribute('from'),0);
									nTo = this.getValue(xAction.getAttribute('to'),100);
									
									var twContract = new ContractTween(obj,'',nFrom,nTo,nDuration);
									twContract.func = this.getActionStyle(sStyle);
									twContract.onMotionStarted = this.onActionStart;
									twContract.onMotionFinished = this.onActionFinish;
									
									actions[actions.length] = twContract;								
									break;
								case "expand":
									nFrom = this.getValue(xAction.getAttribute('from'),0);
									nTo = getValue(xAction.getAttribute('to'),100);
									
									var twExpand = new ExpandTween(obj,'',nFrom,nTo,nDuration,'px');
									twExpand.func = this.getActionStyle(sStyle);
									twExpand.onMotionStarted = this.onActionStart;
									twExpand.onMotionFinished = this.onActionFinish;
									
									actions[actions.length] = twExpand;								
									break;
								case "fadein":
									var twOpacity = new OpacityTween(obj,'',0,100,nDuration);
									twOpacity.func = this.getActionStyle(sStyle);
									twOpacity.onMotionStarted = this.onActionStart;
									twOpacity.onMotionFinished = this.onActionFinish;
									actions[actions.length] = twOpacity;
									break;
								case "fadeto":
									nFrom = this.getValue(xAction.getAttribute('from'),0);
									nTo = this.getValue(xAction.getAttribute('to'),100);
									var twOpacity = new OpacityTween(obj,'',nFrom,nTo,nDuration);
									twOpacity.func = this.getActionStyle(sStyle);
									twOpacity.onMotionStarted = this.onActionStart;
									twOpacity.onMotionFinished = this.onActionFinish;
									actions[actions.length] = twOpacity;
									break;
								case "fadeout":								
									var twOpacity = new OpacityTween(obj,'',100,0,nDuration);
									twOpacity.func = this.getActionStyle(sStyle);
									twOpacity.onMotionStarted = this.onActionStart;
									twOpacity.onMotionFinished = this.onActionFinish;
									actions[actions.length] = twOpacity;
									break;
								case "show":
									var twTask = new TaskTween(obj,"show","",nDuration);
									actions[actions.length] = twTask;										
									break;
								case "hide":
									var twTask = new TaskTween(obj,"hide","",nDuration);
									actions[actions.length] = twTask;										
									break;
								case "setorder":
									if (xAction.getAttribute('order'))
									{
										var twTask = new TaskTween(obj,"setorder",xAction.getAttribute('order'),nDuration);
										actions[actions.length] = twTask;										
									}
									break;
							}
						}
						else
							alert("Actor " + sActor + " Not Found");
					}
				}
				
				if (xMovement.getAttribute("onstart"))
				{
					if (xMovement.getAttribute("onstart") != "")
						eval(xMovement.getAttribute("onstart"));
				}
				var seq =  new Sequence();
				for (var i = 0;i < actions.length;i++)
				{
					if (sChoreography == "parallel")
					{
						actions[i].start();
					}					
					if (sChoreography == "sequence")
					{
						seq.addChild(actions[i]);
					}					
				}
				if (sChoreography == "sequence")
				{
					seq.start();
				}
				return;
			}
		}		
	}
	
	function findNodeTag(xNode, sTagName)
	{
		for(var i = 0;i < xNode.childNodes.length;i++)
		{
			var xChild = getChildNode(xNode,i);
			
			if (xChild == null)
				break;
			if (xChild.nodeName == sTagName)
			{
				return xChild;				
			}
		}
		return null;		
	}
	
	function SceneChange(sNextName)
	{
		// find scene
		var	xScene,xSet;

		this.sc.stop();
		hideDialog();
		if(this.nActions != 0)
		{
			setTimeout("jflash.SceneChange('" + sNextName + "')",100);
			return;
		}
		
		for(var i = 0;i < this.xScenes.childNodes.length;i++)
		{
			var xNode = getChildNode(this.xScenes,i);
			var sName = xNode.getAttribute('name');
			if (sName == sNextName)
			{
				xScene = xNode;
				break;
			}
		}
		if (xScene == null)
		{
			alert("Scene name " + sNextName + " Not Found");
			return;
		}
		this.bSceneChange = true;
		
		if (this.xCurrentScene)
		{
			var sCloseFunc = this.xCurrentScene.getAttribute('onclose');		
			if (sCloseFunc && sCloseFunc != "")
			{
				if (sCloseFunc.indexOf('(') == -1)
					sCloseFunc += "()"
				if (sCloseFunc.indexOf(';') == -1)
					sCloseFunc += ";"
				eval(sCloseFunc);
			}
		}
		
		this.xEvents = findNodeTag(xScene,"events");
		//Adjust the set
	
		xSet = findNodeTag(xScene,"set");
		if (xSet == null)
		{
			for (var i = 0;i < this.xCurrentSet.childNodes.length;i++)
			{
				var xNode = getChildNode(this.xCurrentSet,i);
				var sID = xNode.getAttribute('name');
				var obj = document.getElementById(sID);
				
				if (obj)
				{
					obj.style.display = 'none';
				}
			}			
		}
		else if (this.xCurrentSet)
		{
			// Remove all items in the current set that are not in the new set
			for (var i = 0;i < this.xCurrentSet.childNodes.length;i++)
			{
				var xPiece = getChildNode(this.xCurrentSet,i);
				var obj,bFound = false;

				if (xPiece == null)
					break;
				var sID = xPiece.getAttribute('name');
				for (var n = 0;n < xSet.childNodes.length;n++)
				{
					var xNode = getChildNode(xSet,n);
				
					if (xNode == null)
						break;
					if (sID == xNode.getAttribute('name'))
					{
						bFound = true;
						break;
					}
				}
				if (!bFound)
				{
					obj = document.getElementById(sID);
					if (obj)
					{
						obj.style.display = 'none';
					}
				}			
			}			
		}
		xPerformers = findNodeTag(xScene,"performers");
		if (!xPerformers)
		{
			if (this.xCurrentPerformers)
			{
				for (var i = 0;i < this.xCurrentPerformers.childNodes.length;i++)
				{
					var xNode =  getChildNode(this.xCurrentPerformers,i);
					var sID = xNode.getAttribute('name');
					var obj = document.getElementById(sID);
					
					if (obj)
					{
						obj.style.display = 'none';
					}
				}			
			}
		}
		else if (this.xCurrentPerformers)
		{
			// Remove all actors not in the current scene
			for (var i = 0;i < this.xCurrentPerformers.childNodes.length;i++)
			{
				var xActor = getChildNode(this.xCurrentPerformers,i);
				var obj,bFound = false;

				if (xActor == null)
					break;
				var sID = xActor.getAttribute('name');
				for (var n = 0;n < xPerformers.childNodes.length;n++)
				{
					var xNode = getChildNode(xPerformers,n);
				
					if (xNode == null)
						break;
					if (sID == xNode.getAttribute('name'))
					{
						bFound = true;
						break;
					}
				}
				if (!bFound)
				{
					obj = document.getElementById(sID);
					if (obj)
					{
						obj.style.display = 'none';
					}
				}			
			}						
		}
		// Add the new set parts
		
		if (xSet)
		{
			for (var i = 0;i < xSet.childNodes.length;i++)
			{
				var xPiece = getChildNode(xSet,i);
				var bFound = false;

				if (xPiece == null)
						break;
				var sID = xPiece.getAttribute('name');
				if (this.xCurrentSet)
				{
					for (var n = 0;n < this.xCurrentSet.childNodes.length;n++)
					{
						var xNode = getChildNode(this.xCurrentSet,n);
					
						if (xNode == null)
							alert("Failed");
						if (sID == xNode.getAttribute('name'))
						{
							bFound = true;
							break;
						}
					}
				}
				if (!bFound) //Need to add the new piece
				{
					var sHTML;
					
					for (var e = 0;e < this.xEquipment.childNodes.length;e++)
					{
						xPiece = getChildNode(this.xEquipment,e);
						if (xPiece == null)
							break;
						if (sID == xPiece.getAttribute('name'))
						{
							var el;
							
							var obj = document.getElementById(sID);
							
							if (obj)
							{
								obj.style.display='block';	
							}
							else
							{								
								sHTML = this.pieceHTML(xPiece,sID);
								
								this.addElement(sHTML);
	
								obj = document.getElementById(sID);
								if (!obj)
									alert("Failed To Append Part of Set " + sID)
								if (isIE())
								{
									var p1 = sHTML.indexOf('>');
									var p2 = sHTML.lastIndexOf('<');
									var innerHTML = sHTML.substr(p1+1,p2-(p1+1));
									
									if (innerHTML != "" && innerHTML != null)
										obj.innerHTML = innerHTML;
								}
							}
							break;
						}
					}
				}
			}			
			this.xCurrentSet = xSet;
		}
		// Add the new actors
	
		if (xPerformers)
		{
			for (var i = 0;i < xPerformers.childNodes.length;i++)
			{
				var xActor = getChildNode(xPerformers,i);
				var bFound = false;

				if (xActor == null)
					break;
				var sName = xActor.getAttribute('name');
				if (this.xCurrentPerformers)
				{
					for (var n = 0;n < this.xCurrentPerformers.childNodes.length;n++)
					{
						var xNode = getChildNode(this.xCurrentPerformers,n);
					
						if (xNode == null)
							break;
						if (sName == xNode.getAttribute('name'))
						{
							bFound = true;
							break;
						}
					}
				}
				var obj = document.getElementById(sName);
				if (!bFound && !obj) //Need to add the new actor
				{
					var sHTML;
					
					for (var c = 0;c < this.xCast.childNodes.length;c++)
					{
						var xCastMember = getChildNode(this.xCast,c);
						if (xCastMember == null)
							break;
						if (sName== xCastMember.getAttribute('name'))
						{
							sHTML = this.actorHTML(xCastMember,xActor);
							if (sHTML)
							{
								var startX = parseInt(xActor.getAttribute('left'));
								var startY = parseInt(xActor.getAttribute('top'));
								
								this.addElement(sHTML);
								var obj = document.getElementById(sName);
								if (!obj)
									alert("Failed To Append Actor to Scene " + sName);
								else
								{
									if (startX)
										obj.style.left = startX;
									if (startY)
										obj.style.top = startY;
									this.addObject(sName);	
									if (isIE())
									{
										var p1 = sHTML.indexOf('>');
										var p2 = sHTML.lastIndexOf('<');
										var innerHTML = sHTML.substr(p1+1,p2-(p1+1));
										
										if (innerHTML != "" && innerHTML != null)
											obj.innerHTML = innerHTML;
									}
									if (this.sLastType == "scrollpanel")
									{
										var p1 = sHTML.indexOf('>');
										var p2 = sHTML.lastIndexOf('<');
										var innerHTML = sHTML.substr(p1+1,p2-(p1+1));
										
										this.sc.scrollerHTML = innerHTML;										
										this.sc.populate();											
									}
									if (xActor.getAttribute('tooltip'))
									{
										obj.alt = xActor.getAttribute('tooltip');
									}	
									sOnInit = xCastMember.getAttribute('oninit');
									if (sOnInit)
									{
										eval(sOnInit);
									}	
								}
							}
							break;
						}
					}
				}
				else if (obj)
				{
					sDisplay =  xActor.getAttribute('display');
					if (sDisplay == null)
						sDisplay = "";
					
					if (sDisplay == "N")
						obj.style.display = 'none';
					else
						obj.style.display = 'block';

					sOpacity =  xActor.getAttribute('opacity');
					if (sOpacity == null)
						sOpacity = "";
					if (sOpacity != "")
					{
						this.setOpacity(sName,sOpacity);
					}
					
					var xHTML = getChildNode(xActor,0);
					
					if (xHTML)
					{
						var sInnerHTML =  getNodeXML(xHTML);
			
						sInnerHTML = sInnerHTML.replace("<costume>","");
						sInnerHTML = sInnerHTML.replace("</costume>","");
						
						obj.innerHTML = sInnerHTML;
					}
				}
			}			
			this.xCurrentPerformers = xPerformers;
		}		
		this.xCurrentScene = xScene;
		var sScene = xScene.getAttribute('name');
		this.startdelay = xScene.getAttribute('startdelay');
		if (!this.startdelay)
			this.startdelay = 500;


		var sOpenFunc = xScene.getAttribute('onopen');		
		if (sOpenFunc && sOpenFunc != "")
		{
			if (sOpenFunc.indexOf('(') == -1)
				sOpenFunc += "()"
			if (sOpenFunc.indexOf(';') == -1)
				sOpenFunc += ";"
			eval(sOpenFunc);
		}

		eval("onInit('" + sScene + "');");
		setTimeout("jflash.ActivateEvent('openning','scene')",this.startdelay);
		this.bSceneChange = false;
	}
	
	function RunPerformance(xPerformance)
	{
		if (xPerformance == null)
		{
			alert("Scene Performance Not Defined");
			return;
		}
		if (xPerformance.childNodes.length == 0)
		{
			alert("Scene Performance Has No Movements");
			return;
		}
		for (var i = 0;i < xPerformance.childNodes.length;i++)
		{
			xNode =  getChildNode(xPerformance,i);
			if (xNode == null)
				break;
			if (xNode.nodeName == "movement")
			{
				sName = xNode.getAttribute('name');	
				this.ExecuteMovement(sName);		
			}
			else if (xNode.nodeName == "offstage")
			{
				sFunc = xNode.getAttribute('execute');	
				if (sFunc)
				{
					if (sFunc.indexOf('(') == -1)
				 		sFunc += "();";
					eval(sFunc);		
				}
			}
			else if (xNode.nodeName == "onstage")
			{
				sAction = xNode.getAttribute('action');	
				if (sAction)
				{
					sAction = sAction.toLowerCase();
					switch(sAction)
					{
						case "changescene":
							var sName = xNode.getAttribute('scene');
							var sDelay = xNode.getAttribute('delay');
							
							if (sDelay == null)
								sDelay = "0";
								
							setTimeout("jflash.SceneChange('" + sName + "')",parseInt(sDelay));
							break;
					}
				}
			}
		}		
	}
	
	function ActivateEvent(sEvent,sPart)
	{
		// walk the events for the openning performance
		
		if (this.xEvents == null)
		{
			alert("Scene Events Not Defined");
			return;
		}
		for (var i = 0;i < this.xEvents.childNodes.length;i++)
		{
			xPerformance =  getChildNode(this.xEvents,i);
			
			if (xPerformance == null)
				return;
			sEvt = xPerformance.getAttribute('event');
			sFor = xPerformance.getAttribute('for');
			if (sEvent == sEvt && sPart == sFor)
			{
				this.RunPerformance(xPerformance);
				return;
			}
		}		
	}
	
	function createElement(sHTML)
	{
		var el;
		
		if (isIE())
		{
			el = document.createElement(sHTML);			
		}
		else
		{
			var range = document.createRange();
			range.selectNode(this.stage);
			el = range.createContextualFragment(sHTML);
		}
		return el;
	}
	
	function isIE()
	{
		var ua = window.navigator.userAgent;
	    var msie = ua.indexOf ( "MSIE " )
		
		if (msie > 0)
			return true;
		return false;
	}
	
	function getChildNode(xParent,iChild)
	{
		if (xParent == null)
			return null
		if (xParent.childNodes == null)
			return null
		if (isIE())
		{
			return xParent.childNodes[iChild];
		}
		for (var i = 0;i < xParent.childNodes.length;i++)
		{
			var	xNode = xParent.childNodes[i];
			
			if (xNode.nodeName.substr(0,1) != '#')
			{
				if (iChild == 0)
					return xNode;
				iChild--;
			}
		}
		return null;
	}

	function getNodeXML(xNode)
	{
		if (xNode == null)
			return "";
		sXML = xNode.xml;
		if (sXML == null)
		{
			try
			{
				var serializer = new XMLSerializer();
				sXML = serializer.serializeToString(xNode);
				delete serializer;	
			}
			catch(e)
			{
				sXML = "";
			}
		}
		return sXML;		
	}
	
	function pieceHTML(xPiece,sName)
	{
		var sHTML = "";
		

		sType = "";
		if (xPiece.getAttribute('type')  == "panel")
			sType = "div";			
		if (xPiece.getAttribute('type')  == "image")
			sType = "image";
		
		if (sType != "")
		{
			sOrder = "0";
		 
		 	sType = sType.toLowerCase();
		 	xHTML = getChildNode(xPiece,0);
		 	if (xHTML)
		 	{
				sInnerHTML = getNodeXML(xHTML);
				sInnerHTML = sInnerHTML.replace("<content>","");
				sInnerHTML = sInnerHTML.replace("</content>","");		 		
		 	}
			
			sClass = xPiece.getAttribute('class');
			sStyle = xPiece.getAttribute('style');
			if (sStyle)
				sStyle = "position:absolute;" + sStyle + ";";
			else
				sStyle = "position:absolute;";
			
			sSrc = xPiece.getAttribute('src');
			
			sStyle += "left:" + this.getValue(xPiece.getAttribute('left'),0,"L") + ";";
			sStyle += "top:" + this.getValue(xPiece.getAttribute('top'),0,"T")  + ";";
			sStyle += "width:" + this.getValue(xPiece.getAttribute('width')) + ";";
			sStyle += "height:" + this.getValue(xPiece.getAttribute('height')) + ";";
			sStyle += "z-index:" + sOrder + ";";
			
			if (sType == "image")
			{
				sPiece =  "<" + sType + " id='" + sName + "' src='" + sSrc + "' class='" + sClass + "' style='" + sStyle + "'/>";
				
			}
			else
			{
				sPiece =  "<" + sType + " id='" + sName + "' class='" + sClass + "' style='" + sStyle + "'>";
				sPiece += sInnerHTML;
				sPiece += "</" + sType+ ">";
			}
			sHTML += sPiece;					
		}
		return sHTML;	
	}
	
	function addTheSet(xSet)
	{
		var 	sHTML;
		
		sHTML = "";
		for (var s = 0;s < xSet.childNodes.length;s++)
		{
			xPiece =  getChildNode(xSet,s);
			sName = xPiece.getAttribute('name');
			for (var i = 0;i < this.xEquipment.childNodes.length;i++)
			{
				xPiece = getChildNode(this.xEquipment,i);
				if (sName == xPiece.getAttribute('name'))
				{
					sHTML += this.pieceHTML(xPiece,sName);
					break;
				}
			}
		}
		return sHTML;
	}
	
	function hasPerformance(sEvent,sPart)
	{
	
		if (this.xEvents == null)
		{
			alert("Scene Events No Defined");
			return;
		}
		for (var i = 0;i < this.xEvents.childNodes.length;i++)
		{
			xPerformance =  getChildNode(this.xEvents,i);
			
			if (xPerformance == null)
				break;
			var sEvt = xPerformance.getAttribute('event');
			var sFor = xPerformance.getAttribute('for');
			if (sEvent == sEvt && sPart == sFor)
			{
				return true;
			}
		}		
		return false;	
	}
	
	function installNewActor(xActor,sID)
	{
		for (var i = 0;i < xActor.childNodes.length;i++)
		{
			var xNode =  getChildNode(xActor,i);
			
			if (xNode == null)
				break;
			if (xNode.nodeName == "style")
			{
				var sStyle;
				
				sText = getNodeXML(xNode);
				sText = sText.replace("<style>","");
				sText = sText.replace("</style>","");
				
				if (isIE())
				{
					document.styleSheets[0].addRule("#"+sID, sText);
				}
				else
				{
					sText = "#" + sID + "{" + sText + "}";
					document.styleSheets[0].insertRule(sText,0);					
				}
			}
		}
	}
	
	function addScript(sScript)
	{
		var headID = document.getElementsByTagName("head")[0];
		var newScript = document.createElement('script');
		
		newScript.type = 'text/javascript';
		newScript.text = sScript;
		headID.appendChild(newScript);
	}
	function actorHTML(xCastMember,xActor)
	{
		var sHTML = "";

		if (xCastMember.getAttribute('ref'))
		{
			var xCM = this.fetchCastMember(xCastMember.getAttribute('ref'));	
			
			if (xCM == null)
			{
				alert("Failed To Fetch Cast Member");				
				return "";
			}
			xCastMember = xCM.documentElement;
			this.installNewActor(xCastMember,xActor.getAttribute('name'));
		}
		xScript = findNodeTag(xCastMember,"script");
		if (xScript)
		{
			var sScript =  getNodeXML(xScript);

			sScript = sScript.replace("<script>","");
			sScript = sScript.replace("</script>","");
			addScript(sScript);
		}
		sEvents = "onclick=\"jflash.handleEvents(this,'onmouseclick');\" ";
		sEvents += "onmouseover=\"jflash.handleEvents(this,'onmouseover');\" ";
		sEvents += "onmouseout=\"jflash.handleEvents(this,'onmouseout');\" ";
		sOpacity		=  xActor.getAttribute('opacity');
		sType 			=  xCastMember.getAttribute('type');
		sVisible		=  xActor.getAttribute('visible');
		sDisplay		=  xActor.getAttribute('display');
		sOrder 			=  xActor.getAttribute('order');
		sID 			=  xCastMember.getAttribute('name');
		sClass 			= xCastMember.getAttribute('class');
		sStyle 			= xCastMember.getAttribute('style');
		this.sLastType = sType;
		if (sOpacity == null)
			sOpacity = "";
		if (sVisible == null)
			sVisible = "";
		if (sDisplay == null)
			sDisplay = "";
		if (sClass == null)
			sClass = "";
		if (sID == null)
			sID = xActor.getAttribute('name');
		if (sStyle == null)
			sStyle = "";
		if (sType == "image")
		{
			sID =  xCastMember.getAttribute('name');
			if (sID == null)
				sID = xActor.getAttribute('name')
			sSrc =  xCastMember.getAttribute('src');
			sStyle = xCastMember.getAttribute('style');
			sStyle = ";position:absolute;";
			sLeft =  this.getValue(xCastMember.getAttribute('left'),0,"L");
			sTop =  this.getValue(xCastMember.getAttribute('top'),0,"T");

			sStyle += "left:" + sLeft + ";";
			sStyle += "top:" + sTop + ";";
			if (xCastMember.getAttribute('width'))
			{
				sWidth =  this.getValue(xCastMember.getAttribute('width'));
				sStyle += "width:" + sWidth + ";";
			}
			if (xCastMember.getAttribute('height'))
			{
				sHeight =  this.getValue(xCastMember.getAttribute('height'));
				sStyle += "height:" + sHeight + ";";
			}
			sStyle += "z-index:" + sOrder + ";";
			if (sOpacity != "")
			{
				if (isIE())
				{
					sStyle += "filter: alpha(opacity=" + sOpacity + ");";
					
				}
				else
				{
					sStyle += "opacity:" + (sOpacity/100) + ";-moz-opacity:" + (sOpacity/100) + ";";
				}
			}
			if (sVisible == "N")
			{
				sStyle += "visibility:hidden;";
			}
			if (sDisplay == "N")
			{
				sStyle += "display:none;";
			}
			else
				sStyle += "display:block;";
			
			if (this.hasPerformance("onmouseclick",sID))
			{
				sStyle += "cursor:pointer;";						
			}
			if (this.hasPerformance("onmouseover",sID))
			{
				sStyle += "cursor:pointer;";						
			}
			if (this.hasPerformance("onmouseout",sID))
			{
				sStyle += "cursor:pointer;";						
			}
			sHTML += "<img id='" + sID + "' src='" + sSrc + "' class='" + sClass + "'style='" + sStyle + "' " + sEvents + "/>";
		}
		else if (sType == "scrollpanel")
		{
			sID =  xCastMember.getAttribute('name');
			if (sID == null)
				sID = xActor.getAttribute('name')			
			if (sStyle)
				sStyle = "position:absolute;" + sStyle + ";";
			else
				sStyle = "position:absolute;";
			sLeft = this.getValue(xCastMember.getAttribute('left'),0,"L");
			sTop =  this.getValue(xCastMember.getAttribute('top'),0,"T");
			sWidth =  this.getValue(xCastMember.getAttribute('width'));
			sHeight =  this.getValue(xCastMember.getAttribute('height'));
			
			xHTML = getChildNode(xCastMember,0);
			
			sInnerHTML =  getNodeXML(xHTML);
			
			sInnerHTML = sInnerHTML.replace("<costume>","");
			sInnerHTML = sInnerHTML.replace("</costume>","");

			sStyle += "left:" + sLeft + ";";
			sStyle += "top:" + sTop + ";";
			sStyle += "width:" + sWidth + ";";
			sStyle += "height:" + sHeight + ";";
			sStyle += "z-index:" + sOrder + ";";

			if (sOpacity != "")
			{
				if (isIE())
				{
					sStyle += "filter: alpha(opacity=" + sOpacity + ");";
					
				}
				else
				{
					sStyle += "opacity:" + (sOpacity/100) + ";-moz-opacity:" + (sOpacity/100) + ";";
				}
			}
			if (sVisible == "N")
			{
				sStyle += "visibility:hidden;";
			}
			if (sDisplay == "N")
			{
				sStyle += "display:none;";
			}
			else
				sStyle += "display:block;";

			sHTML += "<div id='" + sID + "' name='" + sID + "' class='" + sClass + "' style='" + sStyle + "' " + sEvents + ">";
				
			if (this.sc)
			{
				this.sc.scrollercontent = sInnerHTML;
				this.sc.scrollerheight = sHeight;
				this.sc.scrollerwidth = sWidth;
				
				if (xCastMember.getAttribute('speed'))
				{
					nSpeed = parseInt(xCastMember.getAttribute('speed'));
					if (nSpeed <= 0)
						nSpeed = 1;
					this.sc.setSpeed(nSpeed);
				}
				else
					this.sc.setSpeed(1);

				if (xCastMember.getAttribute('scrollheight'))
				{
					nScrollHeight = parseInt(xCastMember.getAttribute('scrollheight'));
					if (nScrollHeight >= this.sc.scrollerheight / 4)
					{
						this.sc.actualheight = nScrollHeight;
					}
				}
				sHTML += this.sc.scrollerHTML(sID,"jflash.sc");
			}
			sHTML += "</div>";
		}
		else if (sType == "panel")
		{
			sID =  xCastMember.getAttribute('name');
			if (sID == null)
				sID = xActor.getAttribute('name')
			sClass = xCastMember.getAttribute('class');
			if (sClass == null)
				sClass = "";
			sStyle = xCastMember.getAttribute('style');
			if (sStyle)
				sStyle = "position:absolute;" + sStyle + ";";
			else
				sStyle = "position:absolute;";
			sLeft = this.getValue(xCastMember.getAttribute('left'),0,"L");
			sTop =  this.getValue(xCastMember.getAttribute('top'),0,"T");
			sWidth =  this.getValue(xCastMember.getAttribute('width'));
			sHeight =  this.getValue(xCastMember.getAttribute('height'));
			
			xHTML = getChildNode(xCastMember,0);
			
			sInnerHTML =  getNodeXML(xHTML);
			
			sInnerHTML = sInnerHTML.replace("<costume>","");
			sInnerHTML = sInnerHTML.replace("</costume>","");

			sStyle += "left:" + sLeft + ";";
			sStyle += "top:" + sTop + ";";
			sStyle += "width:" + sWidth + ";";
			sStyle += "height:" + sHeight + ";";
			sStyle += "z-index:" + sOrder + ";";

			if (sOpacity != "")
			{
				if (isIE())
				{
					sStyle += "filter: alpha(opacity=" + sOpacity + ");";
					
				}
				else
				{
					sStyle += "opacity:" + (sOpacity/100) + ";-moz-opacity:" + (sOpacity/100) + ";";
				}
			}
			if (sVisible == "N")
			{
				sStyle += "visibility:hidden;";
			}
			if (sDisplay == "N")
			{
				sStyle += "display:none;";
			}
			else
				sStyle += "display:block;";
			
				
			if (this.hasPerformance("onmouseclick",sID))
			{
				sStyle += "cursor:pointer;";						
			}
			if (this.hasPerformance("onmouseover",sID))
			{
				sStyle += "cursor:pointer;";						
			}
			if (this.hasPerformance("onmouseout",sID))
			{
				sStyle += "cursor:pointer;";						
			}
			// Handle textareas as some browsers cannot handle textarea as a xml tag ie (<textarea/>)
			// so we need to remove the closing / and add the closing tag.
			
			iStart = 0;
			while (sInnerHTML.indexOf("<textarea",iStart) != -1)
			{
				var p1 = sInnerHTML.indexOf("<textarea");
				var p2 = sInnerHTML.indexOf(">",p1);
				var sText = sInnerHTML.substr(p1,(p2-p1)+1);
				if (sText.substr(sText.length-2,1) == '/')
				{
					var sNewText = sText.substr(0,sText.length-2) + "></textarea>";

					sInnerHTML = sInnerHTML.replace(sText,sNewText);
				}
				iStart += p2 + 10;
			}
			sHTML += "<div id='" + sID + "' name='" + sID + "' class='" + sClass + "' style='" + sStyle + "' " + sEvents + ">";
			sHTML += sInnerHTML;
			sHTML += "</div>";
		}
		else if (sType == "dialog")
		{
			if (sStyle)
				sStyle = "position:absolute;" + sStyle + ";";
			else
				sStyle = "position:absolute;";
			sLeft = this.getValue(xCastMember.getAttribute('left'),0,"L");
			sTop =  this.getValue(xCastMember.getAttribute('top'),0,"T");
			sWidth =  this.getValue(xCastMember.getAttribute('width'));
			sHeight =  this.getValue(xCastMember.getAttribute('height'));
			
			if (xActor.getAttribute('left'))
			{
				sLeft =  this.getValue(xActor.getAttribute('left'));
			}
			if (xActor.getAttribute('top'))
			{
				sTop =  this.getValue(xActor.getAttribute('top'));
			}
			if (xActor.getAttribute('width'))
			{
				sWidth =  this.getValue(xActor.getAttribute('width'));
			}
			if (xActor.getAttribute('height'))
			{
				height =  this.getValue(xActor.getAttribute('height'));
			}
			
			xHTML = getChildNode(xCastMember,0);
			
			sInnerHTML =  getNodeXML(xHTML);
			
			sInnerHTML = sInnerHTML.replace("<costume>","");
			sInnerHTML = sInnerHTML.replace("</costume>","");

			xHTML = getChildNode(xActor,0);

			if (xHTML != null)
			{
				var sActorInnerHTML = getNodeXML(xHTML);
				sActorInnerHTML = sActorInnerHTML.replace("<costume>","");
				sActorInnerHTML = sActorInnerHTML.replace("</costume>","");				
				sInnerHTML += sActorInnerHTML;
			}		
			
			sStyle += "left:" + sLeft + ";";
			sStyle += "top:" + sTop + ";";
			sStyle += "width:" + sWidth + ";";
			sStyle += "height:" + sHeight + ";";
			sStyle += "z-index:" + sOrder + ";";

			if (sOpacity != "")
			{
				if (isIE())
				{
					sStyle += "filter: alpha(opacity=" + sOpacity + ");";
					
				}
				else
				{
					sStyle += "opacity:" + (sOpacity/100) + ";-moz-opacity:" + (sOpacity/100) + ";";
				}
			}
			if (sVisible == "N")
			{
				sStyle += "visibility:hidden;";
			}
			if (sDisplay == "N")
			{
				sStyle += "display:none;";
			}
			else
				sStyle += "display:block;";
			
			if (this.hasPerformance("onmouseclick",sID))
			{
				sStyle += "cursor:pointer;";						
			}
			if (this.hasPerformance("onmouseover",sID))
			{
				sStyle += "cursor:pointer;";						
			}
			if (this.hasPerformance("onmouseout",sID))
			{
				sStyle += "cursor:pointer;";						
			}
			// Handle textareas as some browsers cannot handle textarea as a xml tag ie (<textarea/>)
			// so we need to remove the closing / and add the closing tag.
			
			iStart = 0;
			while (sInnerHTML.indexOf("<textarea",iStart) != -1)
			{
				var p1 = sInnerHTML.indexOf("<textarea");
				var p2 = sInnerHTML.indexOf(">",p1);
				var sText = sInnerHTML.substr(p1,(p2-p1)+1);
				if (sText.substr(sText.length-2,1) == '/')
				{
					var sNewText = sText.substr(0,sText.length-2) + "></textarea>";

					sInnerHTML = sInnerHTML.replace(sText,sNewText);
				}
				iStart += p2 + 10;
			}
			sHTML += "<div id='" + sID + "' name='" + sID + "' class='" + sClass + "' style='" + sStyle + "' " + sEvents + ">";
			sHTML += sInnerHTML;
			sHTML += "</div>";
		}
		return sHTML;		
	}
		
	function	startAct(xAct)
	{
		this.xCurrentAct = xAct;
		if (this.xCurrentAct)
		{
			for (var i = 0;i < this.xCurrentAct.childNodes.length;i++)
			{
				xNode = this.xCurrentAct.childNodes[i];
				if (xNode.nodeName == "scenes")
				{
					this.xScenes = xNode;
				}
				else if (xNode.nodeName == "performances")
				{
					this.xPerformances = xNode;
				}
			}	
			if (this.xScenes)	
			{
				for (var i = 0;i < this.xScenes.childNodes.length;i++)
				{
					var xNode = this.xScenes.childNodes[i];
					if (xNode.nodeName == "scene")
					{
						setTimeout("jflash.SceneChange('" + xNode.getAttribute('name') + "')",100);
						break;				
					}
				}				
			}
		}
		else
			alert("No Current Act");	
	}
	
	function	startShow(xRoot)
	{
		var sStyles = "";
		
		for (var i = 0;i < xRoot.childNodes.length;i++)
		{
			var xNode = xRoot.childNodes[i];
			if (xNode.nodeName == "cast")
			{
				this.xCast = xNode;
				
				// Read the details for each cast member;
				for (var xc = 0;xc < this.xCast.childNodes.length;xc++)
				{
					var xActor =  getChildNode(this.xCast,xc);
					if (xActor == null)
						break;
						
					var sName = xActor.getAttribute('name');
					
					for (var n = 0;n < xActor.childNodes.length;n++)
					{
						var xNode =  getChildNode(xActor,n);
						if (xNode == null)
							break;						
						if (xNode.nodeName == "style")
						{
							var sText = getNodeXML(xNode);
							
							if (sText != "")
							{
								sText = sText.replace("<style>","");
								sText = sText.replace("</style>","");
								sText = "#" + sName + "{\r\n" + sText + "\r\n}\r\n";
								sStyles += sText;
							}
						}
					}
				}
			}
			else if (xNode.nodeName == "equipment")
			{
				this.xEquipment = xNode;
				
				// Read the details for each set piece;
				for (var xe = 0;xe < this.xEquipment.childNodes.length;xe++)
				{
					var xPiece =  getChildNode(this.xEquipment,xe);
					if (xPiece == null)
						break;
					var sName = xPiece.getAttribute('name');					
					for (var n = 0;n < xPiece.childNodes.length;n++)
					{
						var xNode =  getChildNode(xPiece,n);
						if (xNode == null)
							break;
						if (xNode.nodeName == "style")
						{
							var sText = getNodeXML(xNode);
							
							if (sText != "")
							{
								sText = sText.replace("<style>","");
								sText = sText.replace("</style>","");
								sText = "#" + sName + "{\r\n" + sText + "\r\n}\r\n";
								sStyles += sText;
							}
						}
					}
				}
			}
			else if (xNode.nodeName == "acts")
			{
				this.xActs = xNode;
			}
			else if (xNode.nodeName == "script")
			{
				this.xScript = xNode;
				sScript = getNodeXML(xNode);
				
				document.write(sScript);
			}			
			else if (xNode.nodeName == "style")
			{
				sText = getNodeXML(xNode);
				sText = sText.replace("<style>","");
				sText = sText.replace("</style>","");
				sStyles += sText;				
			}			
		}
		if (sStyles != "")
		{
			var styleElement = document.createElement('style');
			styleElement.type = 'text/css';
	    	if (isIE())
	    		styleElement.styleSheet.cssText = sStyles;
	    	else
				styleElement.appendChild(document.createTextNode(sStyles));

			var head = document.documentElement.getElementsByTagName('head')[0];
			if (head != null) 
			{
				head.appendChild(styleElement);
			}    			
		}
	}
	
	function	curtainsup(sStage,sShow)
	{
		if (sShow == null || sShow == "")
			sShow = "site.xml";
		this.sShow = sShow;
		if (sStage)
		{
			this.stage = document.getElementById(sStage);
			if (!this.stage)
			{
				sStage = "document.body";
				this.stage = document.body;				
			}			
		}
		else
		{
			sStage = "document.body";
			this.stage = document.body;
		}
		this.sStage = sStage;
		if (this.parseXML())
		{
			var root = this.xmlDoc.documentElement
			
			document.title = root.getAttribute('title');
			this.startShow(root);
			if (this.xActs)
			{
				for (var i = 0;i < this.xActs.childNodes.length;i++)
				{
					var xNode = this.xActs.childNodes[i];
					if (xNode.nodeName == "act")
					{
						this.startAct(xNode);
						break;				
					}
				}
			}
		}
	}
	function handleEvents(obj,sEvent)
	{
		if (this.bSceneChange)
			return;
		if (this.bHandlingEvent)
			return;
		this.bHandlingEvent = true;
		this.ActivateEvent(sEvent,obj.id);
		this.bHandlingEvent = false;
	}
	
	function onActionStart()
	{
		jflash.nActions++;
	}
	
	function OnResize()
	{
	}
	
	function onActionFinish()
	{
		jflash.nActions--;
	}
	
	// end function test
}
jflash = new jflashClass();

