MJL.event.add(window, "load", function(){
	// MJL に関係するコードはこの中に記述
	
	// -------------------------------------------------- ロールオーバー
	MJL.enable.rollover("roll", {disable : "unroll", active : "active"});
	
	// -------------------------------------------------- 高さ調整
	MJL.enable.heightEqualizer("lyt_col2",{
		groupBy:2,
		collect:function(parent){ return MJL.getElementsByClassName(parent, "block_heading"); }
	});
	MJL.enable.heightEqualizer("lyt_col2",{
		groupBy:2,
		collect:function(parent){ return MJL.getElementsByClassName(parent, "hdg_03_block"); }
	});
	MJL.enable.heightEqualizer("block_intro",{
		groupBy:2,
		collect:function(parent){ return MJL.getElementsByClassName(parent, "linkList_02"); }
	});
	MJL.enable.heightEqualizer("block_intro",{
		groupBy:2,
		collect:function(parent){ return MJL.getElementsByClassName(parent, "lyt_imgL"); }
	});
	
	
	// -------------------------------------------------- 画像とテキスト (based on jQuery)
	// 画像とテキストの並列処理を行なう関数を返す高階関数
	function _fitImgBlockWidth(side){
		return function(){
			var obj = $(this),
				imgBlock = $(".image:first", obj),
				imgWidth = $("img", imgBlock).outerWidth();
			imgBlock.css("width", imgWidth+"px");
		};
	}
	$(".lyt_imgL").each(_fitImgBlockWidth());
	$(".lyt_imgR").each(_fitImgBlockWidth());
	
});


// MJL と無関係なコードはこの先に記述

'jQuery' in window && $(function(){
	
	// -------------------------------------------------- IE8以下の lyt_col2 の改行
	if(!jQuery.support.leadingWhitespace){ $(".lyt_col2 > .col:nth-child(2n+1)").css("clear","left") }
	
	// -------------------------------------------------- グローバルナビのカレント表示制御
	(function(){
		var bodyId = $(document.body).attr('id'),
			condSrc = /(\.[a-z]{3})$/,					// img 要素 src 属性置換条件
			condCategory = /(^.+?navGlobal_)(.+?)(\.png$)/;	// img 要素から category を抽出する置換条件
		$('#navGlobal img').each(function(){
			var obj = $(this),
				category = obj.attr('src').replace(condCategory, '$2'),
				ret = true;
			
			// 一致するメインメニューがあればアクティブ化して終了
			if(bodyId === category){
				obj.addClass('active');  // ロールオーバー無効化
				ret = false;
			}
			
			// 何もなければ次をチェック
			return ret;
		});
	})();
	
	// -------------------------------------------------- ライトボックス - fancybox の設定
	if("fancybox" in window){		// プラグインの有無チェック
		$("a.gallery").fancybox({'titlePosition':'inside'});
		$("a[rel=gallery_01], a[rel=gallery_02], a[rel=gallery_03], a[rel=gallery_04], a[rel=gallery_05]").fancybox({
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'titlePosition'	: 'inside',
			'titleFormat'	: function(title, currentArray, currentIndex, currentOpts){
				return ' <span class="caption">'+(title.length? title : '')+'</span> '
					+(currentIndex+1) + ' / ' + currentArray.length + '<p class="note"><a href="#" onclick="$.fancybox.close();return false">閉じる</a> <span>or</span> Esc key</p>';
			}
		});
	}
	
	// -------------------------------------------------- jCarouselLite プラグイン設定
	if("jCarouselLite" in window){	// プラグインの有無チェック
		$('.carousel ul').each(function(){
			$(this).wrap('<div class="carousel-action"></div>');
			
			var _jCL_target = $('.carousel-action'),
				_jCL_parent = _jCL_target.parent('div');
			
			_jCL_parent
				.append('<button class="prev" title="前へ">前へ</button>')
				.append('<button class="next" title="次へ">次へ</button>');
			
			_jCL_target.jCarouselLite({
				btnNext: '.next',
				btnPrev: '.prev',
				speed: 555,
				visible: 4
			});
			
			// Vertical Positioning
			var _jCL_button = _jCL_parent.children('button');
			_jCL_button.css('top', parseInt(_jCL_parent.height()/2-_jCL_button.outerHeight()/2));
		});
	}
	
	// -------------------------------------------------- テキストエリアのサイズ px指定
	$("#contents form input[type='text'], #contents form textarea").each( function(){
		if( (_width=$(this).attr("size")) || (_width=$(this).attr("cols")) )
			$(this).css({width: Math.round(_width*7.2)+"px"});
		if(_height = $(this).attr("rows")) $(this).css({height: Math.round(_height*14)+"px"});
	});

});

