$(document).ready(function() {
  $('ul#menu').children('li').each(function() {
    if($(this).children('ul#submenu').length) {
      $(this).children('ul#submenu').height($(this).children('ul#submenu').height()-2);
    }
    if($(this).children('.left_bg').children('a').hasClass('menu_current') || $(this).children('.left_bg').children('a').hasClass('menu_current_sub')) {
      $(this).children('ul#submenu').css('top','58px');
      $(this).children('.left_bg').children('a').css({
        height: '65px',
        'line-height' : '64px'
      });
      $(this).children('.left_bg').css({
        'margin-top': '-7px',
        'margin-bottom' : '-7px',
        'padding-right': '6px',
        'background-position' : '0 0px',
        height: '64px'
      });
      $(this).children('.right_bg').css({
        'margin-top': '-7px',
        'margin-bottom' : '-7px',
        'margin-right' : '-6px',
        'background-position' : '0 -100px',
        height: '64px'
      });
    }
  });
  $('ul#submenu').children('li').hover(
    function() {
      if(!$(this).hasClass('menu_current')) {
        $(this).children('.left_bg').children('a').css({
          'background-color':'#25346d',
          'color':'#f7ca02'
        });
        $(this).css('color','#f7ca02');
      }      
    },
    function() {
      if(!$(this).hasClass('menu_current')) {
        $(this).children('.left_bg').children('a').css({
          'background-color':'transparent',
          'color':'#fff'
        });
        $(this).css('color','#fff');        
      }
    }
    );
  $('ul#menu').children('li').hover(
    function() {
      if(!$(this).children('.left_bg').children('a').hasClass('menu_current') && !$(this).children('.left_bg').children('a').hasClass('menu_current_sub')) {
        $(this).children('.left_bg').css('background-position','0 -64px');
        $(this).children('.right_bg').css('background-position','0 -50px');
      }
    },
    function() {
      if(!$(this).children('.left_bg').children('a').hasClass('menu_current') && !$(this).children('.left_bg').children('a').hasClass('menu_current_sub')) {
        $(this).children('.left_bg').css('background-position','0 50px');
        $(this).children('.right_bg').css('background-position','0 0');
      }
    }
    )
})
