﻿///////////////////////////////////////////////////////////////////////////////
//
//  ExtendedPlayer
//
//  This extends the base player class, you may override the base player
//  member functions or add additional player functionality here. Here 
//  we monitor the mouse position and show popup player controls and chapter
//  controls if we hover near them.
//
///////////////////////////////////////////////////////////////////////////////
Type.registerNamespace('ExtendedPlayer');

ExtendedPlayer.Player = function(domElement) {
    ExtendedPlayer.Player.initializeBase(this, [domElement]);  
}
ExtendedPlayer.Player.prototype =  {
    onPluginLoaded: function(args) {    
       ExtendedPlayer.Player.callBaseMethod(this, 'onPluginLoaded', [args]);
       if(this.get_chapters().length > 0) {
            new  ExtendedPlayer.HotspotButton( this, "ChapterHotspot" ); 
       }
       new  ExtendedPlayer.HotspotButton( this, "ControlsHotspot" ); 
    }
}
ExtendedPlayer.Player.registerClass('ExtendedPlayer.Player', ExpressionPlayer.Player);




ExtendedPlayer.HotspotButton = function (player, controlName) {
    var domElement = player.get_element().content.findName( controlName );   
    ExtendedPlayer.HotspotButton.initializeBase(this, [domElement, true, null, null, null, this]);      
    this.timeoutId = 0;
    this._showAnim = player.get_element().content.findName(controlName+"_MouseEnter");
    this._hideAnim = player.get_element().content.findName(controlName+"_MouseLeave");
}
ExtendedPlayer.HotspotButton.prototype = {
    _onEnter : function () {
    
        this._showHideControls ( true );
    },
    
    _onLeave : function () {
    
         this._showHideControls ( false );
    },
    
    _showHideControls : function (fShow) {    
        if (this._timeoutId!=0) {
            window.clearTimeout( this._timeoutId );
            this._timeoutId = 0;
        }
        
        if (!fShow) {
            this._timeoutId = window.setTimeout(Function.createDelegate(this, this._hideControls), 1000);     
        } else {
            this._showControls();
        }
    },

    _hideControls : function () {
		try {
		    if (this._controlsShowing) this._hideAnim.begin();
		   
        } catch(e) {}
        finally {
		    this._controlsShowing = false;
        }
	},

	_showControls : function() {
	    try {
		    if (!this._controlsShowing) {
		        this._showAnim.begin();		  
            }
        } catch(e) {} finally {
		    this._controlsShowing = true;
		}
	}    
}
ExtendedPlayer.HotspotButton.registerClass('ExtendedPlayer.HotspotButton',Sys.UI.Silverlight._Button);
