
//----------------------------------------------------------
// Copyright (C) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------
// StartPlayer.js
var mediaURL = null;
var player;

var strProductID;
var strCategoryName;
var timeDelay;
function AssignValues(value1,value2)
{
  strProductID=value1;
  strCategoryName=value2;
}

function StartWithParent(parentId, appId) 
{
   //timeDelay =setTimeout("StartPlayer_0('"+parentId+"')",1000);
    new StartPlayer_0(parentId)
    
}
//function StartWithParent(parentId, appId) 
//{
//    new StartPlayer_0(parentId);
//}

function StartPlayer_0(parentId)
 {
    this._hostname = EePlayer.Player._getUniqueName("xamlHost");
    Silverlight.createObjectEx( {   source: '../XML/SilverLight/player.xaml', 
                                        parentElement: $get(parentId ||"divPlayer_0"), 
                                        id:this._hostname, 
                                        properties:{ width:'300', height:'250', version:'1.0', background:document.body.style.backgroundColor, isWindowless:'true' }, 
                                        events:{ onLoad:Function.createDelegate(this, this._handleLoad) } } );
    this._currentMediainfo = 0;      
}



StartPlayer_0.prototype=
 {
    _handleLoad: function() {
        this._player = $create(   ExtendedPlayer.Player, 
                                  { // properties
                                    autoPlay    : true, 
                                    volume      : 1.0,
                                    muted       : false
                                  }, 
                                  { // event handlers
                                    mediaEnded: Function.createDelegate(this, this._onMediaEnded),
                                    mediaFailed: Function.createDelegate(this, this._onMediaFailed)
                                  },
                                  null, $get(this._hostname)  ); 
        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)
        {
          
           BI_WebRef.GetMediaURL(strProductID,strCategoryName,OnSuccesVideo,OnFailVideo);
           player=this._player;
        }    
    }        
}

function OnSuccesVideo(result, userContext, methodName)
{ 

 
     mediaURL= result;
     player.set_mediainfo( get_mediainfo( mediaURL) );   
}
function OnFailVideo(error, userContext, methodName) 
{

   alert("Failed to show Video");
}
function get_mediainfo(media)
 {

    var a=0;
    switch (a)
     {        

        case 0:
            return  { "mediaUrl": media,
                      "placeholderImage": "",
                      "chapters": [               
                                  ] };                                                                
        case 1:                  
        default:
             throw Error.invalidOperation("No such mediainfo");
     }
}
