
function Start(){
    
    var obj = $('ul#Menu');
    
    var fadeInTime = 200; // in milliseconds
    var fadeOutTime = 300; // in milliseconds
    
    $(obj).find('li.item:has(ul) > a').addClass('hasChildren');
    $(obj).find('li ul li:has(ul) > a').prepend('<span class="menu-sub-indicator"> &raquo;</span>');
    $(obj).find('li ul').attr('fadeState','none');
    $(obj).find('li').hover(
        function() {
            if($(this.getElementsByTagName('ul')[0]).attr('fadeState') =='fadeOut') {
                $(this.getElementsByTagName('ul')[0]).stop(true,true);
                $(this.getElementsByTagName('ul')[0]).attr('fadeState','none')
            }
        
            if ($(this.getElementsByTagName('ul')[0]).attr('fadeState') =='none') {
                $(this.getElementsByTagName('ul')[0]).attr('fadeState','fadeIn');
                $(this.getElementsByTagName('ul')[0]).fadeIn(fadeInTime, function(){
                    $(this).attr('fadeState','none')
                });
            }
            $(this).addClass('over');
        },
        function() {
            if($(this.getElementsByTagName('ul')[0]).attr('fadeState') =='fadeIn') {
                $(this.getElementsByTagName('ul')[0]).stop(true,true)
                $(this.getElementsByTagName('ul')[0]).attr('fadeState','none');
            }
            
            if ($(this.getElementsByTagName('ul')[0]).attr('fadeState') =='none') {
                $(this.getElementsByTagName('ul')[0]).attr('fadeState','fadeOut');
                $(this.getElementsByTagName('ul')[0]).fadeOut(fadeOutTime, function(){
                    $(this).attr('fadeState','none')
                });
            }
            $(this).removeClass('over');
        }
    );
    
    // Hide empty UL's:
    $(obj).find('li ul:empty').css('visibility','hidden');
    
    // Remove the bottom border on all last items in ULs:
    $(obj).find('ul li:last-child').each(function() {
        $(this).css('border-bottom','0px');
    });
    
    // Remove the left border on the first menu item:
    $(obj).find('li.item:first').css('border-left','0');
    
}

$(document).ready(function() {
    pixelsilk.renderSkin('[' + '[Menu1]' + ']', function(html) {
        $('#subNavigation').html(html);
        var sections = $('#subNavigation div');
        var topElements = $('#Menu li.item');
        for (z = 0; z < sections.length; z++) {
            var li = topElements[z];
            var lihtml = li.innerHTML;
            li.innerHTML = lihtml + sections[z].innerHTML;
        }
       Start(); 
    });
});
