
function StartWithParent(parentId, appId) {
    new StartPlayer_0(parentId);
}

var VIDEO_RETRIES_MAX = 3;
var VIDEO_RETRY_CURRENT = 0;

function StartPlayer_0(parentId) {
    this._hostname = EePlayer.Player._getUniqueName("xamlHost");
    Silverlight.createObjectEx( {   source: '/SilverLightData/player.xaml', 
                                        parentElement: $get(parentId ||"divPlayer_0"), 
                                        id:this._hostname, 
                                        properties:{ width:'320px', height:'240px', version:'1.0', background:document.body.style.backgroundColor, isWindowless:'false' }, 
                                        events:{ onLoad:Function.createDelegate(this, this._handleLoad) } } );
    this._currentMediainfo = 0;
}
StartPlayer_0.prototype= {
    _handleLoad: function() {
        this._player = $create(   ExtendedPlayer.Player, 
                                  { // properties
                                    autoPlay    : false, 
                                    volume      : 1.0,
                                    muted       : false
                                  }, 
                                  { // event handlers
                                    mediaEnded: Function.createDelegate(this, this._onMediaEnded),
                                    mediaFailed: Function.createDelegate(this, this._onMediaFailed),
                                    markerReached: Function.createDelegate(this,this._onMarkerReached),
                                    mediaOpened: Function.createDelegate(this,this._onMediaOpened)
                                  },
                                  null, $get(this._hostname)  ); 
        this._playNextVideo();
		var XAML_HOST_OBJECT = document.getElementById('xamlHost0');
		HOST_MEDIA_OBJECT = XAML_HOST_OBJECT.content.findName('VideoWindow');
    },
    _onMarkerReached: function(sender, eventArgs){
		OnMarkerReached(eventArgs.get_marker().text);
    },
	_onMediaOpened: function(sender,eventArgs){
				    
		//var marker_0 = $get(this._hostname).content.createFromXaml('<TimelineMarker Time="00:00:00" Type="Test" Text="0" />');
        //this._player.get_mediaElement().markers.add(marker_0);
        OnMediaOpened($get(this._hostname),this._player.get_mediaElement());
        VIDEO_RETRY_CURRENT = 0;
		//sender.
            
	},
    _onMediaEnded: function(sender, eventArgs) {
        window.setTimeout( Function.createDelegate(this, this._playNextVideo), 1000);
    },
    _onMediaFailed: function(sender, eventArgs) {
        if(VIDEO_RETRY_CURRENT < VIDEO_RETRIES_MAX)
        {
            alert("Video Error...Retrying....");
            VIDEO_RETRY_CURRENT++;
            this._currentMediaInfo = 0;
            this._playNextVideo();
        }
        else
        {
            alert(String.format( Ee.UI.Xaml.Media.Res.mediaFailed, this._player.get_mediaUrl() ) );
        }
    },
    _playNextVideo: function() {
        var cVideos = 1;
        if (this._currentMediainfo<cVideos)
            this._player.set_mediainfo( get_mediainfo( this._currentMediainfo++ ) );    
    }        
}
  
var HOST_MEDIA_OBJECT = null;


