/*

Last UpDate 2009-10-14

*/

$(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が、'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 _off の付いた画像をマウスオーバーで _on の付いた画像に変える
	$('a img').each(function(){
		var imgSrc = $(this).attr('src');
		//smartRollover
		if(imgSrc.match(/(.*)_off(\.gif|\.jpg)/g)){
			var repSrc = RegExp.$1+'_on'+RegExp.$2;
			$(this).hover(function(){
				$(this).attr('src',repSrc);
				$(this).css({opacity: '1',filter: 'alpha(opacity=100)'});
			},function(){
				$(this).attr('src',imgSrc);
			});
		//ウィンク効果
		}else{
			$(this).hover(function(){
				var parentId = $(this).parent().attr("id");
				if(parentId != "logo"){
					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)'});
					}
				}
			});
		}
	});
	
	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();
			if(x > y){
				$(this).css({display:'block'});
				var boxY = $(this).height();
				var rePadding = Math.floor((boxY - y) / 2);
				var reHeight = boxY - rePadding;
				$(this).css({paddingTop:rePadding+'px',height:reHeight+'px'});
			}
		});
	}
	
	//rollover使用時、カレントページのliに、'current'クラスを付ける
	$('li').each(function(){
		var imgSrc = $(' a img',this).attr('src');
		if(imgSrc != undefined){
			if(imgSrc.indexOf('_on') > -1){
				$(this).addClass('current');
			}
		}
	});
	
	//submit押した感&ウィンク
	$('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);
	});
	
	//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){
	}
	
	$(".photoGallery .photo div img").eq(0).css("display","block");	
	$(".photoGallery .photo ul li").mouseover(function(){
		$(".photoGallery .photo div img").css("display","none");
		_index = $(this).parent().children("li").index($(this));
		$(".photoGallery .photo div img").eq(_index).css("display","block");
	});
	
	

});



