﻿/* Do not remove this commented code. This is compiled by Expression Encoder at template compile time.



 
*/


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) {
    try {
    	eval('document.body.style.backgroundColor="#000000"');
    } catch(e){}

    this._hostname = ExpressionPlayer.Player._getUniqueName("xamlHost");
    Silverlight.createObjectEx( {   source: 'player.xaml', 
                                    parentElement: $get(parentId ||"divPlayer_0"), 
                                    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 {
        eval( 'this._playlist=['+
		'{"mediaSource":"2.wmv",'+
		'"placeholderSource":"",'+
		'"chapters":'+
			'['+
			'new Sys.UI.Silverlight.MediaChapter("ALKOI1",0.396,"2_0.396.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("2",42.796,"2_42.796.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("demo1",364.636,"2_364.636.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("pois",803.516,"2_803.516.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("3",837.716,"2_837.716.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("4",839.996,"2_839.996.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("demo2",1035.276,"2_1035.276.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("pois",1279.516,"2_1279.516.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("5",1372.396,"2_1372.396.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("6",1406.796,"2_1406.796.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("7",1527.196,"2_1527.196.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("8",1657.916,"2_1657.916.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("9",1788.636,"2_1788.636.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("10",1891.836,"2_1891.836.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("11",1933.116,"2_1933.116.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("12",1965.316,"2_1965.316.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("13",2020.676,"2_2020.676.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("14",2089.876,"2_2089.876.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("demo3",2167.076,"2_2167.076.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("pois-synkkaa",2653.516,"2_2653.516.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("15",2676.916,"2_2676.916.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("16",2740.196,"2_2740.196.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("17",2808.276,"2_2808.276.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("18",2821.076,"2_2821.076.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("19",2854.356,"2_2854.356.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("20",2887.236,"2_2887.236.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("21",2972.236,"2_2972.236.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("22",3053.596,"2_3053.596.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("23",3080.956,"2_3080.956.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("demo4",3096.516,"2_3096.516.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("pois",3243.716,"2_3243.716.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("24",3248.916,"2_3248.916.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("25",3559.156,"2_3559.156.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("26",3562.516,"2_3562.516.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("demo5",3725.716,"2_3725.716.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("pois",3846.116,"2_3846.116.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("27",3856.956,"2_3856.956.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("demo6",3907.116,"2_3907.116.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("nyt",3950.436,"2_3950.436.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("pois",4303.836,"2_4303.836.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("28",4335.756,"2_4335.756.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("29",4401.876,"2_4401.876.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("30",4415.556,"2_4415.556.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("31",4433.796,"2_4433.796.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("32",4458.876,"2_4458.876.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("33",4511.316,"2_4511.316.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("36",4540.956,"2_4540.956.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("37",4618.476,"2_4618.476.jpg")'+
			']}'+
		'];' ); 
    }
    catch(e){}

    this._galleryItems=[];
    try {
        eval( 'this._galleryItems=['+
		'new ExpressionPlayer.GalleryItem("2.wmv","")'+
		'];' ); 
    }
    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 autoPlay;
    },  
    
    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;
    }
}

function StartWithParent(parentId, appId) {
    new StartPlayer_0(parentId);
}
