// --------------------------------------------------
//	jQuery
//	common.js
// --------------------------------------------------


$(document).ready(function(){


  // --------------------------------------------------
  // フェイスブック用スクリプト埋め込み（prependは改行あるとダメぽい）
  // --------------------------------------------------
  $("body").prepend('<div id="fb-root"></div><script>(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];  if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id;js.src = "//connect.facebook.net/ja_JP/all.js#xfbml=1";fjs.parentNode.insertBefore(js, fjs);}(document, "script", "facebook-jssdk"));</script>');


  // --------------------------------------------------
  // ソーシャルボタンを表示
  // --------------------------------------------------
//  $("ul.breadcrumb").after('<div id="social_button" class="clearfix"><div class="tw-button"><a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="fb-like" data-layout="button_count" data-width="144" data-show-faces="false"></div></div>');

  $("h2").after('<div id="social_button" class="clearfix"><div class="tw-button"><a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="fb-like" data-layout="button_count" data-width="144" data-show-faces="false"></div></div>');


  // --------------------------------------------------
  // 外部リンクは新規ウインドウで開く（newwindowクラスを追加）
  // --------------------------------------------------
  $("a[href^='http']").addClass("newwindow");


  // --------------------------------------------------
  // PDFリンクはダイアログを開く（nodailogクラスがあるもの除く）
  // --------------------------------------------------
  $("a[href$='.pdf']:not('.nodailog')").each(function(){
    pdfname = $(this).attr("href");
    $(this).attr("href","/common/download.php?"+pdfname);
  });


  // --------------------------------------------------
  // ポップアップウインドウ(jquery.popupwindow.js)
  // --------------------------------------------------
  $(".popupwindow").popupwindow();


  // --------------------------------------------------
  // 新規ウインドウで開く（target="_blank"のかわり）
  // --------------------------------------------------
  $(".newwindow").click(function(){
      window.open(this.href,'_blank');
      return false;
  });


  // --------------------------------------------------
  // マウスオーバーで画像切り替え
  // --------------------------------------------------
  $("img.swapImage").hover(
      function () {
          offsrc = $(this).attr('src');
          onsrc  = offsrc.replace(/.png$/ , "_on.png");
//          onsrc  = offsrc.replace(/.jpg$/ , "_on.jpg");
//          onsrc  = offsrc.replace(/.gif$/ , "_on.gif");
          $(this).attr('src', onsrc);
      },
      function () {
           $(this).attr('src', offsrc);
      }
  );


  // --------------------------------------------------
  // マウスオーバーで画像切り替え（CSSスプライト版）
  // --------------------------------------------------
  $("img.swapImage_cs").hover(
      function () {
//         var w = $(this).width();
           var h = $(this).height();
           hh = (h/2)*(-1);
           $(this).css('top' , hh+'px');
      },
      function () {
           $(this).css('top' , '0px');
      }
  );


  // --------------------------------------------------
  // fancyboxの設定
  // --------------------------------------------------
  $("a.fancybox").fancybox();

/*
  $("a.fancybox").fancybox({
    'transitionIn'  : 'elastic',
    'transitionOut' : 'elastic',
    'speedIn'       : 200,
    'speedOut'      : 200,
    'width'         : 800,
    'height'        : 600,
    'titlePosition' : 'inside',	// inside or over
    'overlayShow'   : true,
    'overlayColor'  : '#000',
    'overlayOpacity': 0.5
  });
*/
  // --------------------------------------------------
  // タブUI（PHP include）
  // --------------------------------------------------

  // 初期化（一旦すべてのタブを隠す）
  $("#tab_contents > div").hide();
  $("ul#tab li").removeClass("active");

//  $("#tab_contents > div:first").show();

  // パースURL（カレントディレクトリ取得）
  var url = new parseUri(location.href);
  var dir = url.directory.replace(/\//g, "");

  // クエリ（?tab=hoge）ある？
  if (url.queryKey['tab']) {
// alert("クエリは"+url.queryKey['tab']);
    var tab = url.queryKey['tab'];
	$.cookie('openTab_'+dir , tab , { expires: 7 });  // ★cookie書き込み（1週間保存）
  }

  // アンカー（#hoge）ある？
  if (url.anchor) {
//	alert("アンカは"+url.anchor);
//	$.cookie('openTab_'+dir , url.anchor , { expires: 7 });  // ★cookie書き込み（1週間保存）
  }

  openTab_id = $.cookie('openTab_'+dir);  // cookie読み出し
  if (openTab_id == null) {
    openTab_id = $("ul#tab li:first").attr("id");
    $.cookie('openTab_'+dir , openTab_id , { expires: 7 });  // ★cookie書き込み（1週間保存）
    ot = 'openTab_'+dir;
  }
  $("#tab_contents ." + openTab_id).show();
  $('#tab li[id="'+ openTab_id +'"]').addClass("active");


  // タブクリックで切り替え
  $("ul#tab li").click(
    function () {
      $("ul#tab li").removeClass("active");
      var cid = $(this).attr("id");
//	$("#tab_contents").load(cid + ".htm");
    $.cookie('openTab_'+dir , cid , { expires: 7 });  // ★cookie書き込み（1週間保存）

    $(this).addClass("active");
    $("#tab_contents > div").fadeOut("fast");
    $("."+cid , "#tab_contents").fadeIn("fast");
  }
  ).hover(
  function () {
    $(this).css("cursor","pointer");
  },
  function () {
    $(this).css("cursor","auto");
  }
);





// --------------------------------------------------
// シンプル価格・OKカスタマイズ アイコン(24x24)を追加する。
// --------------------------------------------------
elm = $(".price.simple_price");
$(elm).prepend('<img src="/common/icons/icon_simpleprice24x24.png" width="24" height="24" alt="シンプル価格" class="icon"/>')
$(".icon" , elm).css("margin","-0.5em 4px 0px");


elm = $(".price.okcustom");
$(elm).prepend('<img src="/common/icons/icon_okcustom24x24.png" width="24" height="24" alt="OKカスタマイズ" class="icon" />')
$(".icon" , elm).css("margin","-0.5em 4px 0px");



}); // jQuery end


  // --------------------------------------------------
  // swapContent
  // --------------------------------------------------
function swapContent( src ) {
    $("ul#tab li").removeClass("active");
    $("#tab_contents > div").fadeOut("fast");
    $("#tab_contents > div.swap_area").load(src).fadeIn("fast");
}



  // ::::::::::::::::::::::::::::::::::::::::::::::::::
  // ☆Live設定（★未使用）
  // ::::::::::::::::::::::::::::::::::::::::::::::::::
  // $("a[rel*=facebox]").live("click", function(){
  //     $(this).facebox();
  // });


  // ::::::::::::::::::::::::::::::::::::::::::::::::::
  // FaceBox（★未使用）
  // ::::::::::::::::::::::::::::::::::::::::::::::::::
  // $("a[rel*=facebox]").facebox();


  // --------------------------------------------------
  // クエリで指定したコンテンツを表示（★未使用）
  // --------------------------------------------------
  // パースURL（クエリ取得）
/*
  var url = new parseUri(location.href);
  var content = url.queryKey['c'];

  if (content) {
    $("ul#tab li").removeClass("active");
    $("#tab_contents > div").hide();
    $("#tab_contents ."+content).fadeIn("fast");
  }
*/


// --------------------------------------------------
// 画像のaltをtitleにも追加する（★未使用）
// --------------------------------------------------
/*
$("img[alt]").each(function(){
var alt = $(this).attr("alt");
	$(this).attr("title" , alt);
});
*/

