/*

Last UpDate 2010-01-06

jquery-extension.js =
function.js(2010-01-06) + いつもの（ウィンクのみ,ゼブラ,fancybox,slimbox,flatHeightsの説明追加分)

*/

$(function(){
	//現在居るファイル名	   
	var currentFile = location.href.split('/').pop();
	
	//ua取得
	var ua = navigator.userAgent;

	/* ウィンク効果のみ */
	$("#aside a img,#mainnav a img").hover(function(){
		$(this).css("opacity", "0.6");
		$(this).css("filter", "alpha(opacity=20)");
		$(this).fadeTo("slow", 1.0);
	});

	//fancybox
	try{
		$("#detail div a").fancybox({
			'zoomOpacity' : true,'overlayShow' : false,'zoomSpeedIn' : 500,'zoomSpeedOut' : 500});
	}catch(e){}
		
	/* slimbox */
	try{
	$("div a").slimbox({/* Put custom options here */}, null, function(el) {
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));});
	}catch(e){}

	//classが、'nav'で終わるulの、最後のliに、'last'クラスを付ける
	$('ul[class$="nav"]').each(function(){
		$('li:last',this).addClass('last');
	});
	
	//classが、'list'で終わるulの、偶数の要素に、'even'クラスを付ける
	$('#news dl:nth-child(odd)').addClass('odd');
	
	//classが、'table'で終わるテーブルの、偶数trに、'even'クラスを付ける
	$('table[class$="table"] tr:nth-child(even)').addClass('even');
	
	//rollover
	$('a img').each(function(){
		var imgSrc = $(this).attr('src');
		//smartRollover
		if(imgSrc.match(/(.*)_off(\..*)/)){
			var repSrc = RegExp.$1+'_on'+RegExp.$2;
			$('<img />').attr('src',repSrc);
			$(this).hover(function(){
				$(this).attr('src',repSrc);
				$(this).css({opacity: '1',filter: 'alpha(opacity=100)'});
			},function(){
				$(this).attr('src',imgSrc);
			});
			
		}else if(imgSrc.match(/(.*)_on(\..*)/)){
			
		//ロールオーバーが無い場合は、透明度80%
		}else if(!$(this).hasClass('not')){
			$(this).hover(function(){
					$(this).css({
						opacity: '0.8',
						filter: 'alpha(opacity=80)'
					});
			},function(){
					$(this).css({
						opacity: '1',
						filter: 'alpha(opacity=100)'
					});
			}
			
			);
		}
	});

	//透過条件設定 pngfixクラスを持つ要素に透過を適用する
	/*if(ua.indexOf('IE 6') > -1){
		DD_belatedPNG.fix('.pngfix');
	}*/

	/* div直下の指定要素を3つごとにdivでwrapする */
	/*
	if($('div').is('#album')){
		//要素の全体数をセット
		var maxcount = $('#album dl').length -1;
		
		//グループ数(カレント)計算用変数初期化
		var groupnum = 0;

		$('#album dl').each(function(i) {
			//臨時で振る制御用class名生成
			var classname = "class"+groupnum;
			
			//目印になるクラスを振ってみる
			$(this).addClass(classname);
			
			//3つごとに…	
			if (i % 3 == 2) {
				//グループ数(カレント)計算
				groupnum += 1;
				
				//グループが最後の3つだったら、wrapしない
				if(maxcount != i){
				$("."+classname).wrapAll('<div class="clearfix"></div>');
				}
				
				//wrap時の目印にしてたclassを削除(起点、一個前、二個前)
				$(this).removeClass(classname);
				$(this).prev().removeClass(classname);
				$(this).prev().prev().removeClass(classname);
			}
		});
	}
	*/
	
	//submit押した感 & ウィンクorsmartrollover
	$('form p.submit input').mousedown(function(){
		$(this).css({position:'relative',top:'1px',left:'1px'});
	}).mouseup(function(){
		$(this).css({position:'static'});
	}).mouseout(function(){
		$(this).css({position:'static'});
	})
	  /* ウィンク版 */
	  .hover(function(){
		$(this).css({opacity:0.2});
		$(this).fadeTo('slow',1.0);

	  /* smartrollover版　*/
	  /*.hover(function(){
		$(this).attr('src',$(this).attr('src').replace(/^(.*)_off.(.*)$/,'$1_on.$2'));
	},function(){
		$(this).attr('src',$(this).attr('src').replace(/^(.*)_on.(.*)$/,'$1_off.$2'));*/
	});


	//jQuery.AutoHeight
	if($('div').is('#category')){
	$("#category .itemlist dl").autoHeight({column:3});
	}

	/*
	//jQuery.Autoheight - IE6文字拡大対応版 http://www.tinybeans.net/blog/2010/07/03-093314.html //

	if($('div').is('#category')){

		var e = document.createElement("div");
		var s = document.createTextNode("S");
		e.appendChild(s);
		e.style.visibility="hidden"
		e.style.position="absolute"
		e.style.top="0";
		document.body.appendChild(e);
		var defHeight = e.offsetHeight;
		checkBoxSize = function(){
				if(defHeight != e.offsetHeight){
					$('#category dl').autoHeight({reset:'reset'});
					$('#category dl').autoHeight({column:4});
					defHeight= e.offsetHeight;
				}
		}
		$('#category dl').autoHeight({column:4});
		setInterval(checkBoxSize,1000);
	
	}	
	*/

	/* ddの奇数にoddクラスをつける */
	$('#reserve table td').filter(function(i){
		if(i % 7 == 0) return this;
	}).addClass('sun');

	/* ddの奇数にoddクラスをつける */
	$('#reserve table td').filter(function(i){
		if(i % 7 == 6) return this;
	}).addClass('sat');

	/* ddの奇数にoddクラスをつける */
	$('#reserve table td').filter(function(i){
		if(i % 7 == 1) return this;
	}).addClass('holiday');

	/* ddの奇数にoddクラスをつける */
	$('#reserve table td').filter(function(i){
		if(i % 7 == 4) return this;
	}).addClass('holiday');

});
