$(document).ready(function(){
  var timer_left;
  var timer_right;

  function top_left_out(){
    $("#top_left").fadeOut("");
    $("#top_left_tab").fadeIn("fast");
    return false;
  }
  function top_right_out(){
    $("#top_right").fadeOut("");
    $("#top_right_tab").fadeIn("fast");
    return false;
  }
  
  $("#top_left_tab").bind(
    "click", function(){
	  $(this).fadeOut("fast");
      $("#top_left").fadeIn();
      clearTimeout(timer_left);
      timer_left = setTimeout(top_left_out,10000);
	  return false;
	}
  );
  
  $("#top_left h3").css({"cursor":"pointer"})
  .bind("click", top_left_out);

  // 指定時間カーソルが外にいたらfadeOut
  $("#top_left").bind("mouseout", function(){
    clearTimeout(timer_left);
    timer_left = setTimeout(top_left_out,10000);
  });


  $("#top_right_tab").bind(
    "click", function(){
	  $(this).fadeOut("fast");
      $("#top_right").fadeIn();
      clearTimeout(timer_right);
      timer_right = setTimeout(top_right_out,10000);	  
	  return false;
	}
  );
  
  $("#top_right h3").css({"cursor":"pointer"})
  .bind("click", top_right_out);

  // 指定時間カーソルが外にいたらfadeOut
  $("#top_right").bind("mouseout", function(){
    clearTimeout(timer_right);
    timer_right = setTimeout(top_right_out,10000);
  });
  
  
  // 背景切り替え
  var _bg_img_flg = 1;
  $("#images_wrapper .bg_images").hide();
  $("#images_wrapper .bg_images:first-child").fadeIn("slow");
  

  setInterval(function(){
//    $("#images_wrapper .bg_images").css({"display":"none"});
    _bg_img_flg ++;
//	console.log($("#images_wrapper .bg_images"));
	if(_bg_img_flg == $("#images_wrapper .bg_images").length +1 ){
      _bg_img_flg = 1;
	}
    $("#images_wrapper .bg_images").fadeOut(4000);
    $("#images_wrapper .bg_images:nth-child("+_bg_img_flg+")").fadeIn(4000);

  },5000);


});

