﻿/* 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":"101ab-5.wmv",'+
		'"placeholderSource":"",'+
		'"chapters":'+
			'['+
			'new Sys.UI.Silverlight.MediaChapter("alkiko",0,"101ab-5_0.000.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("2",47.68,"101ab-5_47.680.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("3",109.24,"101ab-5_109.240.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("4",234.64,"101ab-5_234.640.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("5",319,"101ab-5_319.000.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("demoon",460.04,"101ab-5_460.040.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("pois",755.88,"101ab-5_755.880.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("6",824.68,"101ab-5_824.680.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("7",1048.28,"101ab-5_1048.280.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("8",1165.24,"101ab-5_1165.240.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("9",1373.32,"101ab-5_1373.320.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("10",1428.52,"101ab-5_1428.520.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("11",1561.92,"101ab-5_1561.920.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("12",1640.12,"101ab-5_1640.120.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("13",1704.52,"101ab-5_1704.520.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("14",1759.72,"101ab-5_1759.720.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("15",1851.72,"101ab-5_1851.720.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("demoon",1906.92,"101ab-5_1906.920.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("poisko",2238.12,"101ab-5_2238.120.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("16",2270.32,"101ab-5_2270.320.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("17",2414.8,"101ab-5_2414.800.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("18",2480.16,"101ab-5_2480.160.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("19",2542.08,"101ab-5_2542.080.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("demoon",2562.72,"101ab-5_2562.720.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("pois",2758.8,"101ab-5_2758.800.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("20",2789.76,"101ab-5_2789.760.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("21",3119.12,"101ab-5_3119.120.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("22",3249.84,"101ab-5_3249.840.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("23",3277.36,"101ab-5_3277.360.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("loppui",3525.72,"101ab-5_3525.720.jpg")'+
			']}'+
		'];' ); 
    }
    catch(e){}

    this._galleryItems=[];
    try {
        eval( 'this._galleryItems=['+
		'new ExpressionPlayer.GalleryItem("101ab-5.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);
}

