/*

Last UpDate 2010-01-06

*/

$(function(){
	//現在居るファイル名	   
	var currentFile = location.href.split('/').pop();
	
	//ua取得
	var ua = navigator.userAgent;
	
	//カレンダー制御
	if($('dd').is('.calendar')){
		$('dd.calendar table').each(function(){
			var keyDays = {};							 
			keyDays.holiday = $(this).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 'holiday':
								self.addClass('holiday');
								break;
							}
						}
					});
				});
			});
		});
	}

	/*
	//classが、'nav'で終わるulの、最後のliに、'last'クラスを付ける
	$('ul[class$="nav"]').each(function(){
		$('li:last',this).addClass('last');
	});
	*/
	
	//classが、'news'で終わるdivの、偶数dlに、'even'クラスを付ける
	$('div[class$="news"] dl:nth-child(even)').addClass('even');
	
	//classが、'calTbl'で終わるtableの、2/7のtrに、'off'クラスを付ける
	//$('table[class$="calTbl"] td:nth-child(7n+2)').addClass('off');
	
	//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(!$(this).hasClass('not')){
			$(this).hover(function(){
				if((imgSrc.indexOf('_off') == -1) && (imgSrc.indexOf('_on') == -1)){
					$(this).css({
						opacity: '0.2',
						filter: 'alpha(opacity=20)'
					});
					$(this).fadeTo('slow',1.0);
				}else{
					$(this).css({opacity: '1',filter: 'alpha(opacity=100)'});
				}
			});
		*/
		}
		
	});
	
	//#footerコピーライトの年を動的に書き換え
	var year = new Date().getFullYear();
	var copyTxt = $('#footer address').html();
	if(copyTxt.match(/([0-9]{4}-)?([0-9]{4})/) != null){
		var repTxt = copyTxt.replace(RegExp.$2,year);
		$('#footer address').html(repTxt);
	}
		
	//透過条件設定
	/*if(ua.indexOf('IE 6') > -1){
		DD_belatedPNG.fix('.pngfix');
	}*/

	/*flatHeights設定 http://www.akatsukinishisu.net/itazuragaki/js/i20070801.html
		1.dl自体をtemp配列に入れる（dlの個数分）
		2.i%3(3つごとに）temp配列をsets配列に入れる。
		3.tempを空にする
		4.sets配列を左から順に見ていき、sets[0][0]～sets[0][2]までの高さを揃える
		
		*iは0からスタート
	    *setsは二次元配列なので、一つの枠に、temp配列が入る　
	*/

	//flatHeights設定
	if($('ul').is('.hair')){
		var sets = [], temp = [];
		$('ul.hair li').each(function(i) {
			temp.push(this);
			if (i % 4 == 3) {
				sets.push(temp);
				temp = [];
			}
		});
		if (temp.length) sets.push(temp);
	
		/* 各組ごとに高さ揃え */
		$.each(sets, function() {
			$(this).flatHeights();
		});
	}
	
	//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'));*/
	});
	
	//lightBox
	try{
		$('.hair li a').lightBox({
			overlayBgColor: '#000',
			overlayOpacity: 0.8,
			imageLoading:   'js/images/lightbox-ico-loading.gif',
			imageBtnPrev:   'js/images/lightbox-btn-prev.gif',
			imageBtnNext:   'js/images/lightbox-btn-next.gif',
			imageBtnClose:  'js/images/lightbox-btn-close.gif',
			imageBlank:     'js/images/lightbox-blank.gif'
		});
	}catch(error){
	}
	
});
