/**
 * グローバルナビゲーションのふわっとアニメーション
 *
 * @author   Nohara
 * @require  jquery-min.js
 * @date     2009-04-13
 * @update
 */

$(function() {

  /**
   *  基本設定
   */

  //ボタン下のホバー時の背景幅
  var hover_bg_width    = 180;
  //フェードインのアニメーション速度
  var in_speed          = 250;
  //フェードアウトのアニメーション速度
  var out_speed         = 250;


  /**
   * メインロジック
   */
  nav_length = $('ul#global-nav li').length;

  for( x=0 ;nav_length >= x; x++ ) {
    var hover_bg_position = hover_bg_width * x;

    if( $('ul#global-nav li').eq(x).children().children().hasClass('light') ) {
      $('ul#global-nav li').eq(x).children().after('<div class="gnav-bg" style="display: none;background-position: -' + hover_bg_position + 'px 0px; width: ' + hover_bg_width + 'px; height: 20px; font-size: 5px;">&nbsp;</div>');
    }
  }
  $("ul#global-nav li a").mouseover(function() {

    if( $(this).children().hasClass("light") && $(this).css("background-image") != "none" ) {
      $(this).children().fadeOut(in_speed);
      $(this).next().fadeIn(in_speed);
    }
  }).mouseleave(function() {

    if( $(this).children().hasClass("light") ) {
      $(this).children().fadeIn(out_speed);
      $(this).next().fadeOut(out_speed);
    }
  });
});