jQuery(document).ready(function(){
	//画像ロールオーバー
	jQuery(".rollover").each(function(){
		this.orgsrc=jQuery(this).attr("src");
		if ((n = this.orgsrc.lastIndexOf(".")) != -1) {
			ext = this.orgsrc.substring(n);
		}
		this.newsrc=this.orgsrc.replace(ext, "_on"+ext);
		var newimg=new Image();
		newimg.src=this.newsrc;
		
		$(this).hover(
			function(){
				jQuery(this).attr("src",this.newsrc);
			},
			function(){
				jQuery(this).attr("src",this.orgsrc);
			}
		)
	});

	//文字サイズ変更
	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
	
	setTotop();

	jQuery("#searchBox").one("click", function(){
		if(jQuery("#searchBox").val()=="サイト内検索")
		{
			jQuery("#searchBox").val("");
		}
	});
	
	
	slidetime=400
	
	$("#gmenu-hospital-btn").click(function ()
	{
		if ($("#gmenu-hospital").is(":hidden"))
		{
			if (!$("#gmenu-depart").is(":hidden"))
				$("#gmenu-depart").slideUp(slidetime,function(){$("#gmenu-hospital").slideDown(slidetime);});
			else if (!$("#gmenu-treatment").is(":hidden"))
				$("#gmenu-treatment").slideUp(slidetime,function(){$("#gmenu-hospital").slideDown(slidetime);});
			else if (!$("#gmenu-recruit").is(":hidden"))
				$("#gmenu-recruit").slideUp(slidetime,function(){$("#gmenu-hospital").slideDown(slidetime);});	
			else if (!$("#gmenu-divison").is(":hidden"))
				$("#gmenu-division").slideUp(slidetime,function(){$("#gmenu-hospital").slideDown(slidetime);});	
			else
				$("#gmenu-hospital").slideDown(slidetime);
		}
		else
		{
			$("#gmenu-hospital").slideUp(slidetime);
		}
		return false;
	});
	
	$("#gmenu-treatment-btn").click(function ()
	{
		if ($("#gmenu-treatment").is(":hidden"))
		{
			if (!$("#gmenu-depart").is(":hidden"))
				$("#gmenu-depart").slideUp(slidetime,function(){$("#gmenu-treatment").slideDown(slidetime);});
			else if (!$("#gmenu-hospital").is(":hidden"))
				$("#gmenu-hospital").slideUp(slidetime,function(){$("#gmenu-treatment").slideDown(slidetime);});
			else if (!$("#gmenu-recruit").is(":hidden"))
				$("#gmenu-recruit").slideUp(slidetime,function(){$("#gmenu-treatment").slideDown(slidetime);});	
			else if (!$("#gmenu-divison").is(":hidden"))
				$("#gmenu-division").slideUp(slidetime,function(){$("#gmenu-treatment").slideDown(slidetime);});
			else
				$("#gmenu-treatment").slideDown(slidetime);
		}
		else
		{
			$("#gmenu-treatment").slideUp(slidetime);
		}
		return false;
	});
	
	$("#gmenu-depart-btn").click(function ()
	{
		if ($("#gmenu-depart").is(":hidden"))
		{
			if (!$("#gmenu-hospital").is(":hidden"))
				$("#gmenu-hospital").slideUp(slidetime,function(){$("#gmenu-depart").slideDown(slidetime);});
			else if (!$("#gmenu-treatment").is(":hidden"))
				$("#gmenu-treatment").slideUp(slidetime,function(){$("#gmenu-depart").slideDown(slidetime);});
			else if (!$("#gmenu-recruit").is(":hidden"))
				$("#gmenu-recruit").slideUp(slidetime,function(){$("#gmenu-depart").slideDown(slidetime);});	
			else if (!$("#gmenu-divison").is(":hidden"))
				$("#gmenu-division").slideUp(slidetime,function(){$("#gmenu-depart").slideDown(slidetime);});
			else
				$("#gmenu-depart").slideDown(slidetime);
		}
		else
		{
			$("#gmenu-depart").slideUp(slidetime);
		}
		return false;
	});
	
	$("#gmenu-division-btn").click(function ()
	{
		if ($("#gmenu-division").is(":hidden"))
		{
			if (!$("#gmenu-hospital").is(":hidden"))
				$("#gmenu-hospital").slideUp(slidetime,function(){$("#gmenu-division").slideDown(slidetime);});
			else if (!$("#gmenu-treatment").is(":hidden"))
				$("#gmenu-treatment").slideUp(slidetime,function(){$("#gmenu-division").slideDown(slidetime);});
			else if (!$("#gmenu-recruit").is(":hidden"))
				$("#gmenu-recruit").slideUp(slidetime,function(){$("#gmenu-division").slideDown(slidetime);});	
			else if (!$("#gmenu-depart").is(":hidden"))
				$("#gmenu-depart").slideUp(slidetime,function(){$("#gmenu-division").slideDown(slidetime);});	
			else
				$("#gmenu-division").slideDown(slidetime);
		}
		else
		{
			$("#gmenu-division").slideUp(slidetime);
		}
		return false;
	});	
	
	$("#gmenu-recruit-btn").click(function ()
	{
		if ($("#gmenu-recruit").is(":hidden"))
		{
			if (!$("#gmenu-hospital").is(":hidden"))
				$("#gmenu-hospital").slideUp(slidetime,function(){$("#gmenu-recruit").slideDown(slidetime);});
			else if (!$("#gmenu-treatment").is(":hidden"))
				$("#gmenu-treatment").slideUp(slidetime,function(){$("#gmenu-recruit").slideDown(slidetime);});
			else if (!$("#gmenu-depart").is(":hidden"))
				$("#gmenu-depart").slideUp(slidetime,function(){$("#gmenu-recruit").slideDown(slidetime);});	
			else if (!$("#gmenu-divison").is(":hidden"))
				$("#gmenu-division").slideUp(slidetime,function(){$("#gmenu-recruit").slideDown(slidetime);});
			else
				$("#gmenu-recruit").slideDown(slidetime);
		}
		else
		{
			$("#gmenu-recruit").slideUp(slidetime);
		}
		return false;
	});

	var floatDoctorBtn;
	jQuery("#float-menu-doctor img").each(function(){
		this.orgsrc=jQuery(this).attr("src");
		if ((n = this.orgsrc.lastIndexOf(".")) != -1) {
			ext = this.orgsrc.substring(n);
		}
		this.newsrc=this.orgsrc.replace(ext, "_close"+ext);
		var newimg=new Image();
		newimg.src=this.newsrc;
		floatDoctorBtn=this;
	});
	var floatNurseBtn;
	jQuery("#float-menu-nurse img").each(function(){
		this.orgsrc=jQuery(this).attr("src");
		if ((n = this.orgsrc.lastIndexOf(".")) != -1) {
			ext = this.orgsrc.substring(n);
		}
		this.newsrc=this.orgsrc.replace(ext, "_close"+ext);
		var newimg=new Image();
		newimg.src=this.newsrc;
		floatNurseBtn=this;
	});
	var floatCheckBtn;
	jQuery("#float-menu-nurse img").each(function(){
		this.orgsrc=jQuery(this).attr("src");
		if ((n = this.orgsrc.lastIndexOf(".")) != -1) {
			ext = this.orgsrc.substring(n);
		}
		this.newsrc=this.orgsrc.replace(ext, "_close"+ext);
		var newimg=new Image();
		newimg.src=this.newsrc;
		floatCheckBtn=this;
	});


	$("#float-menu-doctor a").click(function () {
		if(!floatDoctor&&!floatNurse&&!floatCheck)
		{
			jQuery(floatDoctorBtn).attr("src",floatDoctorBtn.newsrc);
			$("#float-doctor").show();
			$("#float-inner").css("left","-257px").css("width","282px").animate({ left: 0 }, 800,null,function(){
				floatDoctor=true;
			});
		}
		else if(floatDoctor)
		{
			jQuery(floatDoctorBtn).attr("src",floatDoctorBtn.orgsrc);
			$("#float-inner").animate({ left: -257 }, 800,null,function(){
				$("#float-doctor").hide();
				floatDoctor=false;
			});
		}
		else
		{
			jQuery(floatDoctorBtn).attr("src",floatDoctorBtn.newsrc);
			jQuery(floatNurseBtn).attr("src",floatNurseBtn.orgsrc);
			jQuery(floatCheckBtn).attr("src",floatCheckBtn.orgsrc);
			$("#float-inner").animate({ left: -257 }, 400,null,function(){
				$("#float-nurse").hide().css("left","0");
				$("#float-check").hide().css("left","0");
				floatNurse=false;
				floatCheck=false;
				$("#float-doctor").show();
				$("#float-inner").animate({ left: 0 }, 400,null,function(){
					floatDoctor=true;
				});
			});
		}
	});

	$("#float-menu-nurse a").click(function () {
		if(!floatDoctor&&!floatNurse&&!floatCheck)
		{
			jQuery(floatNurseBtn).attr("src",floatNurseBtn.newsrc);
			$("#float-nurse").show();
			$("#float-inner").css("left","-257px").css("width","282px").animate({ left: 0 }, 800,null,function(){
				floatNurse=true;
			});
		}
		else if(floatNurse)
		{
			jQuery(floatNurseBtn).attr("src",floatNurseBtn.orgsrc);
			$("#float-inner").animate({ left: -257 }, 800,null,function(){
				$("#float-nurse").hide();
				floatNurse=false;
			});
		}
		else
		{
			jQuery(floatNurseBtn).attr("src",floatNurseBtn.newsrc);
			jQuery(floatDoctorBtn).attr("src",floatDoctorBtn.orgsrc);
			jQuery(floatCheckBtn).attr("src",floatCheckBtn.orgsrc);
			$("#float-inner").animate({ left: -257 }, 400,null,function(){
				$("#float-doctor").hide().css("left","0");
				$("#float-check").hide().css("left","0");
				floatDoctor=false;
				floatCheck=false;
				$("#float-nurse").show();
				$("#float-inner").css("left","-257px").animate({ left: 0 }, 400,null,function(){
					floatNurse=true;
				});
			});
		}
	});

	$("#float-menu-check a").click(function () {
		if(!floatDoctor&&!floatNurse&&!floatCheck)
		{
			jQuery(floatCheckBtn).attr("src",floatCheckBtn.newsrc);
			$("#float-check").show();
			$("#float-inner").css("left","-257px").css("width","282px").animate({ left: 0 }, 800,null,function(){
				floatCheck=true;
			});
		}
		else if(floatCheck)
		{
			jQuery(floatCheckBtn).attr("src",floatCheckBtn.orgsrc);
			$("#float-inner").animate({ left: -257 }, 800,null,function(){
				$("#float-check").hide();
				floatCheck=false;
			});
		}
		else
		{
			jQuery(floatCheckBtn).attr("src",floatCheckBtn.newsrc);
			jQuery(floatDoctorBtn).attr("src",floatDoctorBtn.orgsrc);
			jQuery(floatNurseBtn).attr("src",floatNurseBtn.orgsrc);
			$("#float-inner").animate({ left: -257 }, 400,null,function(){
				$("#float-doctor").hide().css("left","0");
				$("#float-nurse").hide().css("left","0");
				floatDoctor=false;
				floatNurse=false;
				$("#float-check").show();
				$("#float-inner").css("left","-257px").animate({ left: 0 }, 400,null,function(){
					floatCheck=true;
				});
			});
		}
	});
});

$(window).scroll(function () {
	$(".float").stop();
	$(".float").animate({ top: $('html,body').scrollTop()+86 }, 1200)
});

var floatDoctor=false;
var floatNurse=false;
var floatCheck=false;

function readSchedule(pagename)
{
	jQuery.ajax({
		cache:true,
		url:"outpatient/schedule/parts.php?depart="+pagename,
		type:"GET",
		error: function(){
			alert("htmlファイルの読み込みに失敗しました");
		},
		dataType:"html",
		success:function(html){
			$("#scheduleTable").append(html);
		}
	});
}



function setTotop(){
	jQuery('a').click(function() {
		var jumpTo = jQuery(this).attr('href');
		if(jumpTo == '#top') {
			$('html,body').animate({ scrollTop: 0 }, 'slow')
			return false;
		}
		else if(jumpTo == '#') {
			return false;
		}
		else if(jumpTo.charAt(0) == '#') {
			$('html,body').animate({ scrollTop: jQuery(jumpTo).offset().top }, 'slow')
			return false;
		}
	});
}





$(window).unload(function(){
  var title = getActiveStyleSheet();
  createCookie("style", title, 0);
});


function setActiveStyleSheet(title) {
	jQuery("link[rel*='stylesheet'][title]").each(function(){
		this.disabled = true;
		this.disabled = jQuery(this).attr("title")!=title;
	});
}


function getActiveStyleSheet() {
	var titlename = null;
	jQuery("link[rel*='stylesheet'][title]").each(function(){
	if(!this.disabled)
		titlename = jQuery(this).attr("title");
	});
	return titlename;
}


function getPreferredStyleSheet() {
	var titlename = null;
	jQuery("link[rel^='stylesheet'][title]").each(function(){
		titlename = jQuery(this).attr("title");
	});
	return titlename;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function popup(href){
	window.open(href, 'popup', 'width=600, height=620, menubar=yes, toolbar=yes, scrollbars=yes');
}



$(document).ready(function() {
	$(".navi2 dt").hover(function(){
		$(this).css("cursor","pointer"); 
	},function(){
		$(this).css("cursor","default"); 
		});
	$(".navi2 dd").css("display","none");
	$(".navi2 dt").click(function(){
		$(this).next().slideToggle("fast");
		});
});

