function rgbToHex(rgb)
{
	var strHex="0123456789ABCDEF";
	var ichBracket=rgb.indexOf("(");
	if (ichBracket!=-1) {
		var rgstr = rgb.substr(ichBracket+1, rgb.length-ichBracket-2).split(',');
		rgb = "#"+ strHex[parseInt(rgstr[0])>>4]+strHex[parseInt(rgstr[0])%16]+
			   strHex[parseInt(rgstr[1])>>4]+strHex[parseInt(rgstr[1])%16]+
			   strHex[parseInt(rgstr[2])>>4]+strHex[parseInt(rgstr[2])%16];
	}
	return rgb;
}


function StartPlayer_0(parentId) {
    try {
    	eval('document.body.style.backgroundColor="#FFFFFF"');
    } catch(e){}

    this._hostname = ExpressionPlayer.Player._getUniqueName("xamlHost");
    Silverlight.createObjectEx( {   source: 'xvtsl1_43.xaml',
                                    parentElement: $get(parentId ||"divPlayer_0"),
                                    id:this._hostname,
                                    properties:{ width:'100%', height:'400', version:'1.0', background:rgbToHex(document.body.style.backgroundColor), isWindowless:'false', inplaceInstallPrompt:true },
                                    events:{ onLoad:Function.createDelegate(this, this._handleLoad) } } );

    this._currentMediainfo = -1;
}
StartPlayer_0.prototype= {
    _handleLoad: function() {
        this._player = $create(   ExtendedPlayer.Player,
                                  { // properties
                                    autoPlay       : this.autoPlayParam(),
                                    autoLoad       : this.autoLoadParam(),
				    scaleMode 	   : this.scaleModeParam(),
                                    muted          : this.mutedParam(),
				    enableCaptions : this.enableCaptionsParam(),
                                    volume         : 1.0
                                  },
                                  { // event handlers
                                    mediaEnded: Function.createDelegate(this, this._onMediaEnded),
                                    mediaFailed: Function.createDelegate(this, this._onMediaFailed),
                                    playPreviousVideo: Function.createDelegate(this, this._onPlayPreviousVideo),
                                    playNextVideo: Function.createDelegate(this, this._onPlayNextVideo)
                                  },
                                  null, $get(this._hostname)  );

    this._playlist=[];
    try {
        eval( 'this._playlist=['+
		'{"mediaSource":<object type="application/x-silverlight-2" data="data:application/x-silverlight-2," width="640" height="360" ><param name="source" value="http://www.microsoft.com/showcase/silverlight/player/1/player-en.xap" /><param name="initParams" value="Culture=en-US,Uuid=69d7c60f-6955-4d41-847c-e422f0765626,Autoplay=False,ShowMarketingOverlay=true,MiscControls=FullScreen;Detached,ShowMenu=True,Tabs=Embed;Email;Share;Info,ShowCaption=false,VideoUrl=http://www.microsoft.com/showcase/en/us/details/69d7c60f-6955-4d41-847c-e422f0765626,Mode=Player" /><param name="enableHtmlAccess" value="true" /><param name="allowHtmlPopupwindow" value="true" /><param name="background" value="#FF000000" /><param name="minRuntimeVersion" value="4.0.50401.0" /><param name="autoUpgrade" value="true" /><a href="http://go.microsoft.com/fwlink/?LinkID=149156" style="text-decoration: none;" onmousedown="javascript:new Image().src = 'http://m.webtrends.com/dcsygm2gb10000kf9xm7kfvub_9p1t/dcs.gif?dcsdat=' + new Date().getTime() + '&dcssip=www.microsoft.com&dcsuri=' + window.location.href + '&WT.tz=-8&WT.bh=16&WT.ul=en-US&WT.cd=32&WT.jo=Yes&WT.ti=&WT.js=Yes&WT.jv=1.5&WT.fi=Yes&WT.fv=10.0&WT.sli=Not%20Installed&WT.slv=Version%20Unavailable&WT.dl=1&WT.seg_1=Not%20Logged%20In&WT.vt_f_a=2&WT.vt_f=2&WT.vt_nvr1=2&WT.vt_nvr2=2&WT.vt_nvr3=2&WT.vt_nvr4=2&vp_site=Embedded&wtEvtSrc=' + window.location.href + '&vp_sli=Embedded'"><img src="http://img.microsoft.com/showcase/Content/img/resx/en-US/installSL.gif" alt="Get Microsoft Silverlight" style="border-style: none"/></a><noscript><div><img alt="DCSIMG" id="DCSIMG" width="1" height="1" src="http://m.webtrends.com/dcsygm2gb10000kf9xm7kfvub_9p1t/njs.gif?dcsuri=/nojavascript&amp;WT.js=No"/></div></noscript></object><script type="text/javascript">document.write("<script type='text/javascript' src='" + (window.location.protocol) + "//c.microsoft.com/ms.js'" +"'><\/script>");</script>,'+
		'"placeholderSource":"",'+
		'"chapters":'+
			'['+
			']}'+
		'];' );
    }
    catch(e){}

    this._galleryItems=[];
    try {
        eval( 'this._galleryItems=['+
		'new ExpressionPlayer.GalleryItem("Visual PlantEngineer","")'+
		'];' );
    }
    catch(e){}

    this._player.set_galleryInfo( this._galleryItems, Function.createDelegate(this, this._onClickGalleryItem) );
    this._onPlayNextVideo(null,null);
    },

    _onClickGalleryItem : function (galleryItemIndex) {
        this._player.set_mediainfo( this._playlist[ galleryItemIndex ] );
        this._currentMediainfo = galleryItemIndex+1;
    },

    _onMediaEnded: function(sender, eventArgs) {
        window.setTimeout( Function.createDelegate(this, this._onPlayNextVideo), 1000);
    },

    _onMediaFailed: function(sender, eventArgs) {
        alert(String.format( Sys.UI.Silverlight.MediaPlayer.Res.mediaFailed, this._player.get_mediaSource() ) );
    },


    _onPlayPreviousVideo: function(sender, eventArgs) {
        if (this._playlist!=null) {
            if (this._currentMediainfo>0) {
                this._player.set_mediainfo( this._playlist[ --this._currentMediainfo ] );
            }
        }
    },

    _onPlayNextVideo: function(sender, eventArgs) {
        if (this._playlist!=null) {
            if (this._currentMediainfo<this._playlist.length-1) {
                this._player.set_mediainfo( this._playlist[ ++this._currentMediainfo ] );
            }
        }
    },

    autoLoadParam: function() {
	    var autoLoad=true;
	    try {
		    eval("autoLoad=('True'!=='False')");
	    } catch(e){}
	    return autoLoad;
    },

    autoPlayParam: function() {
	    var autoPlay=true;
	    try
	    {
		    eval("autoPlay=('False'!=='False')");
	    } catch(e){}
	    return autoPlay;
    },

    scaleModeParam: function() {
	    var scaleMode = 1/*Normal*/;
	    try {
		    eval("scaleMode=1;");
	    } catch(e){}
	    return scaleMode;
    },

    enableCaptionsParam: function() {
	    var enableCaptions=true;
	    try {
		    eval("enableCaptions=('True'!=='False');");
	    } catch(e){}
	    return enableCaptions;
    },

    mutedParam: function() {
	    var muted=false;
	    try {
		    eval("muted=('False'!=='False');");
	    } catch(e){}
	    return muted;
    }
}

function StartWithParent(parentId, appId) {
    new StartPlayer_0(parentId);
}

