function addNavFunc() {
  var configNav = {
    over: function() {
      $('#nav ul').hide();
      $($(this).children()).css('display', 'block');
    },
    timeout: 400, // number = milliseconds delay before onMouseOut
    out: function() {
      $('ul', this).fadeOut('fast');
    },
    interval: 50
  };
  $('#nav > li').hoverIntent(configNav);

  var configSubNav = {
    over: function () {
      $($(this).children()).css('display', 'block');
    },
    timeout: 300, // number = milliseconds delay before onMouseOut
    out: function() {
      $('ul', this).fadeOut('fast');
    },
    interval: 50
  };
  $('#nav ul li').hoverIntent(configSubNav);
}

function adjustNavWidths() {
  var max_width = 300;

  $('#nav li ul').css('position', 'absolute');
  $('#nav li ul').css('top', '-9000px');
  $('#nav li ul').css('display', 'block');

  // Foreach sub menu
  $('#nav > ul').each(function(){
    $(this).width(max_width);
  });

  // Foreach sub menu
  $('#nav ul').each(function(){
            
    // Get all the menu items and find the widest one
    var children = $(this).children();
    var min_width = 100;
    $(children).each(function(){
      if ($(this).width() > min_width) {
        min_width = $(this).width();
      }
    });
 
    // Set the menu width
    $(this).width(min_width);

    // Set the width of each of the children
    $(children).each(function(){
      $(this).width(min_width);
    });

    // Set the 2nd level sub menu left margin
    $('ul', this).css('margin-left', min_width);
  });
 
  $('#nav li ul').hide();
  $('#nav li ul').css('top', 'auto');
}

function initCorners() {
  var all = {
    tl: {
      radius: 6
    },
    tr: {
      radius: 6
    },
    bl: {
      radius: 6
    },
    br: {
      radius: 6
    },
    antiAlias: true
  };
  curvyCorners(all, '.rounded-all');

  var bottom = {
    tl: {
      radius: 0
    },
    tr: {
      radius: 0
    },
    bl: {
      radius: 6
    },
    br: {
      radius: 6
    },
    antiAlias: true
  };
  curvyCorners(bottom, '.rounded-bottom');

  var top = {
    tl: {
      radius: 6
    },
    tr: {
      radius: 6
    },
    bl: {
      radius: 0
    },
    br: {
      radius: 0
    },
    antiAlias: true
  };
  curvyCorners(top, '.rounded-top');

  var top_right = {
    tl: {
      radius: 0
    },
    tr: {
      radius: 6
    },
    bl: {
      radius: 0
    },
    br: {
      radius: 0
    },
    antiAlias: true
  };
  curvyCorners(top_right, '.rounded-top-right');

  var top_left = {
    tl: {
      radius: 6
    },
    tr: {
      radius: 0
    },
    bl: {
      radius: 0
    },
    br: {
      radius: 0
    },
    antiAlias: true
  };
  curvyCorners(top_left, '.rounded-top-left');

  var bottom_left = {
    tl: {
      radius: 0
    },
    tr: {
      radius: 0
    },
    bl: {
      radius: 6
    },
    br: {
      radius: 0
    },
    antiAlias: true
  };
  curvyCorners(bottom_left, '.rounded-bottom-left');
}

$(document).ready(function(){

  $("#sidebar1 li:nth-child(1) ").addClass('widget-one');
  $("#sidebar1 li:nth-child(2) ").addClass('widget-two');
  $("#sidebar1 li:nth-child(3) ").addClass('widget-three');
  $("#sidebar1 li:nth-child(4) ").addClass('widget-four');
  $("#sidebar1 li:nth-child(5) ").addClass('widget-five');

  adjustNavWidths();
  addNavFunc();

  // Add CSS class to drop-down menu items with children
  $("#nav li li ul").parent().addClass('has-children');

  // Add CSS class to the top widget of sidebar1
  $("#sidebar1 li:first-child").addClass('top-widget');
  $("#sidebar1 li:first-child").addClass('rounded-top-left');
  $("#sidebar-news li:first-child").addClass('top-widget');
  $("#sidebar-news li:first-child").addClass('rounded-top-left');

  // Add CSS class to the bottom widget of sidebar1
  $("#sidebar1 li:last-child").addClass('bottom-widget');
  $("#sidebar1 li:last-child").addClass('rounded-bottom-left');
  $("#sidebar1 li:last-child a").addClass('rounded-bottom-left');
  $("#sidebar-news li:last-child").addClass('bottom-widget');
  $("#sidebar-news li:last-child").addClass('rounded-bottom-left');

  // Do CurvyCorners
  if ($.browser.msie || $.browser.opera) {
    addEvent(window, 'load', initCorners);
  }
  
  
});

