$(function(){
    var pos = window.location.toString().replace(/(http:\/\/[\w.]+\/)/, '');
    var activeBgColor = '#002A96';
    if (!pos) pos = 'home';
    else{
      if (pos.match(/.*(topinterview|ladylist).*/)) pos = pos.replace(/.*(topinterview|ladylist).*/, '$1');
      else if (pos.match(/\/?(press|rikei_iv|column)\/.*/)) pos = pos.replace(/\/?(press|rikei_iv|column)\/.*/, '$1');
      else if (pos.match(/.*(lady).*/)) pos = 'ladylist';
    }
    var tds = $('#gmenu td');
    var as = tds.find('a');
    var active_id = 'gmenu_' + pos;

    var switchMenuBg = function(anc){
      var a = anc;
      return function(isOn){
        if (isOn){
          return function(e){
            this.style.background = activeBgColor;
            a.style.color = '#fff';
          };
        }else{
          return function(e){
            this.style.background = '#fff';
            a.style.color = activeBgColor;
          };
        }
      };
    };
    $.map(tds, function(elm, pos){
      if (elm.id != active_id){
        var fn = switchMenuBg(as[pos]);
        $(elm).hover(fn(true), fn(false));
      }else{
        as[pos].style.color = '#fff';
        $(elm).css({"color" : '#fff', "background" : activeBgColor});
      }
    });
    $('#q').val('制度から企業を探す／企業の制度を調べる');
    $('#q').css({"color":'#999'});
    $('#q').focus(function(e){ this.value = ''; this.style.color = '#000'; });
    $('#q').blur(function(e){ this.value = '制度から企業を探す／企業の制度を調べる'; this.style.color = '#999'; });
});