/*

Last UpDate 2010-01-06

*/

$(function(){
	//現在居るファイル名	   
	var currentFile = location.href.split('/').pop();
	
	//ua取得
	var ua = navigator.userAgent;
	
	/*
	//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 || ua.indexOf('IE 7') > -1){

		//サムネールを内包する、.table-cell内で、display:table-cell;vertical-align:middle;のように表示する
		$('.table-cell').each(function(){
			var x = $('img',this).width();
			var y = $('img',this).height();

			var flag = this.nodeName.match(/a/i); //対象ノードがaかどうか判断
			if(flag){
				x += 4; //何故かieはaに内包されている時4px少なく算出する為+4
				y += 4; //何故かieはaに内包されている時4px少なく算出する為+4
			}
			
			if(x > y){
				$(this).css({display:'block'});
				var boxY = $(this).height();
				if(boxY != y){
					var rePadding = Math.floor((boxY - y) / 2);
					var reHeight = boxY - rePadding;
					$(this).css({paddingTop:rePadding+'px',height:reHeight+'px'});
				}else if(flag){
					$(this).css({display:'inline'});
				}
			}
		});
	}
	
	//透過条件設定
	/*if(ua.indexOf('IE 6') > -1){
		DD_belatedPNG.fix('.pngfix');
	}*/
	
	//flatHeights設定
	/*if($('ul').is('.item-list')){
		var sets = [], temp = [];
		$('ul#thumbnail > li').each(function(i) {
			temp.push(this);
			if (i % 3 == 2) {
				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{
		$('.lb a[href$=".jpg"],.lb a[href$=".png"],.lb a[href$=".gif"]').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){
	}
	
});

//* Bs-Studio Add 2010/05/12 
$(document).ready(function(){
		
		// index.html/newa_list.html 新着情報のテーブル偶数行にクラス追加
	 $('.index04 table tr:odd').addClass('even');
	 $('.news_list01 table tr:odd').addClass('even');
		
		//photo.html の画像表示
		
		var list01 = $(".phtBox01 ul li");
		var list02 = $(".phtBox02 ul li");
		var list03 = $(".phtBox03 ul li");
		
		var list_f01 = $(".phtBox01 ul li:first");
		var list_f02 = $(".phtBox02 ul li:first");
		var list_f03 = $(".phtBox03 ul li:first");
		
		list_f01.addClass("select");
		list01.hover(function(){
			$(this).css({cursor:'pointer',opacity: '0.2',filter: 'alpha(opacity=20)'});
		},function(){
			$(this).css({cursor:'default',opacity: '1',filter: 'alpha(opacity=100)'});
		});
		
		list_f02.addClass("select");
		list02.hover(function(){
			$(this).css({cursor:'pointer',opacity: '0.2',filter: 'alpha(opacity=20)'});
		},function(){
			$(this).css({cursor:'default',opacity: '1',filter: 'alpha(opacity=100)'});
		});
		
		list_f03.addClass("select");
		list03.hover(function(){
			$(this).css({cursor:'pointer',opacity: '0.2',filter: 'alpha(opacity=20)'});
		},function(){
			$(this).css({cursor:'default',opacity: '1',filter: 'alpha(opacity=100)'});
		});
		
		
		var box01 = $(".phtBox01 div.phtGallery > div");
		var box_f01 = $(".phtBox01 div.phtGallery > div:first");
		
		var box02 = $(".phtBox02 div.phtGallery > div");
		var box_f02 = $(".phtBox02 div.phtGallery > div:first");
		
		var box03 = $(".phtBox03 div.phtGallery > div");
		var box_f03 = $(".phtBox03 div.phtGallery > div:first");
		
		
		box01.hide();
		box_f01.show();
		
		box02.hide();
		box_f02.show();
		
		box03.hide();
		box_f03.show();
		
		var list_s01 = $(".phtBox01 ul > li");
		var list_s02 = $(".phtBox02 ul > li");
		var list_s03 = $(".phtBox03 ul > li");
	
		list_s01.click(function () {
		list_s01.removeClass("select");
		$(this).addClass("select");
		box01.hide();
		box01.eq(list_s01.index(this)).fadeIn();
		});
		
		list_s02.click(function () {
		list_s02.removeClass("select");
		$(this).addClass("select");
		box02.hide();
		box02.eq(list_s02.index(this)).fadeIn();
		});
		
		list_s03.click(function () {
		list_s03.removeClass("select");
		$(this).addClass("select");
		box03.hide();
		box03.eq(list_s03.index(this)).fadeIn();
	});
	
});

