// menu.js
jQuery(function($){
  $('a[href="#top"]').click(function(){
    window.scrollTo(0,0);
    return false;
  })
  
  var $menu = $('#left-menu') ;
  $menu.find('a').click(function(){
    $(this).blur();
    if( $(this).hasClass('on') ){
      return false ;
    }
  })

  $menu.find('>li').each(function(){
    if( $(this).is(':first-child') ){
      $(this).find('>a').addClass('first');
    }
    if( $(this).is(':last-child') ){
      if( !$(this).hasClass('now') ){
        $(this).find('>a').addClass('last');
      } else {
        $(this).find('li:last a').addClass('end');
      }
    }
    
    if( !$(this).hasClass('now') ){
      $(this).find('li:first a').addClass('first');
      $(this).find('li:last a').addClass('last');
      $(this).hover(
        function(){
          $(this).addClass('on').find('ul').show();
        },
        function(){
          if(!$(this).hasClass('now')){
            $(this).removeClass('on').find('ul').hide();
          } else{
            $(this).removeClass('on');
          }
        }
      )
    }
  })
  
});

var reWidth = function(parent,position){
  parent   = parent ? parent : 'body' ;
  position = position ? position : 'center' ;
  if ( $.browser.msie && $.browser.version<=7 ) {
    var setWidth ;
    // can't use [inline-block] browser
    $('.btn-clear',parent).each(function(){
      setWidth = 0 ;
      var div = this ;
      $('a.button',this).each(function(i,a){
        if( $(a).width() > 0 ) {
          setWidth += $(a).width()+40+(i>0?20:0) ;
        }
      })
      
      if( setWidth > 0 ) {
        if( position == 'center' ) {
          $(div).css({
            'display'     : 'block',
            'width'       : setWidth+'px',
            'margin-left' : 'auto',
            'margin-right': 'auto'
          });
        } else if ( position == 'right' ){
          $(div).css({
            'display'     : 'block',
            'width'       : setWidth+'px',
            'float'       : 'right'
          });
        } else {
          $(div).css({
            'display'     : 'block',
            'width'       : setWidth+'px'
          });
        }
      }
    })
  } else {
    return ;
  }
}
