///////////////////////////////////////////////////////////////////////////////
//
//  ExtendedPlayer
//
//  This extends the base player class, you may override the base player
//  member functions or add additional player functionality here. Here 
//  we add a button class that toggles a show/hide animation
//
///////////////////////////////////////////////////////////////////////////////
Type.registerNamespace('ExtendedPlayer');

ExtendedPlayer.Player = function(domElement) {
	ExtendedPlayer.Player.initializeBase(this, [domElement]);
}

ExtendedPlayer.Player.prototype = {
	xamlInitialize: function() {
		ExtendedPlayer.Player.callBaseMethod(this, 'xamlInitialize');
		this._showHideControlsButton = new ExtendedPlayer.showHideAnimationButton(this.get_element(), "ToggleControlsAreaButton", "Control");
	},

	xamlDispose: function() {
		if (this._showHideControlsButton) this._showHideControlsButton.dispose();
		this._showHideControlsButton = null;
		ExtendedPlayer.Player.callBaseMethod(this, 'xamlDispose');
	}
}

ExtendedPlayer.Player.registerClass('ExtendedPlayer.Player', EePlayer.Player);

ExtendedPlayer.showHideAnimationButton = function(host, nameButton, nameElement, showing) {
	ExtendedPlayer.showHideAnimationButton.initializeBase(this);
	this._animOpen = nameElement ? host.content.findName(nameElement + "_Show") : null;
	this._animClose = nameElement ? host.content.findName(nameElement + "_Hide") : null;
	this._button = host.content.findName(nameButton);
	this._button.Cursor = "Hand";
	this._eventToken = this._button.addEventListener("mouseLeftButtonUp", Function.createDelegate(this, this._onToggle));
	this._showing = !!showing;
}

ExtendedPlayer.showHideAnimationButton.prototype = {
	_onToggle: function() {
		this._showing = !this._showing;
		if (this._showing) {
			if (this._animOpen) this._animOpen.begin();
		}
		else {
			if (this._animClose) this._animClose.begin();
		}
	},

	dispose: function() {
		this._animOpen = null;
		this._animClose = null;
		if (this._eventToken) this._button.removeEventListener("mouseLeftButtonDown", this._eventToken);
		this._eventToken = null;
		this._button = null;
	}
}

ExtendedPlayer.showHideAnimationButton.registerClass('ExtendedPlayer.showHideAnimationButton');

