/*

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が、'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');
	
	$('#news dd').filter(function(i){
		if(i % 2) return this;
	}).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(!$(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){
	}
	
});


