﻿// Register the namespace for the control.

Type.registerNamespace('SportsMEDIA.Web.Common.Core.Universal');

//
// Define the control properties.
//
SportsMEDIA.Web.Common.Core.Universal.ctlImageButtonEx = function(element) 
{ 
    SportsMEDIA.Web.Common.Core.Universal.ctlImageButtonEx.initializeBase(this, [element]);

    this._normalImageUrl   = null;
    this._hoverImageUrl    = null;
    this._activeImageUrl   = null;
    this._disabledImageUrl = null;
    
    this._selectednormalImageUrl = null;
    this._selectedhoverImageUrl  = null;
    this._selectedactiveImageUrl = null;
    this._targetPageUrl			 = null;
}

//
// Create the prototype for the control.
//
SportsMEDIA.Web.Common.Core.Universal.ctlImageButtonEx.prototype = {

    initialize: function() {
        SportsMEDIA.Web.Common.Core.Universal.ctlImageButtonEx.callBaseMethod(this, 'initialize');

        this._onmouseoverHandler = Function.createDelegate(this, this._onMouseOver);
        this._onmouseoutHandler = Function.createDelegate(this, this._onMouseOut);
        this._ommousedownHandler = Function.createDelegate(this, this._onMouseDown);
        this._onmouseupdHandler = Function.createDelegate(this, this._onMouseUp);

        $addHandlers(this.get_element(),
                     { 'mouseover': this._onMouseOver,
                         'mouseout': this._onMouseOut,
                         'mousedown': this._onMouseDown,
                         'mouseup': this._onMouseUp
                     },
                     this);

        if (!this.get_element().disabled) {
            if (document.URL.toLowerCase().match(this._targetPageUrl.toLowerCase())) {
                $(this.get_element()).find("img:first").attr("src", this._selectednormalImageUrl);

                var sub_css = '.' + this._targetPageUrl + '-submenu';
                $(sub_css).css('top', '62px');
            }
            else {
                $(this.get_element()).find("img:first").attr("src", this._normalImageUrl);
            }
        }
        else {
            $(this.get_element()).find("img:first").attr("src", this._disabledImageUrl);
        }
    },

    dispose: function() {
        $clearHandlers(this.get_element());
        SportsMEDIA.Web.Common.Core.Universal.ctlImageButtonEx.callBaseMethod(this, 'dispose');
    },


    //
    // Event delegates
    //
    // USE NORMAL SELECTED IMAGE IF SELECTED HOVER IMAGE IS NOT DEFINED.
    _onMouseOver: function(e) {

        $('.Tools-submenu').css('top', '-200px');
        //Sys.Debug.trace('cleaning submenu');

        if (this.get_element() && !this.get_element().disabled) {
            if (document.URL.toLowerCase().match(this._targetPageUrl.toLowerCase())) {
                if (this._selectedhoverImageUrl !== "") {
                    $(this.get_element()).find("img:first").attr("src", this._selectedhoverImageUrl);
                }
                else {
                    $(this.get_element()).find("img:first").attr("src", this._selectednormalImageUrl);
                }
            }
            else {
                $(this.get_element()).find("img:first").attr("src", this._hoverImageUrl);
            }

            var sub_css = '.' + this._targetPageUrl + '-submenu';
            $(sub_css).css('top', '62px');
            //Sys.Debug.trace('showing submenu '+ sub_css);
        }
    },

    _onMouseOut: function(e) {
        if (this.get_element() && !this.get_element().disabled) {
            if (document.URL.toLowerCase().match(this._targetPageUrl.toLowerCase())) {
                $(this.get_element()).find("img:first").attr("src", this._selectednormalImageUrl);
                var sub_css = '.' + this._targetPageUrl + '-submenu';
                $(sub_css).css('top', '62px');
            }
            else {
                $(this.get_element()).find("img:first").attr("src", this._normalImageUrl);
            }
        }
    },

    // USE NORMAL SELECTED IMAGE IF SELECTED ACTIVE IMAGE IS NOT DEFINED.
    _onMouseDown: function(e) {
        if (this.get_element() && !this.get_element().disabled) {
            if (document.URL.toLowerCase().match(this._targetPageUrl.toLowerCase())) {
                if (this._selectedactiveImageUrl !== "") {
                    $(this.get_element()).find("img:first").attr("src", this._selectedactiveImageUrl);
                }
                else {
                    $(this.get_element()).find("img:first").attr("src", this._selectednormalImageUrl);
                }
            }
            else {
                $(this.get_element()).find("img:first").attr("src", this._activeImageUrl);
            }
        }
    },

    _onMouseUp: function(e) {
        if (this.get_element() && !this.get_element().disabled) {
            $(this.get_element()).find("img:first").attr("src", this._normalImageUrl);
        }
    },

    //
    // Control properties
    //
    get_normalImageUrl: function() {
        return this._normalImageUrl;
    },

    set_normalImageUrl: function(value) {
        if (this._normalImageUrl !== value) {
            this._normalImageUrl = value;
            this.raisePropertyChanged('normalImageUrl');
        }
    },

    get_hoverImageUrl: function() {
        return this._hoverImageUrl;
    },

    set_hoverImageUrl: function(value) {
        if (this._hoverImageUrl !== value) {
            this._hoverImageUrl = value;
            this.raisePropertyChanged('hoverImageUrl');
        }
    },

    get_activeImageUrl: function() {
        return this._activeImageUrl;
    },

    set_activeImageUrl: function(value) {
        if (this._activeImageUrl !== value) {
            this._activeImageUrl = value;
            this.raisePropertyChanged('activeImageUrl');
        }
    },

    get_disabledImageUrl: function() {
        return this._disabledImageUrl;
    },

    set_disabledImageUrl: function(value) {
        if (this._disabledImageUrl !== value) {
            this._disabledImageUrl = value;
            this.raisePropertyChanged('disabledImageUrl');
        }
    },

    get_selectednormalImageUrl: function() {
        return this._selectednormalImageUrl;
    },

    set_selectednormalImageUrl: function(value) {
        if (this._selectednormalImageUrl !== value) {
            this._selectednormalImageUrl = value;
            this.raisePropertyChanged('selectednormalImageUrl');
        }
    },

    get_selectedhoverImageUrl: function() {
        return this._selectedhoverImageUrl;
    },

    set_selectedhoverImageUrl: function(value) {
        if (this._selectedhoverImageUrl !== value) {
            this._selectedhoverImageUrl = value;
            this.raisePropertyChanged('selectedhoverImageUrl');
        }
    },

    get_selectedactiveImageUrl: function() {
        return this._selectedactiveImageUrl;
    },

    set_selectedactiveImageUrl: function(value) {
        if (this._selectedactiveImageUrl !== value) {
            this._selectedactiveImageUrl = value;
            this.raisePropertyChanged('selectedactiveImageUrl');
        }
    },

    get_targetPageUrl: function() {
        return this._targetPageUrl;
    },

    set_targetPageUrl: function(value) {
        if (this._targetPageUrl !== value) {
            this._targetPageUrl = value;
            this.raisePropertyChanged('targetPageUrl');
        }
    }

}

SportsMEDIA.Web.Common.Core.Universal.ctlImageButtonEx.registerClass('SportsMEDIA.Web.Common.Core.Universal.ctlImageButtonEx', Sys.UI.Control);


if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();