﻿/// <reference Name="MicrosoftAjax.js" />

Type.registerNamespace("ServerTransformed");

ServerTransformed.NavigationItemPresenter = function(model, view)
{
    this._model = model;
    this._view = view;
    
    this._mouseOverDelegate = Function.createDelegate(this, this._mouseOver);
    this._mouseOutDelegate = Function.createDelegate(this, this._mouseOut);
    this._mouseClickDelegate = Function.createDelegate(this, this._mouseClick);
    
    this._enabledChangedDelegate = Function.createDelegate(this, this._enabledChanged);
    
    this._startFloatAnimation = Function.createDelegate(this, this._startFloat);
    
    this._showMoreAnimation = Function.createDelegate(this, this._showMore);
    this._hideMoreAnimation = Function.createDelegate(this, this._hideMore);
    
    this._exitHandler = Function.createDelegate(this, this._exit);
    
    this.init();
}

ServerTransformed.NavigationItemPresenter.prototype = 
{
    init: function()
    {
        this._view.add_mouseOverHandler(this._mouseOverDelegate);
        this._view.add_mouseOutHandler(this._mouseOutDelegate);
        this._view.add_mouseClickHandler(this._mouseClickDelegate);
        
        this._model.add_EnabledChangedHandler(this._enabledChangedDelegate);
        
        this._model.add_StartFloatAnimation(this._startFloatAnimation);
        this._model.add_ShowMoreAnimation(this._showMoreAnimation);
        this._model.add_HideMoreAnimation(this._hideMoreAnimation);
        
        this._model.add_ExitHandler(this._exitHandler);
    },
    
    _exit: function(sender, eventArgs)
    {
//        this._view.remove_mouseOverHandler(this._mouseOverDelegate);
//        this._view.remove_mouseOutHandler(this._mouseOutDelegate);
//        this._view.remove_mouseClickHandler(this._mouseClickDelegate);
//        
//        this._model.remove_EnabledChangedHandler(this._enabledChangedDelegate);
//        
//        this._model.remove_StartFloatAnimation(this._startFloatAnimation);
//        this._model.remove_ShowMoreAnimation(this._showMoreAnimation);
//        this._model.remove_HideMoreAnimation(this._hideMoreAnimation);
//        
//        this._model.remove_ExitHandler(this._exitHandler);
    },
    
    _startFloat: function(sender, eventArgs) { this._view.playAnimation(eventArgs.floatAnim); },
    
    _showMore: function(sender, eventArgs) { this._view.playAnimation(eventArgs.moreAnimation); },
    _hideMore: function(sender, eventArgs) { this._view.playAnimation(eventArgs.moreAnimation); },
    
    _mouseOver: function(sender, eventArgs) { this._model.playMouseOverAnimation(); },
    _mouseOut: function(sender, eventArgs) { this._model.playMouseOutAnimation(); },
    _mouseClick: function(sender, eventArgs) { this._model.mouseClick(); },
    
    _enabledChanged: function(sender, eventArgs) { this._view.set_Cursor(this._model.get_enabled()); }
    
}

ServerTransformed.NavigationItemPresenter.registerClass("ServerTransformed.NavigationItemPresenter");