﻿/// <reference Name="MicrosoftAjax.js" />

Type.registerNamespace("ServerTransformed");

ServerTransformed.NavigationItemModel = function(args)
{
    this._properties = args;
    this._isEnabled = true;
    this.init();
}

ServerTransformed.NavigationItemModel.prototype = 
{
    init: function()
    {
        this._buildAnimationSet();
    },
    
    exit: function()
    {
        this._raiseEvent("exit");
    },
    
    floatThem: function()
    {
        this._raiseEvent("startFloat", {floatAnim:this._properties.floatingAnimation});
    },
    
    get_enabled: function() { return this._isEnabled; },
    set_enabled: function(value) 
    {
        if(value == this._isEnabled)
            return;
        else if(!value)
        {
            this.playMouseNonHoverOverAnimation();
            this._isEnabled = value;
        }
        else
        {
            this._isEnabled = value; 
            this.playMouseOutAnimation();
        }
        
        this._raiseEvent("enabledChanged");
    },
    
    get_properties: function() { return this._properties; },
    
    set_filterState: function(value)
    {
        this._properties.filter = value;
        this._buildAnimationSet();
        this.playMouseOutAnimation();
    },
    
    add_StartFloatAnimation: function(handler) { this.get_events().addHandler("startFloat", handler); },
    remove_StartFloatAnimation: function(handler) { this.get_events().removeHandler("startFloat", handler); },
    
    add_MouseClickHandler: function(handler) { this.get_events().addHandler("mouseClick", handler); },
    remove_MouseClickHandler: function(handler) { this.get_events().removeHandler("mouseClick", handler); },
    
    add_MouseOverHandler: function(handler) { this.get_events().addHandler("mouseOver", handler); },
    remove_MouseOverHandler: function(handler) { this.get_events().removeHandler("mouseOver", handler); },
    
    add_MouseOutHandler: function(handler) { this.get_events().addHandler("mouseOut", handler); },
    remove_MouseOutHandler: function(handler) { this.get_events().removeHandler("mouseOut", handler); },
    
    add_EnabledChangedHandler: function(handler) { this.get_events().addHandler("enabledChanged", handler); },
    remove_EnabledChangedHandler: function(handler) { this.get_events().removeHandler("enabledChanged", handler); },
    
    add_ShowMoreAnimation: function(handler) { this.get_events().addHandler("startMore", handler); },
    remove_ShowMoreAnimation: function(handler) { this.get_events().removeHandler("startMore", handler); },
    
    add_HideMoreAnimation: function(handler) { this.get_events().addHandler("endMore", handler); },
    remove_HideMoreAnimation: function(handler) { this.get_events().removeHandler("endMore", handler); },
    
    add_ExitHandler: function(handler) { this.get_events().addHandler("exit", handler); },
    remove_ExitHandler: function(handler) { this.get_events().removeHandler("exit", handler); },
    
    add_AnyEventHandler: function(handler) { this.get_events().addHandler("anyEvent", handler); },
    remove_AnyEventHandler: function(handler) { this.get_events().removeHandler("anyEvent", handler); },
    
    playMouseOverAnimation: function() 
    {
        if(this._isEnabled)
        {
            this._mouseOverAnimation.Begin();
            this._raiseEvent("mouseOver");
        }
    },
    
    playMouseOutAnimation: function() 
    {
        if(this._isEnabled)
        {
            this._mouseOutAnimation.Begin(); 
            this._raiseEvent("mouseOut"); 
        }
    },
    
    playMouseNonHoverOverAnimation: function() 
    { 
        if(this._isEnabled)
            this._mouseNonHoverAnimation.Begin(); 
    },
    
    playMouseNonHoverOutAnimation: function() 
    { 
        if(this._isEnabled)
            this._mouseOutAnimation.Begin(); 
    },
    
    mouseClick: function() 
    { 
        if(this._isEnabled)
            this._raiseEvent("mouseClick", {name:this._properties.name}); 
    },
    
    showMoreAnimation: function()
    {
        this._raiseEvent("startMore", {moreAnimation:this._properties.showMoreAnimation});
    },
    
    hideMoreAnimation: function()
    {
        this._raiseEvent("endMore", {moreAnimation:this._properties.hideMoreAnimation});
    },
    
    _buildAnimationSet: function()
    {
        var animationSet = this._properties.animationSets[this._properties.filter];
        this._mouseOverAnimation = animationSet.mouseOverAnimation;
        this._mouseOutAnimation = animationSet.mouseOutAnimation;
        this._mouseNonHoverAnimation = animationSet.mouseNonHoverAnimation;
    },
    
    get_events: function()
    {
        if(!this._events)
        {
            this._events = new Sys.EventHandlerList();
        }
        return this._events;
    },
    
    _raiseEvent: function(eventName, eventArgs)
    {
        var handler = this.get_events().getHandler(eventName);
        
        if(handler)
        {
            if(!eventArgs) eventArgs = Sys.EventArgs.Empty;
            if(eventName != "anyEvent") this._raiseEvent("anyEvent");
            handler(this, eventArgs);
        }
    }
}

ServerTransformed.NavigationItemModel.registerClass("ServerTransformed.NavigationItemModel");