/**
 * @name main.js
 * @fileOverview
 * @version 1.0
 * @description
 * <p>(c) FOURDIGIT Inc. Licensed <a href="http://ja.wikipedia.org/wiki/GNU_General_Public_License">GNU General Public License</a>.</p>
 */
//他ライブラリと共存する場合、下の一行削除($無効化)
//jQuery.noConflict();
(function($){
	var config = function () {
	//bodyのクラスにブラウザ情報を追加
		$.addClassUA();
	//easyOverのターゲット設定
		$("img.ahover, .ahoverArea img").easyOver();
	//IE5,6にてPNG有効化 (pngfixの読み込みが必要)
		$("img[src$=png],p.png").enablePNG();
	//Flash
		//$("object, embed").enableFlash();
	//ポップアップリンクに置換
		$(".commonPop").easyPop();
	//他ドメインリンク時にpageTracker有効化
		//$("a,area").blankLogToGoogle();
	//アンカーリンクをスムージング
		$("a[href^=#]").smoothScroll();
	}
	//onload
	$(function() {
		config();
		switch (jQuery("body").attr("id")) {
			case "page-fair":
				$('#page-fair div.overlayContent').fadeIn('slow');
				$('#page-fair p.close a').click(function(){ $('#page-fair div.overlayContent').fadeOut("1000"); });
			break;
			case "pageID":
				//eachPageFunction
			break;
		}

		/* list - .firstItem / .lastItem */
		$('ul,ol').each(function(){
			$(this).find('li:first').addClass('firstItem');
			$(this).find('li:last').addClass('lastItem');
		});

		/* .allHover - エリア内にリンクがひとつの場合のみ */
		$('.allHover').hover(
			function(){
				$(this).addClass('hoverArea');
			},
			function(){
				$(this).removeClass('hoverArea');
			}
		);
		$('.allHover').click(
			function(){
				if($(this).find('a.commonPop')[0]){
					$(this).find('a').click();
				}else{
					if($(this).find('a')[0].target == "_blank") {
						window.open($(this).find('a')[0].href);
					}else{
						location.href = $(this).find('a')[0].href;
					}
				}		
			}
		);

		/* daytable */
		$('div.daytable,.busTimeTable,.commonTable').find('tr:odd').addClass('oddLine');
		$('.commonTable').find('tr').each(function(){
			$(this).find('th:first,td:first').addClass('firstItem');
			$(this).find('th:last,td:last').addClass('lastItem');
		});
		$('#page-fair .daytable tr td:nth-child(6),#page-fair .daytable tr td:nth-child(7)').addClass('commonHoliday');
		$('#page-fair .daytable tr td:nth-child(7)').addClass('sunday');
		/* fairTable */
		$('.fairTable').find('tr:first').addClass('firstLine');

		/* daytableS */
		$('.daytableS td:has(a)').each(function(){$(this).addClass('hasEvent');});
		/* 当日予約する場合 */
		$('.daytableS td.today:has(a)').hover(
			function(){
				$(this).find('a').blur();
				$(this).addClass('hasEventToday');
			},function(){
				$(this).removeClass('hasEventToday');
			}
		);

		/* #photoset */
		$('#photoset #qaList ul.fr > li:odd,.commonList > li:odd').addClass('oddLine');
		$('#photoset #qaList ul.fl > li:even,.voiceList > li:even').addClass('evenLine');
		$('#photoset #qaList dt').hover(
			function(){
				$(this).addClass('ov');
			},
			function(){
				$(this).removeClass('ov');
			}
		);

		$('#photoset #qaList ul.qaList li').toggle(
			function(){
				$(this).addClass('on');
				$(this).find('dd').slideDown(150);
			},
			function(){
				$(this).removeClass('on');
				$(this).find('dd').slideUp(150);
			}
		);

		/* priceTable */
		$('div.priceTable th,div.priceTable td').wrapInner('<span></span>');

		/* chapel */
		$('.thumbLists li:nth-child(1)').addClass('thumb01');
		$('.thumbLists li:nth-child(2)').addClass('thumb02');
		$('.thumbLists li:nth-child(3)').addClass('thumb03');
		$('.thumbLists li:nth-child(4)').addClass('thumb04');
		$('.thumbLists li:nth-child(5)').addClass('thumb05');

	/* form */
		if($('#form')[0]) {
		/* form - on */
			$('#form input,#form textarea').focus(function(){$(this).addClass('onThis');});
			$('#form input,#form textarea').blur(function(){$(this).removeClass('onThis');});

		/* form - textType or checkType */
			$('#form input[type=checkbox],#form input[type=radio]').addClass('inputBtns');
			$('#form input[type=text]').addClass('textInput');
	
		/* form - submit & reset */
			$('#submitBtn').click(function(){$('#submitForm').click();});
			$('#resetBtn').click(function(){$('#resetForm').click();});

		/* form - selectPlace */
			$('#form .selectPlace label').hover(
				function(){$(this).addClass('ovThis');},
				function(){$(this).removeClass('ovThis');}
			);
	
		/* form - hasQuestion */
			$('#form #question01').click(function(){$('#hasQuestion').slideDown();});
			$('#form #question02').click(function(){$('#hasQuestion').slideUp();});
		}

		//対象の要素をスクロールに追従するようにする
		$("div.commonPage #frContent:has(div.moveMenu)").css('top','225px').fixPosition("endInfo","slow");
	});
})(jQuery);
