	<PG name="youtube">
		<SCR id="ic" name="getPageID"><![CDATA[pageIcon = icon.parentNode.clip();
myXML = new XML(extXML.firstChild.childNodes[rootIcon.getPageIndex() - pgOffset]);
pageIcon.templateData = myXML.toObject();

rootIcon.setTitleText(templateData.learningObject[0].name);

xml = new XML(pageIcon.templateData.youtube[0]);
embedObj = xml.toObject();

debug(embedObj.iframe);

//new iframe code...
if (pageIcon.templateData.youtube[0].indexOf('iframe') != -1){
  //find the ID
  str = pageIcon.templateData.youtube[0];
  s = str.indexOf('src') + 5;
  f = str.indexOf('"', s);
  src = str.substr(s, f-s);
  if (src.indexOf('?') != -1) {
    // Remove all extra params
    str = src;
    p = str.indexOf('?');
    src = str.substr(0, p);
  }
  vidID = src.substr(src.lastIndexOf('/') + 1);
} else {  
  //two types of object embed code...
  if (embedObj.object[0].embed[0].src.split('/')[4].indexOf('?') != -1){
    vidID = embedObj.object[0].embed[0].src.split('/')[4].split('?')[0];
  } else {
    vidID = embedObj.object[0].embed[0].src.split('/')[4].split('&')[0];
  }
}
debug(vidID);

align = pageIcon.templateData.youtube[0].align;

if (pageIcon.templateData.youtube[0].narration != undefined){
  narration = pageIcon.templateData.youtube[0].narration;
  rootIcon.broadcast('showAudio');
}

d = new Date();
ytID = 'yt' + d.getTime();
icon.parentNode.getChildByName('youtube').attributes.id = ytID;
]]></SCR>
		<DIS h="290" w="340" tabIndex="-1" id="panel" name="panel" x="align == 'Left' ? 440 : 20" y="20" type="ext" url="templatePath + 'common/whitePanel.swf'"><![CDATA[]]></DIS>
		<DIS textColour="#999999" textSize="10" id="status" name="status" x="panel._x + 62" y="panel._y + 262" w="240" h="10" type="text"><![CDATA[Player Loading...]]></DIS>
		<DIS scrolling="auto" id="txt" name="text" x="align == 'Left' ? 20 : 380" y="20" w="400" h="484" type="text"><![CDATA[{pageIcon.templateData.youtube[0].text}]]></DIS>
		<COM id="coded" y="panel._y + 10" x="panel._x+ 10" name="youtube" url="templatePath + 'common/youtube.swf?' + yt" initObject="{ id: vidID}" />
		<SCR name="setup"><![CDATA[status.txt.selectable = false;
status.lineStyle(0,0x999999,100);
status.drawRect(0,0,240,18);

//rootIcon.enableControls(false, 80);






  ]]></SCR>
		<INT name="controls" perpetual="0">
			<RES name="onPlayerLoad" type="event" eventName="onPlayerLoad" icon="engine[ytID]" erase="1" exit="0">
				<SCR name="handler"><![CDATA[btnToggle.setEnabled(true);
btnPlay.setEnabled(true);
status.setText("Press Play");

rootIcon.enableControls(true, 100);

if (pageIcon.templateData.youtube[0].toggle == "true"){
//debug("toggle=" + pageIcon.templateData.youtube[0].toggle);
  ytTog = true;
  engine[ytID].setSize(800,515);
  engine[ytID]._x = 0;
  engine[ytID]._y = 0;
  
  btnStop._x = 10;
  btnStop._y = 484;
  btnPlay._x = 35;
  btnPlay._y = 484;
  btnPause._x = 35;
  btnPause._y = 484;
  btnToggle._x = 60;
  btnToggle._y = 484;
  
} 
else{
  ytTog = false;
  engine[ytID].setSize(320,240);
  engine[ytID]._x = panel._x + 10;
  engine[ytID]._y = panel._y + 10;
      
  btnStop._x = panel._x + 10;
  btnStop._y = 280;
  btnPlay._x = panel._x + 35;
  btnPlay._y = 280;
  btnPause._x = panel._x + 35;
  btnPause._y = 280;
  btnToggle._x = panel._x + 308;
  btnToggle._y = 280;
}
if (pageIcon.templateData.youtube[0].autoplay == "true"){
if (engine[ytID].playerLoaded != true){
  engine[ytID].loadVideoById(vidID);
  btnPlay.setEnabled(false);
  status.setText("Loading and will autoplay...");
} else {
  engine[ytID].playVideo();
}
}]]></SCR>
			</RES>
			<RES name="onPlayerStateChange" type="event" eventName="onPlayerStateChange" icon="engine[ytID]" erase="1" exit="0">
				<SCR name="handler"><![CDATA[if (engine[ytID].state == 1){  //playing

  btnStop.setEnabled(true);
  btnPause.setEnabled(true);
     
  btnPlay._visible = false;
  btnPause._visible = true;

} else if (engine[ytID].state == 2){  //paused

  btnPlay.setEnabled(true);  
  btnPlay._visible = true;
  btnPause._visible = false;
  
}
]]></SCR>
			</RES>
			<RES name="onProgress" type="event" eventName="onProgress" icon="engine[ytID]" erase="1" exit="0">
				<SCR name="handler"><![CDATA[engine[ytID].playerLoaded = true;
status.setText(engine[ytID].statusStr);

status.clear();
status.lineStyle(0,0x999999,100);
status.drawRect(0,0,240,18);

status.lineStyle();
status.beginFill(STYLES.fillColour,50);
status.drawRect(0,0,engine[ytID].bytesPercent*2.4,18);

status.lineStyle(0,0x999999,100);
status.beginFill(STYLES.fillColour,100);
status.drawRect(0,0,engine[ytID].percent*2.4,18);
]]></SCR>
			</RES>
			<RES name="onRelease" type="event" eventName="onRelease" icon="status" erase="1" exit="0">
				<SCR name="seek"><![CDATA[nt = Math.floor(status._xmouse / 240 * engine[ytID].duration);
engine[ytID].seekTo(nt ,true);]]></SCR>
			</RES>
			<RES toolTip="Stop Video" enabled="0" rs="btnStop" swf="templatePath + 'common/stopMedia.swf'" name="stop" type="button" x="panel._x + 10" y="280" label="Stop" erase="1" exit="0">
				<SCR name="stop"><![CDATA[engine[ytID].pauseVideo();
engine[ytID].seekTo(0,true);

//reset the status information
status.setText('0:00 / ' + engine[ytID].durationStr);
status.clear();
status.lineStyle(0,0x999999,100);
status.drawRect(0,0,240,18);


]]></SCR>
			</RES>
			<RES enabled="0" toolTip="Pause Video" rs="btnPause" swf="templatePath + 'common/pauseMedia.swf'" name="pause" type="button" x="panel._x + 35" y="280" label="Pause" erase="1" exit="0">
				<SCR name="play"><![CDATA[engine[ytID].pauseVideo();
]]></SCR>
			</RES>
			<RES enabled="0" toolTip="Play Video" rs="btnPlay" swf="templatePath + 'common/playMedia.swf'" name="play" type="button" x="panel._x + 35" y="280" label="Play" erase="1" exit="0">
				<SCR name="play"><![CDATA[if (engine[ytID].playerLoaded != true){
  engine[ytID].loadVideoById(vidID);
  btnPlay.setEnabled(false);
  status.setText("Loading...");
} else {
  engine[ytID].playVideo();
}



]]></SCR>
			</RES>
			<RES toolTip="Toggle Fullscreen" enabled="0" rs="btnToggle" swf="templatePath + 'common/zoomMedia.swf'" name="toggle" type="button" x="panel._x + 308" y="280" label="Resize" erase="1" exit="0">
				<SCR name="resize"><![CDATA[if (ytTog != true){
  ytTog = true;
  engine[ytID].setSize(800,515);
  engine[ytID]._x = 0;
  engine[ytID]._y = 0;
  
  btnStop._x = 10;
  btnStop._y = 484;
  btnPlay._x = 35;
  btnPlay._y = 484;
  btnPause._x = 35;
  btnPause._y = 484;
  btnToggle._x = 60;
  btnToggle._y = 484;
  
} else {
  ytTog = false;
  engine[ytID].setSize(320,240);
  engine[ytID]._x = panel._x + 10;
  engine[ytID]._y = panel._y + 10;
      
  btnStop._x = panel._x + 10;
  btnStop._y = 280;
  btnPlay._x = panel._x + 35;
  btnPlay._y = 280;
  btnPause._x = panel._x + 35;
  btnPause._y = 280;
  btnToggle._x = panel._x + 308;
  btnToggle._y = 280;
}




]]></SCR>
			</RES>
		</INT>
	</PG>
