/*

Last UpDate 2009-11-18

*/

$(function(){
	//現在居るファイル名	   
	//var currentFile = location.href.split('/').pop();
	
	//ua取得
	var ua = navigator.userAgent;
	
	$('#footer-nav li:last,.article:last').addClass('last-child');
	$('.item-list > li:nth-child(4n)').addClass('fourth');
	$('#price table tr').each(function(){
		$('td',this).eq(2).addClass('price');
	});
	
	//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();
	$('#footer address span').text(year);
	
	/*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');
	}*/
	if($('ul').is('.item-list')){
		//flatHeights設定
		var sets = [], temp = [];
		$('.item-list > 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{
		$('.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){
	}
*/	
	if($('ul').is('.item-list') || $('div').is('#map')){
		Shadowbox.init({
			language: 'en',
			players:  ['img', 'html', 'iframe', 'qt', 'wmp', 'swf', 'flv']
		});
	}
	
});
	  
function googleMaps(lat,lng,zoom){
    Shadowbox.open({
        player:     'html',
        content:    '',
        height:     500,
        width:      600,
        options:    {
            onFinish: function(item){
                if(GBrowserIsCompatible()){
                    var body = document.getElementById(Shadowbox.contentId());
                    var map = new GMap2(body);
                    map.setCenter(new GLatLng(lat, lng), zoom);
					var marker = new GMarker(new GLatLng(lat,lng));
					map.addOverlay(marker);

					map.addControl(new GLargeMapControl3D());
                    map.addControl(new GMapTypeControl());
					var miniMap=new GOverviewMapControl(new GSize(200,150));
					map.addControl(miniMap);
                }
            }
        }
    });
	
}

