/*

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;
	var currentURL = location.href;

	$("ul.nav li a").each(function(){
		var target = $(this).attr("href");
		var re = new RegExp(target + "$");
		
		if(currentURL.match(re) != null ){
			$("img",this).attr("src",$("img",this).attr("src").replace("_off","_on"));
		}
	});

	/*
	$("#side dl dd a").each(function(){
		var target = $(this).attr("href");
		var re = new RegExp(target + "$");
		
		if(currentURL.match(re) != null ){
			$(this).addClass("current");
		}
	});
	*/
	
	/* ウィンク効果のみ */
	/*
	$("#sidecolumn a img").hover(function(){
		$(this).css("opacity", "0.2");
		$(this).css("filter", "alpha(opacity=20)");
		$(this).fadeTo("slow", 1.0);
	});
	*/
	
	/* ddの奇数にoddクラスをつける */
	/*
	$('#ind04 dd').filter(function(i){
		alert(i);
		if(i % 2 == 0) return this;
	}).addClass('odd');
	*/
	
	//fancybox
	try{
		$("#detail div a").fancybox({
			'zoomOpacity' : true,'overlayShow' : false,'zoomSpeedIn' : 500,'zoomSpeedOut' : 500});
	}catch(e){}
	
	/*
	//classが、'nav'で終わるulの、最後のliに、'last'クラスを付ける
	$('ul[class$="nav"]').each(function(){
		$('li:last',this).addClass('last');
	});
	
	//classが、'list'で終わるulの、偶数の要素に、'even'クラスを付ける
	$('ul[class$="list"] li:nth-child(even)').addClass('even');
	
	//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);
	
	}	
	*/

	
	//lightBox
	/*
	try{
		$('.lb a[href$=".jpg"],.lb a[href$=".png"],.lb a[href$=".gif"]').lightBox({
			overlayBgColor: '#000',
			overlayOpacity: 0.8,
			imageLoading:   '/images/lightbox-ico-loading.gif',
			imageBtnPrev:   '/images/lightbox-btn-prev.gif',
			imageBtnNext:   '/images/lightbox-btn-next.gif',
			imageBtnClose:  '/images/lightbox-btn-close.gif',
			imageBlank:     '/images/lightbox-blank.gif'
		});
	}catch(error){
	}
	*/
	
	
	//カレンダー制御(MTCalenderの装飾js)
	/*if($('dd').is('.availability')){
		$('dd.availability table').each(function(){
			var keyDays = {};							 
			keyDays.available = $(this).next().val().split(',');
			keyDays.waning = $(this).next().next().val().split(',');
			
			$('td',this).each(function(){
				var self = $(this);
				var day = self.text();
				$.each(keyDays,function(key,ary){
					$.each(ary,function(i,val){
						if(day == val){
							switch(key){
								case 'available':
								self.addClass('available');
								break;
								case 'waning':
								self.addClass('waning');
								break;
							}
						}
					});
				});
			});
		});
	}*/

});
