/* ------------------------------------------------------------ */
/*                                                              */
/*                         global param                         */
/*                                                              */
/* ------------------------------------------------------------ */

var _loc  = location.pathname;
var _path = _loc.substring(0,_loc.lastIndexOf('/')+1);
var _lv1path = _path.split('/')[1];
var _lv2path = _path.split('/')[2];
var _lv3path = _path.split('/')[3];
var _pwd  = _path.split('/')[_path.split('/').length-2];
var _html = _loc.substring(_loc.lastIndexOf('/')+1);
var isIE  = /*@cc_on!@*/0;
var isIE6 = isIE && !window.XMLHttpRequest;
var isIE7 = isIE && window.XMLHttpRequest && ((!document.documentMode)||(document.documentMode && document.documentMode == '7'))
var $j = jQuery.noConflict();





/* ------------------------------------------------------------ */
/*                                                              */
/*                       import libraries                       */
/*                                                              */
/* ------------------------------------------------------------ */
document.write('<script type="text/javascript" src="/_common/js/lib/jquery.easing.js"></script>');
document.write('<script type="text/javascript" src="/_common/js/lib/jquery.cookie.js"></script>');
document.write('<script type="text/javascript" src="/_common/js/lib/jquery.flatheights.js"></script>');
document.write('<script type="text/javascript" src="/_common/js/lib/jquery.sudoSlider.min.js"></script>');
document.write('<script type="text/javascript" src="/_common/js/lib/jquery.tinyTips.js"></script>');

// PNGFIX --------------------------------------------------------
if(isIE6) {
  document.write('<script type="text/javascript" src="/_common/js/lib/DD_belatedPNG.js"></script>');
  try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}  // ie6 background-image reload issue
}





/* ------------------------------------------------------------ */
/*                                                              */
/*                      jQuery initialize                       */
/*                                                              */
/* ------------------------------------------------------------ */

$j(function($){

  // IE6 : PNG -------------------------------------------
  if(isIE6) { DD_belatedPNG.fix('#nav-header li a, #nav-main li a, #content .news h2'); }

  // #hero -------------------------------------------
  var nowdate = new Date();
  var H = nowdate.getHours();
  if (H<6 || H>17) {
    $('#hero').addClass('night');
    $('body').addClass('night');
  }

  // img hover : toggle -------------------------------------------
  $('.imghover').imghover();
  $('.imgtoggle').imgtoggle();

  // .first,.last --------------------------------------------------------
  $('li:first-child, dt:first-child, dd:nth-child(2), div > .column:first').addClass('first');
  $('li:last-child, dt:last-child, dd:last-child, div > .column:last').addClass('last');
  $('#content ul,#content ol,.stripe,.item').each(function(i) {
    $('>li:even,>tbody>tr:even',this).addClass('even');
    $('>li:odd,>tbody>tr:odd',this).addClass('odd');
  });

/*
  // #nav-main -------------------------------------------
  $('#nav-main li a[href*=/' + _path.split('/')[1] + '/]').addClass('on');

  // #nav-sub -------------------------------------------
  var title = $('title').html().split('|')[0];
  $('#nav-sub dl a').each(function(){
    if ($(this).text()==$.trim(title)) $(this).parent().addClass('on');
    if ($(this).attr('title')==$.trim(title)) $(this).parent().addClass('on');
  });

  // breadcrumbs ------------------------------------------------------------
  $('body:not(#home) #breadcrumbs').breadcrumbs();

*/

  // dl.column ------------------------------------------------------------
  $('dl.column,dl.columnR').each(function(i) {
    var dtWidth = [];
    $(this).children('dt').each(function(j) {
      dtWidth.push($(this).width()+5);
    });
    var max = Math.max.apply(null,dtWidth);
    $(this).children('dt').width(max);
    var marginLR = ($(this).hasClass('columnR')) ? 'marginRight' : 'marginLeft';
    $(this).children('dd').css(marginLR,max+10);
  });

  // fontsize switcher ------------------------------------------------------------
//  $.fn.setFontsize(($.cookie('fsize')) ? $.cookie('fsize'):'fs-normal');
//  $('#fontsize a').click(function(){$.fn.setFontsize(this.id)});
  
  // window -----------------------------------------------------
  $('a.blank, area.blank, a.pdf, a.rss').click(function(){ window.open(this.href, null); return false; });
  $('.close a, a.close').click(function(){ window.close(); return false; });
  
  // gotop smooth scroll ------------------------------------------------------------
  $('.gotop a[href="#header"], .nav-anchor a').click(function(){
    $($(this).attr('href')).doScroll();
  });

  // tooltip ------------------------------------------------------------
//  $('#nav-main li:not(#nm-home) a').tinyTips('light', 'title');
});





/* ------------------------------------------------------------ */
/*                                                              */
/*                        breadcrumbs                           */
/*                                                              */
/* ------------------------------------------------------------ */
(function($){
  $.fn.breadcrumbs = function() {
    if($(this).html()!='') return null;
    var lv1label={'company':'会社情報','people':'人＆社風','career':'採用情報'};
    var lv2label={};
    var lv1 = ((typeof lv1label[_lv1path]=='undefined') ? _lv1path.toUpperCase():lv1label[_lv1path]);
    var lv2 = ((typeof lv2label[_lv2path]=='undefined') ? '':lv2label[_lv2path]);
    var crumbs = '<li class="root"><a href="/">トップページ</a></li>';
    if (lv1 != '') crumbs += '<li><a href="/'+_lv1path+'/" title="'+lv1+'">'+lv1+'</a></li>';
    if (lv2 != '' && (_lv3path != '' || (_html !='index.html' && _html != ''))) crumbs += '<li><a href="/'+_lv1path+'/'+_lv2path+'/">'+ lv2 +'</a></li>';
    crumbs += ( '<li class="here"><span>' + $('title').html().split('|')[0] + '</span></li>');
    $(this).prepend('<ol>'+crumbs+'</ol>');
  }
})(jQuery);





/* ------------------------------------------------------------ */
/*                                                              */
/*                     fontsize switcher                        */
/*                                                              */
/* ------------------------------------------------------------ */
(function($){
  $.fn.extend({
    setFontsize: function(fsize) {
      $('#fontsize a').removeClass('on');
      switch (fsize) {
        case 'fs-large' : fsize_val='90%'; $('#fontsize a#fs-large').addClass('on'); break;
        default         : fsize_val='78%';  $('#fontsize a#fs-normal').addClass('on');
      }
      $('body').css('font-size',fsize_val);
      $.cookie('fsize',fsize,{expires:30,path:'/'});
    }
  });
})(jQuery);





/* ------------------------------------------------------------ */
/*                                                              */
/*                          doScroll                            */
/*                                                              */
/* ------------------------------------------------------------ */
(function($){
  $.fn.extend({
    doScroll: function() {
      $('html,body').animate({scrollTop: $(this).offset().top}, 500);
    }
  });
})(jQuery);





/* ------------------------------------------------------------ */
/*                                                              */
/*                       image switcher                         */
/*            [ filename.ext <-> filename_on.ext ]              */
/*                                                              */
/* ------------------------------------------------------------ */
(function($){
  $.fn.extend({
    imghover: function() {
      return this.each(function() {
        var node = $(this);
        if (!node.is('img')&&!node.is(':image')){
          node.find('img,:image').imghover();
          return;
        }
        node.hover(function() {
          node.addClass('hover');
          if (!node.hasClass('on')) $.fn.imgOn(node);
        },function() {
          node.removeClass('hover');
          if (!node.hasClass('on')) $.fn.imgOff(node);
        });
      });
    },
    imgtoggle: function() {
      return this.each(function() {
        var node = $(this);
        if (!node.is('img')&&!node.is(':image')){
          node.find('img,:image').imgtoggle();
          return;
        }
        node.click(function() {
          if (node.hasClass('on')) {
            $.fn.imgOff(node);
          } else {
            if (!node.hasClass('hover')) $.fn.imgOn(node);
          }
          node.toggleClass('on');
        });
      });
    },
    imgOn: function(node) {
      if(node.attr('src').match(/^(.+)_on(\.[a-z]+)$/)) return;
      if(isIE6 && node.context.style.filter) {
        node.context.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+node.context.style.filter.split('"')[1].replace(/^(.+)(\.[a-z]+)$/,'$1_on$2')+'",sizingMethod="scale")';
      } else {
        node.attr('src',node.attr('src').replace(/^(.+)(\.[a-z]+)$/,'$1_on$2'));
      }
    },
    imgOff: function(node) {
      if(isIE6 && node.context.style.filter) {
        node.context.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+node.context.style.filter.split('"')[1].replace(/^(.+)_on(\.[a-z]+)$/,'$1$2')+'",sizingMethod="scale")';
      } else {
        node.attr('src',node.attr('src').replace(/^(.+)_on(\.[a-z]+)$/,'$1$2'));
      }
    }
  });
})(jQuery);

