﻿


function get_mediainfo(mediainfoIndex) {
    switch (mediainfoIndex) {

        case 0:
            return { "mediaUrl": mediaUrl,
                "placeholderImage": "",
                "chapters": [
                                  ]
            };

        default:
            throw Error.invalidOperation("No such mediainfo");
    }
}

function StartWithParent(parentId, appId) {
    new StartPlayer_0(parentId);
}

function StartPlayer_0(parentId) {
    this._hostname = EePlayer.Player._getUniqueName("xamlHost");
    Silverlight.createObjectEx({ source: xamlUrl,
        parentElement: $get(parentId || "divPlayer_0"),
        id: this._hostname,
        properties: { width: '550', height: '460', 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: true,
                                      volume: 0.6,
                                      muted: false
                                  },
                                  { // event handlers
                                      mediaEnded: Function.createDelegate(this, this._onMediaEnded),
                                      mediaFailed: Function.createDelegate(this, this._onMediaFailed)
                                  },
                                  null, $get(this._hostname));
        //        //this._playNextVideo();  
        //		// changes to original script 
        this._host = $get(this._hostname);
        this._InitialPlayButtonControl = this._host.content.findName("InitialPlayButton");
        // var sb = this._host.content.findName("InitialPlayButtonAnimation")
        //sb.begin();
        this._InitialPlayButtonControl.Visibility = 'Collapsed';
        //		this._InitialPlayButtonControl.addEventListener("mouseLeftButtonUp", Function.createDelegate(this, this._onInitialPlayButtonControlClick));
        //		//this._eventToken = this._InitialPlayButtonControl.addEventListener("mouseLeftButtonUp", Function.createDelegate(this, this._onInitialPlayButtonControlClick));
        //		//alert(this._eventToken)

        // 16 jan 2009 autoplay
        this._playNextVideo();

    
    },
    _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()));
    },
    _playNextVideo: function() {
        var cVideos = 1;
        if (this._currentMediainfo < cVideos)
            this._player.set_mediainfo(get_mediainfo(this._currentMediainfo++));
    },
    // changes to original script
    _onInitialPlayButtonControlClick: function(sender, eventArgs) {
        //alert(this._eventToken)
        //this._InitialPlayButtonControl.removeEventListener(this._eventToken);
        this._InitialPlayButtonControl.IsHitTestVisible = false; // ipv deleten event

        var sb = this._host.content.findName("InitialPlayButtonAnimation")
        sb.begin();

        this._playNextVideo();
        pageTracker._trackPageview(urchinTrackerID);
    }
}

