﻿/* 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":"3.wmv",'+
		'"placeholderSource":"",'+
		'"chapters":'+
			'['+
			'new Sys.UI.Silverlight.MediaChapter("2",31.111,"3_31.111.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("3",333.551,"3_333.551.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("4",528.711,"3_528.711.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("demo1",556.711,"3_556.711.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("5",1104.111,"3_1104.111.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("6",1190.751,"3_1190.751.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("7",1204.431,"3_1204.431.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("8",1311.591,"3_1311.591.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("demoon",1576.071,"3_1576.071.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("pois",1653.471,"3_1653.471.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("windows error reporting",1758.831,"3_1758.831.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("1",1775.951,"3_1775.951.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("2",1899.151,"3_1899.151.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("3",1943.951,"3_1943.951.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("demo1",1974.191,"3_1974.191.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("pois",2322.151,"3_2322.151.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("Poikki",2322.151,"3_2322.151.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("4",2492.031,"3_2492.031.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("5",2507.991,"3_2507.991.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("6",2726.871,"3_2726.871.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("7",2761.071,"3_2761.071.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("8",2817.631,"3_2817.631.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("9",2967.711,"3_2967.711.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("10",3109.391,"3_3109.391.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("11",3270.871,"3_3270.871.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("12",3373.471,"3_3373.471.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("13",3425.911,"3_3425.911.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("14",3544.471,"3_3544.471.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("15",3599.191,"3_3599.191.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("16",3688.111,"3_3688.111.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("demoko",3765.631,"3_3765.631.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("17",3913.831,"3_3913.831.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("18",3934.351,"3_3934.351.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("demo3",3991.351,"3_3991.351.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("pois",4303.191,"3_4303.191.jpg"),'+
			'new Sys.UI.Silverlight.MediaChapter("19",4307.671,"3_4307.671.jpg")'+
			']}'+
		'];' ); 
    }
    catch(e){}

    this._galleryItems=[];
    try {
        eval( 'this._galleryItems=['+
		'new ExpressionPlayer.GalleryItem("3.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);
}

