
function get_mediainfo(mediainfoIndex) {
    videoMetadata = [{ "mediaUrl": "videos/agata_english.wmv", "placeholderImage": "", "chapters": [] }, // 0
                     {"mediaUrl": "videos/agata_polish.wmv", "placeholderImage": "", "chapters": [] },  // 1
                     {"mediaUrl": "videos/casper_english.wmv", "placeholderImage": "", "chapters": [] }, // 2
                     {"mediaUrl": "videos/jonathan_english.wmv", "placeholderImage": "", "chapters": [] }, // 3
                     {"mediaUrl": "videos/justin_english.wmv", "placeholderImage": "", "chapters": [] }, // 4
                     {"mediaUrl": "videos/andrzej_english.wmv", "placeholderImage": "", "chapters": [] }, // 5
                     {"mediaUrl": "videos/andrzej_polish.wmv", "placeholderImage": "", "chapters": [] }, // 6
                     {"mediaUrl": "videos/denis_english.wmv", "placeholderImage": "", "chapters": [] }, // 7
                     {"mediaUrl": "videos/denis_russian.wmv", "placeholderImage": "", "chapters": [] }, // 8
                     {"mediaUrl": "videos/interview_video.wmv", "placeholderImage": "videos/interview_preview.png", "chapters": [] },  // 9
                     {"mediaUrl": "videos/infomercial_video.wmv", "placeholderImage": "videos/infomercial_preview.png", "chapters": [] }, // 10
                  ];
    if (mediainfoIndex >= 0 && mediainfoIndex < videoMetadata.length) {
        return videoMetadata[mediainfoIndex];
    } else {
        throw Error.invalidOperation("No such mediainfo");
    }
}




function StartWithParent(parentId, appId) {
    new StartPlayer_0(parentId);
}

function StartPlayer_0(parentId, videoToPlay, videoWidth) {
    this._hostname = EePlayer.Player._getUniqueName("xamlHost");
    if (videoWidth == 380) {
        Silverlight.createObjectEx({ source: 'videos/player380.xaml',
            parentElement: $get(parentId || "divPlayer_0"),
            id: this._hostname,
            properties: { width: '382', height: '292', version: '1.0', background: document.body.style.backgroundColor, isWindowless: 'false' },
            events: { onLoad: Function.createDelegate(this, this._handleLoad) }
        });
    } else {
        Silverlight.createObjectEx({ source: 'videos/player.xaml',
            parentElement: $get(parentId || "divPlayer_0"),
            id: this._hostname,
            properties: { width: '322', height: '316', version: '1.0', background: document.body.style.backgroundColor, isWindowless: 'false' },
            events: { onLoad: Function.createDelegate(this, this._handleLoad) }
        });
    }    
    this._currentMediainfo = videoToPlay;
}


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)
                                  },
                                  null, $get(this._hostname));
        this._playVideo();
    },
    _onMediaEnded: function(sender, eventArgs) {
        //        window.setTimeout( Function.createDelegate(this, this._playNextVideo), 1000);
    },
    _onMediaFailed: function(sender, eventArgs) {
        alert(String.format(Ee.UI.Xaml.Media.Res.mediaFailed, this._player.get_mediaUrl()));
    },
    _playVideo: function() {
        this._player.set_mediainfo(get_mediainfo(this._currentMediainfo));
    }
}
