$(function(){

  // FIx Header/Footer
  function resizeContainer() {
    if ( $(document).width() < 964 ) {
      $("#headerarea").css("width", "960px");
      $("#footer_bg").css("width", "960px");
    } else {
      $("#headerarea").css("width", "100%");
      $("#footer_bg").css("width", "100%");
    }
  }
  var resizeTimer = null;
  $(window).bind('resize', function() {
    if (resizeTimer) clearTimeout(resizeTimer);
    resizeTimer = setTimeout(resizeContainer, 100);
  });
  resizeContainer();

  // Back to Top
  jQuery.easing.quart = function (x, t, b, c, d) {
    return -c * ((t=t/d-1)*t*t*t - 1) + b;
  };  
  $('.backtotop a').click(function () {
    $('html,body').animate({ scrollTop: 0 }, 100, 'quart');
    return false;
  });

  // Stripe & BtnRoll
  $("ul.stripe_index li:nth-child(odd)").addClass("odd");
  $("ul.stripe_index li:nth-child(even)").addClass("even");
  $('#header_apply a img, #globalnavi a img, #mainarea_bottom a img, .btn_roll img, form input.btn:image').rollover();

  // Search
  search_target = 'self';
  btn_switch($("#search_switch_self img"),"on");
  $("#search_switch_self").click(function(){
    btn_switch($("#search_switch_self img"),"on");
    btn_switch($("#search_switch_web img"),"off");
    $("#header_sel").val("all");
    $("#header_searchform").attr("target","_self");
    search_target = 'self';
  });
  $("#search_switch_web").click(function(){
    btn_switch($("#search_switch_self img"),"off");
    btn_switch($("#search_switch_web img"),"on");
    $("#header_sel").val("web");
    $("#header_searchform").attr("target","_blank");
    search_target = 'web';
  });
  
  // Font Size
  set_fontsize($.cookie('fontsize')?$.cookie('fontsize'):"m");

  $("#fontsize_s").click(function(){
    set_fontsize('s');
  });
  $("#fontsize_m").click(function(){
    set_fontsize('m');
  });
  $("#fontsize_b").click(function(){
    set_fontsize('b');
  });
 
  // Sub Function
  function btn_switch(obj,mode){
    if (obj && obj.attr("src") ) {
      new_src = obj.attr("src").replace(/(_on)?\.gif/ig, (mode=='on')?'_on.gif':'.gif');
      if ( new_src ) obj.attr("src",new_src);
    }
  }
  function set_fontsize(size){
    btn_switch($("#fontsize_s img"),(size=='s')?'on':'');
    btn_switch($("#fontsize_m img"),(size=='m')?'on':'');
    btn_switch($("#fontsize_b img"),(size=='b')?'on':'');
    $.cookie('fontsize',size,{ path: '/' });
    switch( size ) {
      case 's':
        $("#contents").css("font-size","1em");
        $("#contents h3").css("padding-bottom","8px");
        $("#contents #mainarea_bottom h3").css("padding-bottom","0");
        $("#contents h3.h3_p1, #contents h3.h3_p2, #contents h3.h3_p3, #contents h3.h3_p4, #contents h3.h3_p5, #contents h3.h3_p6, #contents h3.h3_p7, #contents h3.h3_p8, #contents h3.h3_p9, #contents h3.h3_p10").css("padding-bottom","0");
        $(".mainarea_right_menublock li").css("font-size","0.95em");
        break;
      case 'm':
        $("#contents").css("font-size","1.25em");
        $("#contents h3").css("padding-bottom","8px");
        $("#contents #mainarea_bottom h3").css("padding-bottom","0");
        $("#contents h3.h3_p1, #contents h3.h3_p2, #contents h3.h3_p3, #contents h3.h3_p4, #contents h3.h3_p5, #contents h3.h3_p6, #contents h3.h3_p7, #contents h3.h3_p8, #contents h3.h3_p9, #contents h3.h3_p10").css("padding-bottom","0");
        $(".mainarea_right_menublock li").css("font-size","1.2em");
        break;
      case 'b':
        $("#contents").css("font-size","1.5em");
        $("#contents h3").css("padding-bottom","8px");
        $("#contents #mainarea_bottom h3").css("padding-bottom","0");
        $(".mainarea_right_menublock li").css("font-size","1.45em");
        break;
    }
  }

});

