function findLeft(obj) {
    var curLeft = 0;
    if (obj.offsetParent) {
        curLeft = obj.offsetLeft;
        while (obj = obj.offsetParent) {
            curLeft += obj.offsetLeft;
        }
    }
    return curLeft;
}

function StartMenu(){

    var obj = $('ul#Menu');

    var pos;
    var menuWidth = 275;
    
    $(obj).find('li ul li ul').each(function() {
        pos = $(this).parent().parent().parent().position();
        if ($('#themeContainer').width() - pos < (menuWidth  * 2)) {
            $(this).css('left', '-' + menuWidth + 'px');
        }
    });

  var fadeInTime = 200; // in milliseconds
  var fadeOutTime = 300; // in milliseconds

  $(obj).find('li ul li:has(ul)').prepend('<span class="menu-sub-indicator"> &nbsp;</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');
    }
  );
    
    $(obj).find('li:first').addClass('first');
    
    $(obj).find('li ul:empty').css('visibility','hidden');
    
    // Remove the bottom border on all last items in ULs:
    $(obj).find('ul').each(function() {
        $(this).find('li:last a').css('border-bottom','0px');
    });
  
    $(obj).find('li:has(ul)').hover(function() {
        $(this).addClass('hasChild');
    },
    function() {
        $(this).removeClass('hasChild');
    });
    
    // Add the top and bottom to the sub-menus:
    $(obj).find('li ul').each(function() {
        $(this).find('li:first').before('<li class="first"><div class="subNavcorner topLeft"></div><div class="menuCornerFill">&nbsp;</div><div class="subNavcorner topRight"></div></li>');
        $(this).find('li:last').after('<li class="last"><div class="subNavcorner bottomLeft"></div><div class="menuCornerFill">&nbsp;</div><div class="subNavcorner bottomRight"></div></li>');
    });
    
}
