﻿

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) {
    this._hostname = "xamlHost0";

    Silverlight.createObjectEx( {   source: source_0, 
                                    parentElement: $get(parentId ||"div" + this._hostname), 
                                    id:this._hostname, 
                                    properties:{ width:'100%', height:'100%', version:'1.0', background:rgbToHex(document.body.style.backgroundColor), isWindowless:'false', inplaceInstallPrompt:true }, 
                                    events:{ onLoad:Function.createDelegate(this, this._handleLoad) } } );


    this._currentMediainfo = -1;     
}

function StartPlayer_1(parentId) {
    this._hostname = "xamlHost1";

    Silverlight.createObjectEx( {   source: source_1, 
                                    parentElement: $get(parentId ||"div" + this._hostname), 
                                    id:this._hostname, 
                                    properties:{ width:'100%', height:'100%', version:'1.0', background:rgbToHex(document.body.style.backgroundColor), isWindowless:'false', inplaceInstallPrompt:true }, 
                                    events:{ onLoad:Function.createDelegate(this, this._handleLoad) } } );

    this._currentMediainfo = -1;     
}


function StartPlayer_2(parentId) {
    this._hostname = "xamlHost2";

    Silverlight.createObjectEx( {   source: source_2, 
                                    parentElement: $get(parentId ||"div" + this._hostname), 
                                    id:this._hostname, 
                                    properties:{ width:'100%', height:'100%', version:'1.0', background:rgbToHex(document.body.style.backgroundColor), isWindowless:'false', inplaceInstallPrompt:true }, 
                                    events:{ onLoad:Function.createDelegate(this, this._handleLoad) } } );

    this._currentMediainfo = -1;     
}

function StartPlayer_3(parentId) {
    this._hostname = "xamlHost3";

    Silverlight.createObjectEx( {   source: source_3, 
                                    parentElement: $get(parentId ||"div" + this._hostname), 
                                    id:this._hostname, 
                                    properties:{ width:'100%', height:'100%', version:'1.0', background:rgbToHex(document.body.style.backgroundColor), isWindowless:'false', inplaceInstallPrompt:true }, 
                                    events:{ onLoad:Function.createDelegate(this, this._handleLoad) } } );

    this._currentMediainfo = -1;     
}

function StartPlayer_4(parentId) {
    this._hostname = "xamlHost4";

    Silverlight.createObjectEx( {   source: source_4, 
                                    parentElement: $get(parentId ||"div" + this._hostname), 
                                    id:this._hostname, 
                                    properties:{ width:'100%', height:'100%', version:'1.0', background:rgbToHex(document.body.style.backgroundColor), isWindowless:'false', inplaceInstallPrompt:true }, 
                                    events:{ onLoad:Function.createDelegate(this, this._handleLoad) } } );

    this._currentMediainfo = -1;     
}

function StartPlayer_5(parentId) {
    this._hostname = "xamlHost5";

    Silverlight.createObjectEx( {   source: source_5, 
                                    parentElement: $get(parentId ||"div" + this._hostname), 
                                    id:this._hostname, 
                                    properties:{ width:'100%', height:'100%', version:'1.0', background:rgbToHex(document.body.style.backgroundColor), isWindowless:'false', inplaceInstallPrompt:true }, 
                                    events:{ onLoad:Function.createDelegate(this, this._handleLoad) } } );

    this._currentMediainfo = -1;     
}

function StartPlayer_6(parentId) {
    this._hostname = "xamlHost6";

    Silverlight.createObjectEx( {   source: source_6, 
                                    parentElement: $get(parentId ||"div" + this._hostname), 
                                    id:this._hostname, 
                                    properties:{ width:'100%', height:'100%', version:'1.0', background:rgbToHex(document.body.style.backgroundColor), isWindowless:'false', inplaceInstallPrompt:true }, 
                                    events:{ onLoad:Function.createDelegate(this, this._handleLoad) } } );

    this._currentMediainfo = -1;     
}


function StartPlayer_7(parentId) {
    this._hostname = "xamlHost7";

    Silverlight.createObjectEx( {   source: source_7, 
                                    parentElement: $get(parentId ||"div" + this._hostname), 
                                    id:this._hostname, 
                                    properties:{ width:'100%', height:'100%', 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 {
	switch (this._hostname)
	{
		case 'xamlHost0':
		        eval(playlistString_0); 
		break;

		case 'xamlHost1':
		        eval(playlistString_1); 
		break;

		case 'xamlHost2':
		        eval(playlistString_2); 
		break;

		case 'xamlHost3':
		        eval(playlistString_3); 
		break;

		case 'xamlHost4':
		        eval(playlistString_4); 
		break;

		case 'xamlHost5':
		        eval(playlistString_5); 
		break;

		case 'xamlHost6':
		        eval(playlistString_6); 
		break;

		case 'xamlHost7':
		        eval(playlistString_7); 
		break;
	} 

    }
    catch(e){}

    this._galleryItems=[];
    try {
        eval( 'this._galleryItems=['+
		'new ExpressionPlayer.GalleryItem("","")'+
		'];' ); 
    }
    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=('True'!=='False')");
	    } catch(e){}
	    return false;
    },  
    
    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;
    }
}

StartPlayer_1.prototype = StartPlayer_0.prototype;
StartPlayer_2.prototype = StartPlayer_0.prototype;
StartPlayer_3.prototype = StartPlayer_0.prototype;
StartPlayer_4.prototype = StartPlayer_0.prototype;
StartPlayer_5.prototype = StartPlayer_0.prototype;
StartPlayer_6.prototype = StartPlayer_0.prototype;
StartPlayer_7.prototype = StartPlayer_0.prototype;