window.addEvent('domready', function() {

//角丸初期設定
new kadoMaru('.kadomaru');

//ドロップダウン
dropDown();

//タブ丸初期設定
new tabMaru('.tabmaru');

//ロールオーバー
rollOver();
rollOverOpacity();

//Tips
toolTips();

//DisableOutline
disable_links_outline();

if(Browser.Engine.trident) {
DD_belatedPNG.fix('.iepngfix, .tip, .tip-top, .tip-bottom, .box-TL, .box-TC, .box-TR, .box-ML, .box-MR, .box-BL, .box-BC, .box-BR');
}

//contentSlide初期設定
new contentSlide('.slide', '.hide', '.toggle');

});


function showhide() {
	var showtoggle = $$(".showtoggle");
	var hidetoggle = $$(".hidetoggle").setProperty("class","current");
	var shExclude = $$(".campaign");
	showtoggle.addEvent('click',function(e){
		showtoggle.set('html', 'キャンペーン中の診療メニューのみ表示中').setProperty("class","current");
		hidetoggle.set('html', '全ての診療を表示');
		shExclude.setProperty("class","current-campaign");
		hidetoggle.removeProperty("class","current");
		$$(".unit ul li").setStyle('opacity',0);
		$$(shExclude).fade('in');
		e.stop();
	});
	hidetoggle.addEvent('click',function(e){
		showtoggle.set('html', 'キャンペーン中の診療のみ表示');
		hidetoggle.set('html', '全ての診療を表示中');
		$$(".unit ul li").fade('in');
		shExclude.removeProperty("class","current-campaign");
		hidetoggle.setProperty("class","current");
		showtoggle.removeProperty("class","current");
		e.stop();
	});
}


function contentSlide(csSlide, csHide, csToggle) {
	$$(csSlide).each(function(div){
		var link = div.getElement(csToggle);
		var hide = div.getElement(csHide);
		var fxcontentSlide = new Fx.Slide(hide, {duration: 240, mode: 'vertical'}).hide();
		link.addEvent('click', function(){fxcontentSlide.toggle();});
	});
}

//角丸
function kadoMaru(div) {
	$$(div).each(function(div){
		divId = div.getProperty('id');
		divClass = div.getProperty('class');
		div.setProperty('class', 'kadomaruContent').removeProperty('id');
		this.content = new Element('div').setProperties({'id': divId , 'class': divClass}).setStyles({'padding':0, 'background':'none'}).injectBefore(div).adopt(
			this.TL = new Element('div').setProperty('class', 'box-TL'),
			this.ML = new Element('div').setProperty('class', 'box-ML'),
			this.BL = new Element('div').setProperty('class', 'box-BL')
		);
		this.TR = new Element('div').setProperty('class', 'box-TR').injectInside(this.TL);
		this.TC = new Element('div').setProperty('class', 'box-TC').injectInside(this.TR);
		this.MR = new Element('div').setProperty('class', 'box-MR').injectInside(this.ML);
		this.MC = new Element('div').setProperty('class', 'box-MC').injectInside(this.MR);
		this.BR = new Element('div').setProperty('class', 'box-BR').injectInside(this.BL);
		this.BC = new Element('div').setProperty('class', 'box-BC').injectInside(this.BR);
		div.injectInside(this.MC);
	});
}

//タブ丸
function tabMaru(div) {
	$$(div).each(function(div){
		divId = div.getProperty('id');
		divClass = div.getProperty('class');
		div.setProperty('class', 'tabmaruContent').removeProperty('id');
		this.content = new Element('div').setProperties({'id': divId , 'class': divClass}).injectBefore(div).adopt(
		this.ML = new Element('div').setProperty('class', 'box-ML'),
		this.BL = new Element('div').setProperty('class', 'box-BL')
		);
		this.MR = new Element('div').setProperty('class', 'box-MR').injectInside(this.ML);
		this.MC = new Element('div').setProperty('class', 'box-MC').injectInside(this.MR);
		this.BR = new Element('div').setProperty('class', 'box-BR').injectInside(this.BL);
		this.BC = new Element('div').setProperty('class', 'box-BC').injectInside(this.BR);
		div.injectInside(this.MC);
	});
}

//タブメニュー
function tabMenu(Disp) {
var tabTitle = $$('.tab a');
var tabContent = $$('.tab_content');
var tabEffect = new Accordion(
tabTitle, tabContent, {
	onActive: function(tog){
		tog.addClass('current');
	},
	onBackground: function(tog){
		tog.removeClass('current');
	},
	duration: 300,
	alwaysHide: true,
	opacity: true,
	display:Disp,
	transition: Fx.Transitions.sineOut
});
}

//ロールオーバー
function rollOver() {
	$$('img.hover').each(function(img) {
		var src = img.getProperty('src');
		var extension = src.substring(src.lastIndexOf('.'),src.length)
		img.addEvent('mouseenter', function() { img.setProperty('src',src.replace(extension,'-hover' + extension)); });
		img.addEvent('mouseleave', function() { img.setProperty('src',src); });
	});
}

//ロールオーバーリンク（透明）
function rollOverOpacity() {
	$$('img.opacity').each(function(img) {
		img.addEvent('mouseenter', function() { img.fade(0.5); });
		img.addEvent('mouseleave', function() { img.fade(1); });
	});
}


//リンクの点線(クリックフォーカス)を消す
function disable_links_outline() {
	var blur = function () { this.blur() };
	for (var i = 0; i < document.links.length; i++)
	document.links[i].onfocus = blur;
}

//ドロップダウン
function dropDown() {
	var tog = $('gnavi').getElements('li.menu');
	tog.each( function( elem ){
		var list = elem.getElement('ul.links');
		var myFx = new Fx.Slide(list,{duration:300,transition: Fx.Transitions.Quint.easeOut}).hide();
		elem.addEvents({
			'mouseenter' : function(){
				tog.addClass('hover');
				list.setStyles({position:"static",visibility:"visible"});
				myFx.cancel();
				myFx.slideIn();
			},
			'mouseleave' : function(){
				tog.removeClass('hover');
				myFx.cancel();
				var t = function(){ myFx.slideOut(); }.delay(100);
			}
		});
	})
}

//Tips /*IEはフェードなしその他はフェード付き*/
function toolTips() {
	if(!Browser.Engine.trident) {
		var myTips = new Tips($$('.tips'), {
			initialize: function(){ this.tip.setStyle('opacity', 0); },
			onShow: function () { this.tip.fade('in'); },
			onHide: function() { this.tip.fade('out'); }
		});
	} else {
		var myTips = new Tips($$('.tips'), {});
	}
}
