$(function(){

//フォントサイズ設定
	var FontSize = [];
	FontSize["S"] = '14';
	FontSize["M"] = '14';
	FontSize["L"] = '16';

//フォントサイズ変更ボタン設定
	var ChangeBtn = "#fontSize img";
	var SearchImg = ["#fontS img","#fontM img","#fontL img"];

//フォントサイズ変更関数
	function FontSizeSet(fs){
		$('#main').css("font-size",fs+"px");
		$('h2','#main').css("font-size",fs+"px");
		$('h3','#main').css("font-size",fs+"px");
		$('p','#main').css("font-size",fs+"px");
		$('table','#main').css("font-size",fs+"px");
		$('ul','#main').css("font-size",fs+"px");
		$('dt','#main').css("font-size",fs+"px");
		$('dd','#main').css("font-size",fs+"px");
		$('dl','#main').css("font-size",fs+"px");
		$('li','#main').css("font-size",fs+"px");
	};

//画像置換関数
	function OnFont(){
		$(this).attr("src",$(this).attr("src"));
	};
	function OvFont(io){
		$(io).attr("src",$(io).attr("src").replace(/^(.+)(\.[a-z]+)$/,"$1_ov$2"));
	};
	function OffFont(io){
		$(io).attr("src",$(io).attr("src").replace(/^(.+)_ov(\.[a-z]+)$/,"$1$2"));
	};

//クッキー設定関数
	function FontCookie(ck){
		$.cookie("fontsize",ck,{path:'/',expires:7});
	};

//クッキー確認関数
	function CookieChack(fs){
		return $.cookie("fontsize")==fs;
	};

//ロード時表示設定
	function LoadFont(fs,si){
		FontSizeSet(FontSize[fs]);
		OvFont(SearchImg[si]);
	};
	if(CookieChack("fontS")){
		LoadFont("S",0);
	}
	else if(CookieChack("fontM")){
		LoadFont("M",1);
	}
	else if(CookieChack("fontL")){
		LoadFont("L",2);
	}
	else {
		FontCookie("fontS");
		LoadFont("S",0);
	};

//画像プリロード設定
	function ImgPreload(io){
		$(ChangeBtn).not(SearchImg[io]).each(function(){
			$("<img>").attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/,"$1_ov$2"));
		});
	};
	if(CookieChack("fontS")){
		ImgPreload(0);
	}
	else if(CookieChack("fontM")){
		ImgPreload(1);
	}
	else if(CookieChack("fontL")){
		ImgPreload(2);
	};

//ホバーイベント
	$(ChangeBtn)
	.hover(
	function(){
		if(!$(this).attr("src").match("_ov")){
			OvFont(this);
		};
	},
	function(){
		if($(this).attr("src").match("_ov")){
			if(CookieChack("fontS")){
				OffFont(SearchImg[1]),OffFont(SearchImg[2]);
			}
			else if(CookieChack("fontM")){
				OffFont(SearchImg[0]),OffFont(SearchImg[2]);
			}
			else if(CookieChack("fontL")){
				OffFont(SearchImg[0]),OffFont(SearchImg[1]);
			};
		};
	});

//クリックイベント
	function ClickFont(ck,fs,io1,io2){
		FontCookie(ck);
		FontSizeSet(FontSize[fs]);
		OffFont(SearchImg[io1]),OffFont(SearchImg[io2]);
		OnFont();
	};
	$(SearchImg[0]).click(function(){
		ClickFont("fontS","S",1,2);
	});
	$(SearchImg[1]).click(function(){
		ClickFont("fontM","M",0,2);
	});
	$(SearchImg[2]).click(function(){
		ClickFont("fontL","L",0,1);
	});
});

jQuery(document).ready(function($) {
	var postfix = '_on';
	$('#nav-global a img').not('[src*="'+ postfix +'."]').each(function() {
		var img = $(this);
		var src = img.attr('src');
		var src_on = src.substr(0, src.lastIndexOf('.'))
		           + postfix
		           + src.substring(src.lastIndexOf('.'));
		$('<img>').attr('src', src_on);
		img.hover(
			function() {
				img.attr('src', src_on);
			},
			function() {
				img.attr('src', src);
			}
		);
	});
});
jQuery(document).ready(function($) {
	var postfix = '_on';
	$('#clinical-indicator-index a img').not('[src*="'+ postfix +'."]').each(function() {
		var img = $(this);
		var src = img.attr('src');
		var src_on = src.substr(0, src.lastIndexOf('.'))
		           + postfix
		           + src.substring(src.lastIndexOf('.'));
		$('<img>').attr('src', src_on);
		img.hover(
			function() {
				img.attr('src', src_on);
			},
			function() {
				img.attr('src', src);
			}
		);
	});
});


(function($) {
	
	$.fn.opOver = function(op,oa,durationp,durationa){
		
		var c = {
			op:op? op:1.0,
			oa:oa? oa:0.6,
			durationp:durationp? durationp:'fast',
			durationa:durationa? durationa:'fast'
		};
		

		$(this).each(function(){
			$(this).css({
					opacity: c.op,
					filter: "alpha(opacity="+c.op*100+")"
				}).hover(function(){
					$(this).fadeTo(c.durationp,c.oa);
				},function(){
					$(this).fadeTo(c.durationa,c.op);
				})
		});
	},
	
	$.fn.wink = function(durationp,op,oa){

		var c = {
			durationp:durationp? durationp:'slow',
			op:op? op:1.0,
			oa:oa? oa:0.2
		};
		
		$(this).each(function(){
			$(this)	.css({
					opacity: c.op,
					filter: "alpha(opacity="+c.op*100+")"
				}).hover(function(){
				$(this).css({
					opacity: c.oa,
					filter: "alpha(opacity="+c.oa*100+")"
				});
				$(this).fadeTo(c.durationp,c.op);
			},function(){
				$(this).css({
					opacity: c.op,
					filter: "alpha(opacity="+c.op*100+")"
				});
			})
		});
	}
	
})(jQuery);

(function($) {
$(function() {
 
  $('#banner a img').opOver();
  $('#hos-link a img').opOver();
  $('#in-hos-link a img').opOver();
  $('#recruit-banner a img').opOver();
  $('#news p.view a img').opOver();
  $('#kouza p.view a img').opOver();
  $('p.pagetop a img').opOver();

});
})(jQuery);
