// Betfred.Warp.Components.LeftHandNavComponent.js
//


Type.createNamespace('Betfred.Warp.Components.LeftHandNavComponent');

////////////////////////////////////////////////////////////////////////////////
// Betfred.Warp.Components.LeftHandNavComponent.LeftHandNavComponent

Betfred.Warp.Components.LeftHandNavComponent.LeftHandNavComponent = function Betfred_Warp_Components_LeftHandNavComponent_LeftHandNavComponent() {
    this._arLILevelClass$1 = [ 'Level1CollapsedLI', 'Level2CollapsedLI', 'Level3CollapsedLI' ];
    this._arLILevelExpandedClass$1 = [ 'Level1ExpandedLI', 'Level2ExpandedLI', 'Level3ExpandedLI' ];
    this._arLILevelSelectedClass$1 = [ 'Level1SelectedLI', 'Level2SelectedLI', 'Level3SelectedLI' ];
    Betfred.Warp.Components.LeftHandNavComponent.LeftHandNavComponent.constructBase(this);
}
Betfred.Warp.Components.LeftHandNavComponent.LeftHandNavComponent.prototype = {
    _parameters$1: null,
    _navigationService$1: null,
    _selectedDOMElement$1: null,
    _protocol: null,
    
    _displaySelectedNode$1: function Betfred_Warp_Components_LeftHandNavComponent_LeftHandNavComponent$_displaySelectedNode$1(oPassedElement) {
        var oClickedElement = oPassedElement;
        this._selectedDOMElement$1 = oClickedElement;
        var oControlContainerDiv = document.getElementById(this._domElementId);
        var oDivs = oControlContainerDiv.getElementsByTagName('div');
        if (oDivs.length > 0) {
            this._unSelectAllChildItems$1(oDivs[0], 0, this._arLILevelClass$1, this._arLILevelSelectedClass$1);
        }
        var oLIParent = oClickedElement;
        var iDepthOfCurrentElement = this._getLIDepth$1(oLIParent);
        oClickedElement.className = this._arLILevelSelectedClass$1[iDepthOfCurrentElement - 1];
        var oElement = oClickedElement;
        while (oElement.id !== this._domElementId) {
            if (oElement.tagName.toUpperCase() === 'DIV') {
                var oParentLITemp = oElement.parentNode;
                var iTempDepth = this._getLIDepth$1(oElement);
                if (iTempDepth > 0) {
                    oParentLITemp.className = this._arLILevelExpandedClass$1[iTempDepth - 1];
                }
            }
            oElement = oElement.parentNode;
        }
        this._collapseAllUnselectedNodes$1(oClickedElement, this._arLILevelClass$1);
    },
    
    selectNode: function Betfred_Warp_Components_LeftHandNavComponent_LeftHandNavComponent$selectNode(oPassedElement, sPageArea, sPageFilter, iLevel) {
        this._displaySelectedNode$1(oPassedElement);
        this._log.debug('selectNode');
        var arPageFilters = sPageFilter.split('|');
        var oPageFilter = {};
        var $enum1 = arPageFilters.getEnumerator();
        while ($enum1.moveNext()) {
            var sNameValuePair = $enum1.get_current();
            var arNameValue = sNameValuePair.split('=');
            var sName = '';
            var sValue = '';
            if (arNameValue.length > 0) {
                sName = arNameValue[0];
                if (arNameValue.length > 1) {
                    sValue = arNameValue[1];
                }
            }
            oPageFilter[sName] = sValue;
        }
        this._navigationService$1.goTo(sPageArea, oPageFilter);
    },
    
    toggleNode: function Betfred_Warp_Components_LeftHandNavComponent_LeftHandNavComponent$toggleNode(oPassedElement, iCurrentLevel) {
        var oElement = oPassedElement;
        var oDivs = oElement.getElementsByTagName('div');
        if (oElement.className === this._arLILevelClass$1[iCurrentLevel]) {
            this._collapseAllUnselectedNodes$1(oElement, this._arLILevelClass$1);
            oElement.className = this._arLILevelExpandedClass$1[iCurrentLevel];
        }
        else {
            oElement.className = this._arLILevelClass$1[iCurrentLevel];
        }
    },
    
    _unSelectAllChildItems$1: function Betfred_Warp_Components_LeftHandNavComponent_LeftHandNavComponent$_unSelectAllChildItems$1(oDiv, iCurrentLevel, arLILevelClass, arLevelLISelectedClass) {
        var oULs = oDiv.getElementsByTagName('ul');
        if (oULs.length > 0) {
            var oLIs = oULs[0].getElementsByTagName('li');
            for (var i = 0; i < oLIs.length; i++) {
                var oLI = oLIs[i];
                if (oLI.className === arLevelLISelectedClass[iCurrentLevel]) {
                    oLI.className = arLILevelClass[iCurrentLevel];
                }
                var oDivs = oLI.getElementsByTagName('div');
                if (oDivs.length > 0) {
                    this._unSelectAllChildItems$1(oDivs[0], iCurrentLevel + 1, arLILevelClass, arLevelLISelectedClass);
                }
            }
        }
    },
    
    _collapseAllUnselectedNodes$1: function Betfred_Warp_Components_LeftHandNavComponent_LeftHandNavComponent$_collapseAllUnselectedNodes$1(oSelectedElement, arLevelClass) {
        var oLIs = document.getElementById(this._domElementId).getElementsByTagName('li');
        for (var i = 0; i < oLIs.length; i++) {
            if (this._shouldListItemBeClosed$1(oSelectedElement, oLIs[i])) {
                var iDepth = this._getLIDepth$1(oLIs[i]);
                if (iDepth > 0) {
                    oLIs[i].className = arLevelClass[iDepth - 1];
                }
            }
        }
    },
    
    _getLIDepth$1: function Betfred_Warp_Components_LeftHandNavComponent_LeftHandNavComponent$_getLIDepth$1(oSelectedElement) {
        var iCount = 0;
        var oElement = oSelectedElement;
        while (oElement.id !== this._domElementId) {
            if (oElement.tagName.toUpperCase() === 'LI') {
                iCount++;
            }
            oElement = oElement.parentNode;
        }
        return iCount;
    },
    
    _shouldListItemBeClosed$1: function Betfred_Warp_Components_LeftHandNavComponent_LeftHandNavComponent$_shouldListItemBeClosed$1(oSelectedElement, oLIToCheck) {
        if (!oSelectedElement) {
            return true;
        }
        var oParent;
        if (oSelectedElement.tagName.toUpperCase() === 'LI') {
            oParent = oSelectedElement;
        }
        else {
            oParent = oSelectedElement.parentNode;
        }
        if (oLIToCheck === oParent) {
            return false;
        }
        else {
            while (oParent.id !== this._domElementId) {
                if (oParent.tagName.toUpperCase() === 'LI') {
                    if (oLIToCheck === oParent) {
                        return false;
                    }
                }
                oParent = oParent.parentNode;
            }
        }
        return true;
    },
    
    init: function Betfred_Warp_Components_LeftHandNavComponent_LeftHandNavComponent$init(environment, componentInstanceName, domElementId, parameters) {
        Betfred.Warp.Components.LeftHandNavComponent.LeftHandNavComponent.callBase(this, 'init', [ environment, componentInstanceName, domElementId, parameters ]);
        this._parameters$1 = parameters;
        this._protocol = parameters['protocol'];
    },
    
    start: function Betfred_Warp_Components_LeftHandNavComponent_LeftHandNavComponent$start() {
        this._log.debug('Start');
        this._navigationService$1.registerPageFilterChangedListener(this);
        this.repaint();
    },
    
    repaint: function Betfred_Warp_Components_LeftHandNavComponent_LeftHandNavComponent$repaint() {
        this._log.debug('Repaint');
        var xsltParameters = {};
        xsltParameters['region'] = this._environment.getRegion();
        xsltParameters['component-instance-name'] = this._componentInstanceName;
        this._environment.transformAndUpdate(this._domElementId, this._parameters$1['content-url'], this._parameters$1['xslt-url'], xsltParameters, Delegate.create(this, function() {
            this.onPageFilterChanged(null);
        }));
    },
    
    setNavigationService: function Betfred_Warp_Components_LeftHandNavComponent_LeftHandNavComponent$setNavigationService(navigationService) {
        this._log.debug('SetNavigationService');
        this._navigationService$1 = navigationService;
    },
    
    onPageFilterChanged: function Betfred_Warp_Components_LeftHandNavComponent_LeftHandNavComponent$onPageFilterChanged(eventSource) {
        this._log.debug('OnPageFilterChanged');
        var progress = this._navigationService$1.getPageFilter()['selected-menu-id'];
        if (progress) {
            if (progress.length > 0) {
                var oSelectedMenuItem = document.getElementById(progress);
                this._displaySelectedNode$1(oSelectedMenuItem);
            }
        }
    }
}


Betfred.Warp.Components.LeftHandNavComponent.LeftHandNavComponent.createClass('Betfred.Warp.Components.LeftHandNavComponent.LeftHandNavComponent', Framework.AbstractComponent, NavigationService.IPageFilterChangedListener);

// ---- Do not remove this footer ----
// Generated using Script# v0.5.1.0 (http://projects.nikhilk.net)
// -----------------------------------
Type.createNamespace('IncludeComponent');

////////////////////////////////////////////////////////////////////////////////
// IncludeComponent.IncludeComponent

IncludeComponent.IncludeComponent = function IncludeComponent_IncludeComponent() {
    IncludeComponent.IncludeComponent.constructBase(this);
}
IncludeComponent.IncludeComponent.prototype = {
    _parameters$1: null,
    _navigationService$1: null,
    
    setNavigationService: function IncludeComponent_IncludeComponent$setNavigationService(navigationService) {
        this._log.debug('SetNavigationService');
        this._navigationService$1 = navigationService;
        this._navigationService$1.registerTopicalizedPageFilterChangedListener(this, NavigationService.NavigationService.action);
        this._navigationService$1.registerTopicalizedPageFilterChangedListener(this, NavigationService.NavigationService.page);
    },
    
    onPageFilterChanged: function IncludeComponent_IncludeComponent$onPageFilterChanged(eventSource) {
        this._log.debug('OnPageFilterChanged');
        this.repaint();
    },
    
    init: function IncludeComponent_IncludeComponent$init(environment, componentInstanceName, domElementId, parameters) {
        IncludeComponent.IncludeComponent.callBase(this, 'init', [ environment, componentInstanceName, domElementId, parameters ]);
        this._parameters$1 = new Framework.CommonComponentParameters(parameters);
    },
    
    repaint: function IncludeComponent_IncludeComponent$repaint() {
        this._log.debug('Repaint');
        if (this.isVisible(this._parameters$1.get_visibleOn(), this._parameters$1.get_notVisibleOn(), this._navigationService$1.getAction())) {
            this.show();
            var contentUrl = this._parameters$1.get_contentUrl().replace('${region}', this._environment.getRegion()).replace('${language}', this._environment.getLanguage());
            var page = this._navigationService$1.getPageFilter()[NavigationService.NavigationService.page];
            if (!String.isNullOrEmpty(page)) {
                contentUrl = contentUrl.replace('${page}', page);
            }
            var ajaxUpdater = new Framework.AjaxUpdater(this._domElementId, contentUrl, null, null);
            ajaxUpdater.update();
        }
        else {
            this.hide();
        }
    }
}


IncludeComponent.IncludeComponent.createClass('IncludeComponent.IncludeComponent', Framework.AbstractComponent, NavigationService.IPageFilterChangedListener);

// ---- Do not remove this footer ----
// Generated using Script# v0.5.1.0 (http://projects.nikhilk.net)
// -----------------------------------
