﻿// ---------- nav panel center helper class ---------- //
Ext.ux.NavPanelCenterHelper = Ext.extend(Object, {

    // standard constructor
    constructor: function(currentController) {
        // store current controller for hover handler
        this.m_currentController = currentController;
    },

    // standard initializer
    initComponent: function() {
        Ext.ux.NavPanelCenterHelper.superclass.initComponent.apply(this, arguments);

        // extra args have to go here as base class initComponent doesn't get called for some reason
        var config = {};

        Ext.apply(this, config);
        Ext.apply(this.initialConfig, config);
    },


    // initialize main tabs & corresponding links in tab reflections
    initialize: function(tabs, links) {

        this.initializeInt(tabs);
        this.initializeInt(links);
    },

    // initialize main tabs & corresponding links in tab reflections
    initializeInt: function(items) {
        for (var i = 0; i < items.length; i++) {
            if (!items[i].isDisabled) {
                $.preloadImages(items[i].activeImagePath, items[i].hoverImagePath, items[i].inactiveImagePath);

                // bind hover images
                $.bindHoverImages(
                    items[i].imageId,
                    items[i].hoverImagePath,
                    items[i].inactiveImagePath,
                    items[i].controllerName,
                    delegate(this, this.checkIsActive),
                    null, null, null, null, null);
            }
        }
    },

    // return true if the specified controller is the controller of the current action
    checkIsActive: function(controller) {
        return controller.toLowerCase() == this.m_currentController.toLowerCase();
    }
});