/*
 * jcommon.js 1.14
 * 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)});}});};
	//するするアニメーション
	$.fn.scroller=function(){if(!$.browser.opera){$('a[href^="#"]','#main').not('[class^="shop"]').each(function(){this.target=$(this).attr('href')}).click(function(){$.scrollTo(this.target,{speed:800});return false})}}
	//要素全体にリンク
	$.fn.groupLink=function(){$(this).hover(function(){$(this).css({cursor:"pointer"});$(this).addClass('hover')},function(){$(this).removeClass('hover')}).click(function(){location.href=$(this).find('a').attr('href');return false})}

$(function(){


	//工務店トップ#headline にボタンをclone
	$('#main .btns','body#comIndex').each(function(num){
		$(this).clone().prependTo('#headline #pageTitle');
	});
	
	//ロールオーバー
	$('a img.btn,a.btn,#globalNav li a,.btns a').addRollOver('_on');

	//現在のページへのリンク
	$('#globalNav li:not([id="toHome"]),#localNav li:not([id="toCompanyHome"])').add('body#home #globalNav li#toHome,body#comIndex #localNav li#toCompanyHome').find('a').addCurrentImages('_cr');

	//外部リンクは別ウインドウを設定
	$('a[href^="http://"]:not([href*="sumailab.net"]),area[href^="http://"]').click(function(){
		window.open(this.href, '_blank');
		return false;
	}).addClass('externalLink');

	//別ウィンドウを設定
	$('a[href$=".pdf"],a[href$=".asx"]').click(function(){
		window.open(this.href, '_blank');
		return false;
	})
	
	//別ウィンドウを設定
	$('a[href$=".gif"],a[href$=".jpg"],a[href$=".png"]').click(function(){
		$(this).lightBox();
		return false;
	})


	//連番nxxxをクラスとして追加
	$('body#home #main #pickup ul li p').each(function(num){
		$(this).wrapAll('<div class="flame"></div>');
	});


	//ポップアップ ※href="[表示するURL]?width=000&amp;height=000"

$('a.popup').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(){
		this.pu = window.open(this.param[0], 'popup', "menubar=1,location=0,resizable=1,status=0,scrollbars=1,"+this.param[1]);
		return false;
	});

	//ポップアップ印刷ページ用 ※href="[表示するURL]?eventid=000&amp;width=000&amp;height=000"
	$('a.popupPrint').each(function(){
		this.param = $(this).attr("href");
		this.param = this.param.split('?');
		this.param[1] = this.param[1].split('&');
		this.toURL = this.param[0]+'?'+this.param[1].shift();
		this.param[1] = this.param[1].join(',')
		$(this).attr("href","");
	}).click(function(){
		this.pu = window.open(this.toURL, 'popup', "menubar=1,location=0,resizable=1,status=0,scrollbars=1,"+this.param[1]);
		return false;
	});

	
	//要素全体にリンク
	$('ul .work .body','#works').add('#areaSearch table tr, #pickup li','body#home').groupLink();
	
	//するするアニメーション ※要scrollTo.js
	$('a[href^="#"]','#main').not('[class^="shop"]').scroller();

	//連番nxxxをクラスとして追加
	$('.thumb img','body.company #headline').each(function(num){
		$(this).wrap('<div class="thumbInner"></div>');
	});
	
	//連番nxxxをクラスとして追加
	$('body.comEvent').not('body#cevPrint').find('#main .eventArea p.date').each(function(){
		$(this).wrapInner('<span class="dateInner"></span>');
	});
	

	
	$('.bnrs li a').each(function(){
	}).hover(function(){
		$(this).find('img').fadeTo(200,0.75);
	},function(){
		$(this).find('img').fadeTo(200,1);
	});

});