// 全ページで読み込むjavascript。jquery1.3.2とjquery.easing.1.3が必要
// ・IE6, IE7のセレクタ補完
// ・サイドバーのナビゲーションにactiveのクラスを付ける
// ・ページ内リンクはアニメーションでスクロール（#topは一番上へ）
// ・ロールオーバー（img.rolloverに対して"off.***"→"on.***"に切り替わる）

$(function(){

//メインボディ内のIE6, IE7のセレクタ補完
if(jQuery.browser.msie && parseInt(jQuery.browser.version)<8){
  $("#mainBody")
    .children(":first")
      .addClass("mainBody-first")
    .end()
    .find(".headLine10")
      .next()
        .addClass("headLine10-next")
      .end()
    .end()
    .find(".headLine11")
      .next()
        .addClass("headLine11-next")
      .end()
    .end()
    .find(".headLine20")
      .next()
        .addClass("headLine20-next")
      .end()
    .end()
    .find(".headLine30")
      .next()
        .addClass("headLine30-next")
      .end()
    .end()
    .find(".headLine40")
      .next()
        .addClass("headLine40-next")
      .end()
    .end()
    .find(".headLine41")
      .next()
        .addClass("headLine41-next")
      .end()
    .end()
    .find(".headLine50")
      .next()
        .addClass("headLine50-next")
      .end()
    .end()
    .find(".headLine51")
      .next()
        .addClass("headLine51-next")
      .end()
    .end()
  .find("div.box00")
    .each(function(){
      $(this)
      .children(":first")
          .addClass("box00-first")
        .end()
          .children(":last")
            .addClass("box00-last")
        .end()
      .end();
    })
  .end()
  .find("div.box01_inner2")
    .each(function(){
      $(this)
        .children(":first")
          .addClass("box01-first")
        .end()
        .children(":last")
          .addClass("box01-last")
        .end()
      .end();
    })
  .end()
  .find("div.box02_inner2")
    .each(function(){
    $(this)
      .children(":first")
        .addClass("box02-first")
      .end()
      .children(":last")
        .addClass("box02-last")
      .end()
      .end();
    })
  .end()
    .find("div.box03_inner2")
      .each(function(){
        $(this)
          .children(":first")
            .addClass("box03-first")
          .end()
          .children(":last")
            .addClass("box03-last")
          .end()
        .end();
      })
  .end()
  .find("div.busTimeTable")
    .each(function(){
      $(this)
        .children(":first")
          .addClass("busTimeTable-first")
        .end()
      .end();
    })
  .end()
.end();
}

$("a")
  //ページ内リンクはアニメーションでスクロール（#topは一番上へ）
  .filter("[href^='#']")
    .click(function(){
      var hash = $(this).attr("href");
      var posiotion = (hash=="#top")?0 : $(hash).offset().top;
      $("html, body")
        .animate(
          {scrollTop:posiotion},
          {easing:"easeOutCirc",duration:400,complete:function(){location.hash = hash;}}
        )
      .end();
      return false;
    })
  .end()
  //外部リンクは新しいウィンドウで開く
  .filter("[href^='http']")
    .each(function(){
      var href = $(this).attr("href");
      if(href.indexOf("http://www.h-chuo.co.jp/") < 0 && href.indexOf("https://www.h-chuo.co.jp/") < 0){
        $(this).click(function(){
          window.open(href);
          return false;
        });
      }
    })
.end();

//ロールオーバー
$("img.rollover")
.each(
function(){
var normalSrc = $(this).attr("src");

//hoverのイメージ要素ソースを取得するロジックはブラッシュアップ必要かも
var hoverSrc  = (function(){
return normalSrc.replace("_n.","_o.");
})();

//イメージ要素をキャッシュ
$(this)[0].normalImage = new Image;
$(this)[0].hoverImage  = new Image;
$(this)[0].normalImage.src = normalSrc;
$(this)[0].hoverImage.src  = hoverSrc;
}
)
.hover(
function(){
$(this).attr("src",$(this)[0].hoverImage.src);
},
function(){
$(this).attr("src",$(this)[0].normalImage.src);
}
)
.end();

//パラメーターにteststyle=trueがある場合は、bodyのクラスにteststyleを加える
if(location.search.indexOf("teststyle=true")>=0){
$("body").addClass("teststyle");
}

});