﻿/*  
    These are the functions that initialise the menu.
    Both are written out in packed form, in the 'RegisterScripts()' method of the xrxMenuControl
    If edited, select everything within the 'function(){}' curly braces, pack it and update the code file
*/
function initFlyouts() {
    if (jQuery('.FirstFlyout, .Flyout, .LastFlyout') != null) {
        jQuery('.FirstFlyout, .Flyout, .LastFlyout').each(function() {
            var imgHeights = new Array(0, 31, 61, 91, 121, 151, 181, 211);
            var subDivs = jQuery('div', this);
            var ul = jQuery('ul', this);
            this.style.display = 'block'; //must display or width/height do not work...
            var height = ul.height();
            subDivs.height(height);

            subDivs.eq(1).css('left', subDivs.eq(0).width() + 'px');
            subDivs.eq(2).css('left', (subDivs.eq(0).width() + subDivs.eq(1).width()) + 'px');
            this.style.display = 'none'; //hide it again!

            var re = new RegExp(/(xrx_gf.*)(\d)/);
            for (var loop = 0; loop < subDivs.length; loop++) {
                var el = subDivs.eq(loop)[0];
                var m = re.exec(el.className);
                if (m != null) {
                    var i = parseInt(m[2]);
                    if (height > imgHeights[i]) {
                        while (height > imgHeights[i]) {
                            i++;
                        }
                        el.className = el.className.replace(re, m[1] + i);
                    }
                }
            }
        });
    }
}
function alignLastFlyout() {
    var lfo = jQuery('.lmiRight');
    if (lfo.length > 0) {
        var lfoDivs = jQuery('div', lfo);
        var lmi = jQuery('#xrxMenu_LastMenuItem');
        if (lfoDivs.length > 0 && lmi.length > 0) {
            lfo.css('display', 'block'); //must display or width/height do not work...
            var lmiWidth = lmi.outerWidth();
            var lfoWidth = 0;
            for (var loop = 0; loop < lfoDivs.length; loop++) {
                lfoWidth += lfoDivs.eq(loop).width();
            }
            lfo.css('display', 'none');//hide it again!
            var leftShift = lfoWidth - lmiWidth;
            lfo.css('margin-left', '-' + (leftShift + 5) + 'px');
        }
    }
}