/*** Page Gate ***/
getOSSepectifInstall = function(platform)
{
    var directDownload = "http://www.microsoft.com/silverlight/handlers/getSilverlight.ashx?v=2.0&targetplatform=win";
    if (platform == "detect")
    {
        if ((navigator.userAgent.indexOf('PPC Mac OS X') != -1))
        {
            directDownload = "http://www.microsoft.com/silverlight/handlers/getSilverlight.ashx?v=2.0&targetplatform=macintel";
        }
        else if ((navigator.userAgent.indexOf('Intel Mac OS X') != -1))
        {
            directDownload = "http://www.microsoft.com/silverlight/handlers/getSilverlight.ashx?v=2.0&targetplatform=macintel";
        }
    }
    else
    {
        if (platform == "mac")
        {
            directDownload = "http://www.microsoft.com/silverlight/handlers/getSilverlight.ashx?v=2.0&targetplatform=macintel"; // default Mac set to "Intel Mac OS X"
        }
    }
    return directDownload;
}

doOSSepectifInstall = function(platform)
{
    var thePlatform = ((typeof(platform) == "undefined") || (platform == null)) ? "detect" : platform;
    window.location.href = getOSSepectifInstall(thePlatform);
    setCookie('agclear', 'true');
}

createSilverlightApp = function(){
	if(Silverlight.isInstalled("1.0")){
		player = new StartPlayer_0();
	}else{
		TimeoutDelegate = function()
		{
			if (Silverlight.isInstalled("1.0"))
				window.location.reload(false);
			else
				setTimeout(TimeoutDelegate, 3000);
		}
		setTimeout(TimeoutDelegate, 3000);
	}
}

function StartPlayer_0(parentId) {
    try {
    	eval('background:document.body.style.backgroundColor="#ck"');
    } catch(e){}

    this._hostname = ExpressionPlayer.Player._getUniqueName("xamlHost");
    Silverlight.createObjectEx( {   source: '/silverlight/player.xaml', 
                                    parentElement: $get(parentId ||"divPlayer_0"), 
                                    id:this._hostname, 
                                    properties:{ width:'100%', height:'100%', version:'1.0', background:document.body.style.backgroundColor, isWindowless:'false', inplaceInstallPrompt:true }, 
                                    events:{ onLoad:Function.createDelegate(this, this._handleLoad) } } );
    this._currentMediainfo = 0;     
}
StartPlayer_0.prototype= {
    _handleLoad: function() {
        this._player = $create(   ExtendedPlayer.Player, 
                                  { // properties
                                    autoPlay       : this.autoPlayParam(), 
                                    autoCue        : this.autoCueParam(),
				                    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)
                                  },
                                  null, $get(this._hostname)  );   

	this._playlist=[];
	var strCode = 	'this._playlist=[{ "mediaSource": "/silverlight/QQFinal.wmv","placeholderImageSource": "","chapters": [ ] }  ];';
        try {
            eval( strCode ); 
            }
        catch(e){}



	var galleryItems=[];
	var strCode = 	'galleryItems=[new ExpressionPlayer.GalleryItem("/silverlight/QQFinal.wmv", "")];';
        try {
            eval( strCode ); 
            }
        catch(e){}

        this._player.set_galleryInfo( galleryItems, Function.createDelegate(this, this._onClickGalleryItem) );  

	this._playNextVideo();                                      
    },
    
    _onClickGalleryItem : function (galleryItemIndex) {
        this._player.set_mediainfo( this._playlist[ galleryItemIndex ] ); 
        this._currentMediainfo = galleryItemIndex+1;
    },

    _onMediaEnded: function(sender, eventArgs) {
        window.setTimeout( Function.createDelegate(this, this._playNextVideo), 1000);
    },
    
    _onMediaFailed: function(sender, eventArgs) {
        alert(String.format( Sys.UI.Silverlight.MediaPlayer.Res.mediaFailed, this._player.get_mediaSource() ) );
    },
       
    _playNextVideo: function() {
        if (this._playlist!=null) {
            if (this._currentMediainfo<this._playlist.length)
                this._player.set_mediainfo( this._playlist[ this._currentMediainfo++ ] );    
        }
    },
    
    autoCueParam: function() {
	    var autoCue=true;
	    try {
		    eval("autoCue=('True'!=='False')");
	    } catch(e){}
	    return autoCue;
    },  
    
    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);
}
