﻿/// <reference name="MicrosoftAjax.js" />
/// <reference name="dnn.js" assembly="DotNetNuke.WebUtility" />
/// <reference name="dnn.xmlhttp.js" assembly="DotNetNuke.WebUtility" />

// Register Namespace
Type.registerNamespace('Bluestar.Common.Controls');

//**********************************************************************
// CasinoLanguage Class
//**********************************************************************
// CasinoLanguage - Constructor
Bluestar.Common.Controls.CasinoLanguage = function() {
    // Call Base Method
    Bluestar.Common.Controls.CasinoLanguage.initializeBase(this);
    // Member Variables
    this._msgs = {};

    // Associate delegates to single member variable dictionary,
    // to make it easy to dispose.
    this._delegates = {
        _onLoadDelegate: Function.createDelegate(this, this._onLoad)
    };
    // Event Hookup:
    Sys.Application.add_load(this._delegates._onLoadDelegate);
};
// CasinoLanguage - Prototype
Bluestar.Common.Controls.CasinoLanguage.prototype = {
    // Properties
    get_ns: function() { return this.get_id() + '_'; },
    get_msgs: function() { return this._msgs; },
    set_msgs: function(value) { this._msgs = value; },
    // ASP.NET AXAX Events
    initialize: function() {
        // Call Base Method
        Bluestar.Common.Controls.CasinoLanguage.callBaseMethod(this, 'initialize');
    },
    dispose: function() {
        this._delegates = null;
        Bluestar.Common.Controls.CasinoLanguage.callBaseMethod(this, 'dispose');
    },
    // Public Methods
    getMessage: function(key, def) {
        if (this._msgs[key]) {
            return this._msgs[key];
        } else {
            return def;
        }
    },
    // Control Events
    _onLoad: function(src, arg) {
        // The page is completely loaded.
        jQuery(function($) {
            // Check if drop down selector button exists in page.
            if ($('a.rp-btn-d').length > 0) {
                // Hide all tabs.
                $('ul.sub').hide();

                // Assign button click event, to toggle drop down panel.
                $('a.rp-btn-d').click(function(e) {
                    // Prevent server side event from triggering.
                    e.preventDefault();

                    // Toggle the drop down panel & update the toggle button state.
                    $(this).parent().find('ul.sub').toggle();
                    $(this).parent().toggleClass('active');
                });

                $('a.rp-btn-d').parent().find('ul.sub').mouseup(function(e) {
                    return false;
                });

                $(document).mouseup(function(e) {
                    if ($(e.target).parent('a.rp-btn-d').length == 0) {
                        $('a.rp-btn-d').parent().removeClass('active').find('ul.sub').hide();
                    }
                });
            }
        });
    }
};
// Register class and inherit from Sys.Component
Bluestar.Common.Controls.CasinoLanguage.registerClass("Bluestar.Common.Controls.CasinoLanguage", Sys.Component);

