﻿/* ================================================================ 
This copyright notice must be untouched at all times.
Stay Put!
Copyright (c) 2009 Stu Nicholls - stunicholls.com - all rights reserved.
=================================================================== */


$(function() {

//サイト内検索ヒント表示
  $('#query-input')
    .blur(function(){
      var $$=$(this);
      if($$.val()=='' || $$.val()==$$.attr('title')){
        $$.css('color', '#999')
          .val($$.attr('title'));
      }
    })
    .focus(function(){
      var $$=$(this);
      if($$.val()==$$.attr('title')){
        $(this).css('color', '#000')
               .val('');
      }
    })
    .parents('form:first').submit(function(){
      var $$=$('#query-input');
      if($$.val()==$$.attr('title')){
        $$.triggerHandler('focus');
      }
    }).end()
    .blur();


  //ウィンドウの高さと幅を取得
  scrH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; 
  scrW = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  
  pfHeight = $("#qm_movebox").outerHeight();
  footerHeight =  $("#footer").outerHeight();

  if ($.browser.safari) {
      pfHeight += 20;
  }
	$('#youken_1').click(function(){		$("div.omimai").css({"display":"none"});	});
	$('#youken_2').click(function(){		$("div.omimai").css({"display":"none"});	});
	$('#youken_3').click(function(){		$("div.omimai").css({"display":"none"});	});
	$('#youken_4').click(function(){		$("div.omimai").css({"display":"none"});	});
	$('#youken_6').click(function(){		$("div.omimai").css({"display":"none"});	});
	$('#youken_5').click(function(){
		$("div.omimai").css({"display":"inherit"});
	});
	
  $("#quick_menu").css("height", pfHeight + "px");
  //クイックメニューのulの幅制限
  $("#qm_movebox .list ul").css("max-width", scrW - 290 + "px");
  //外来担当の縦幅をmedicalにあわせる
  $("#today_dr .scroll").css("height", $("#medical1").outerHeight() -76 + "px");
  //外来担当のタイトルタブ横幅を下のテーブルにあわせる
  $("#Larea #today_dr .title th").css("width", $("#Larea #today_dr .scroll th").outerWidth() -2 + "px");

  //スクロール中の処理
  $(window).scroll(function pmove(e) {
	  scrH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; 
	  scrW = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;

    startPos =$(document).height() - footerHeight-pfHeight;

	//ページ一覧の縦幅
	$("#qm_content").css("height", scrH - 100 + "px");
	$("#qm_content .list").css("height", scrH - 150 + "px");

    scrTop = $(window).scrollTop();

    if (startPos < scrTop+scrH - pfHeight) {
      $("#qm_movebox").css("position", "static");
    }
    else {
    if ($.browser.msie && $.browser.version <= 6) {
          topPos = scrTop + scrH - pfHeight;
    	  $("#qm_movebox").css("position", "absolute")
			.css("top", topPos + "px");
      }
      else {
	        $("#qm_movebox").css("position", "fixed")
			.css("bottom", "0px");
      }
    }
  });

  //初期処理
  $(window).load(function() {
	startPos =$(document).height() - footerHeight-pfHeight;

	//ページ一覧の縦幅
	$("#qm_content").css("height", scrH - 100 + "px");
	$("#qm_content .list").css("height", scrH - 150 + "px");

    scrTop = $(window).scrollTop();

    if (startPos < scrTop+scrH - pfHeight) {
      $("#qm_movebox").css("position", "static");
    }
    else {
      if ($.browser.msie && $.browser.version <= 6) {
          topPos = scrTop + scrH - pfHeight;
    	  $("#qm_movebox").css("position", "absolute")
			.css("top", topPos + "px");
      }
      else {
	        $("#qm_movebox").css("position", "fixed")
			.css("bottom", "0px");
      }
    }
  });

  //ウィンドウリサイズ中の処理
  $(window).bind("resize",function() {
	  pmove();
  });


});

