﻿$(function() {

    $('#mainNav>ul>li').each(function() {
        if ($(this).find('ul').children().size() == 0) {
            $(this).find('ul').remove();
        }
    });
    $('#mainNav').show();

    $("ul.sf-menu").supersubs({
        minWidth: 13,
        maxWidth: 27,
        extraWidth: 1
    }).superfish({
        hoverClass: 'sfHover',
        autoArrows: false
    });

    $('ul.sf-menu>li>a').each(function(i) {
        var width;
        $(this).css('background-image', 'url(/assets/images/menu-bg' + (i + 1) + '.jpg)');
        if (i == 0) width = '107px';
        if (i == 1) width = '130px';
        if (i == 2) width = '253px';
        if (i == 3) width = '165px';
        if (i == 4) width = '149px';
        if (i == 5) width = '156px';
        $(this).css('width', width);
    });

    if ($('#rightSideMenu a:first').html() == 'Home' || $('#rightSideMenu a').size() <= 1) {
        $('#rightSideMenu').hide();
    }
    $('#rightSideMenu').html($('#rightSideMenu>span>ul'));
    $('#rightSideMenu ul ul').hide();
    $('#rightSideMenu li').prepend('<a href="#" class="arrow"><img src="assets/images/bullet_arrow_right.png" /></a>');
    var $visibleArrows = $('#rightSideMenu li:has(ul)>a.arrow');
    if ($visibleArrows.size() > 0) {
        $visibleArrows.css('visibility', 'visible');
    }
    else {
        $('#rightSideMenu .arrow').hide();
    }
    $("#rightSideMenu li>a.arrow").click(function() {
        var $element = $(this).nextAll("ul");
        if ($element.length > 0) {
            $element.slideToggle("fast");
            return false;
        }
    });

    $('#rightSideMenu .selected').parent().parent().show();
    $('#rightSideMenu .selected').parent().children('ul').show();
    $('#rightSideMenu .selected').parent().parent().parent().parent().show();
});