/*
 * jcommon.js 1.12
 * Copyright (c) 2007 C.M.A. Co.,Ltd.
 *
 * Last Added: 2008-09-09
 *
 */

var ary = location.pathname.split('/');var l=0;var isLinkAry=new Array;for(i=0;i<=ary.length-1;i++){isLinkAry[i]=ary.slice(i,i+1);isLinkAry[i]=isLinkAry[i].join('/');isLinkAry[i]=isLinkAry[i].replace(/index.*$/,"")}for(k=i+1;k<=i+ary.length;k++){isLinkAry[k]=ary.slice(0,ary.length-l);isLinkAry[k]=isLinkAry[k].join('/');isLinkAry[k]=isLinkAry[k].replace(/^\//,"");isLinkAry[k]=isLinkAry[k].replace(/index.*$/,"");l++}isLinkAry[0]=isLinkAry[0].replace(/\#.*$/,"");var jcommon={preloader:{loadedImages:[],load:function(url){var img=this.loadedImages;var l=img.length;img[l]=new Image();img[l].src=url}},URI:function(path){path=path.replace(/^https[^a-z]*/,"");path=path.replace(/^http[^a-z]*/,"");path=path.replace(document.domain,"");path=path.replace(/^[^a-z]*/,"");path=path.replace(/index.*$/,"");path=path.replace(/\/$/,"");this.absolutePath=path;this.len=isLinkAry.length;this.isSelfLink=false;while(this.len--){this.isSelfLink=this.isSelfLink||(this.absolutePath==isLinkAry[this.len])}}};

//ロールオーバー
$.fn.addRollOver=function(add){$(this).filter('img').each(function(){$(this).runRollOver(add,$(this));}).end().not('img').each(function(){$(this).runRollOver(add,$(this).find('img'));});};
$.fn.runRollOver=function(add,target){$(this).each(function(num){this.originalSrc=String(target.attr('src'));this.rolloverSrc=this.originalSrc.replace(/(\.gif|\.jpg|\.png)/,add+"$1");}).hover(function(){target.attr('src',this.rolloverSrc);},function(){target.attr('src',this.originalSrc);});};

//現在のページへのリンク
$.fn.addCurrentImages=function(add){$(this).each(function(){var href=new jcommon.URI($(this).attr('href'));if(href.isSelfLink){$(this).addClass('current');$(this).unbind('mouseenter');$(this).unbind('mouseleave');$(this).find('img').each(function(){$(this).unbind('mouseenter');$(this).unbind('mouseleave');this.currentSrc=this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/,add+"$1");$(this).attr('src',this.currentSrc)});}});};

// Googlemapをiframeで表示
$.fn.addGoogleMaps=function(){
	var winHeight = $(window).height();
	var attPoint  = $(window).scrollTop() + winHeight;
	$(this).each(function(){
		var targetTop = $(this).offset().top;
		if(attPoint >= targetTop && attPoint <= targetTop+winHeight && !$(this).is('.show')){
			this.gmapURI = $(this).attr('href');
			$(this).before('<iframe frameborder="0" src="'+this.gmapURI+'"></iframe>');
			$(this).addClass('show');
		}
	});
}
//ページpopUp
$.fn.pagePoper=function(){$(this).each(function(){this.param=$(this).attr("href");this.param=this.param.split('?');this.param[1]=this.param[1].split('&');this.param[1]=this.param[1].join(',');$(this).attr("href","")}).click(function(){
window.open(this.param[0],'popup',"menubar=0,location=0,resizable=0,status=0,"+this.param[1]);return false})};

$(function(){

	//ロールオーバー
	$('.btn,.navigation a','#subContent').addRollOver('_on');

	//現在のページへのリンク
	$('.navigation a','#header,#subContent').addCurrentImages('_cr');	

	//外部リンクは別ウインドウを設定
	$('a[href^="http://"]:not([href^="http://www.shiiki.jp/"],[href^="http://204.227.175.84/"]),a[href*="gallery/"],a[href$=".pdf"],a[href$=".asx"]').click(function(){
		window.open(this.href, '_blank');
		return false;
	}).addClass('externalLink');
	
	//サイズ指定の新規ウィンドウ
	$('#designAlbum a','#albIndex').pagePoper();

	//googlemapをiframeで表示(マップ配置の地点までスクロールしたら)
	function checkAttachMap(){ $('a.gmap').addGoogleMaps(); }
	$(window).load(checkAttachMap).scroll(checkAttachMap);

	//ページの目次
	$('#pageNav').each(function(){
		var openImage = "/shared/img/button/btn_show_all";
		var closeImage= "/shared/img/button/btn_close";
		var ifOpen = false;
		var defHeight = $(this).children('dl').height();
		$(this).children('dl').css({height:48});
		$(this).append('<img style="display:block; position:relative; margin:50px 0 0 auto;" src="'+openImage+'.gif" alt="すべて表示" />')
		.click(function(){
			$(this).children('dl')	.queue("fx",[]).animate({height:ifOpen?48:defHeight},{duration:400,easing:'easeOutExpo'});
			$(this).children('img').queue("fx",[]).animate({marginTop:ifOpen?50:5+defHeight},{duration:400,easing:'easeOutExpo'})
									.attr('src',(ifOpen?openImage:closeImage)+'.gif')
									.attr('alt',ifOpen?'すべて表示':'閉じる');
			ifOpen=ifOpen?false:true;
		})
		.hover(function(){
			$(this).children('img').attr('src',(ifOpen?closeImage:openImage)+'_on.gif');
		},function(){
			$(this).children('img').attr('src',(ifOpen?closeImage:openImage)+'.gif');
		});
	});

	//下階層表示
	$('.navigation dd','#subContent').each(function(){
		var defHeight = $(this).children('ul').height();
		$(this).children('ul').height(0).css({paddingBottom:0});
		$(this).hover(function(){
			$(this).children('ul').queue("fx",[]).animate({paddingBottom:5,height:defHeight}	,{duration:400,easing:'easeOutExpo'});
		},function(){
			$(this).children('ul').queue("fx",[]).animate({paddingBottom:0,height:0}			,{duration:400,easing:'easeOutExpo'});
		});	
	});

	//するするアニメーション ※要scrollTo.js
	if(!$.browser.opera){
		$('a[href^="#"]').each(function(){
			this.target = $(this).attr('href');
		}).click(function(){
			$.scrollTo( this.target, {speed:800} );
			return false;
		});
	}else if($.browser.opera){
		$('.toTop a[href^="#"]').each(function(){
			this.target = $(this).attr('href');
		}).click(function(){
			$.scrollTo( this.target, {speed:800} );
			return false;
		});
	}

	//oddとevenを追加
	$('tr','#mainContent').filter(':odd').addClass('even').end().filter(':even').addClass('odd');

	//:first-child(x) :連番nxxxをクラスとして追加
	$('.num>li','#mainContent').each(function(num){
		$(this).addClass('n'+(++num));
	});

	//:first-child, :last-childをクラスとして追加
	$('li,tr,th').filter(':first-child').addClass('firstChild');
	$('dd,li,tr,th').filter(':last-child').addClass('lastChild');

	//トップ画像の自動切り替え
	var tickerLen = $('#mainVisual li','#home').length;
	$('#mainVisual li','#home').each(function(num){
		$(this).css({zIndex:100+$(this).length - num,display:'none'});
	});
	$.newsticker = function(len){
		if(len > tickerLen-1)len=0;
		$('#mainVisual li:eq('+len+')').each(function(){
			$(this).fadeIn(1000,function(){
				$(this).animate({left:0},4000,function(){
					$(this).fadeOut(1000);
					$.newsticker(++len);
				});
			});
		});
	}
	$.newsticker(0);
	
	//新着情報一覧を読み込む
	$('#news','#home').load('news/toplist.html');

});