/*
 * 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)});}});};

//画像popUp
$.fn.imagePoper=function(){$(this).click(function(){
	var _x,_y,popImg,_URL=$(this).attr("href"),_LINK=$(this).attr("rel"),floatingObj='#floatingWrapper,#floatingWindow';
	function closeEvent(){
		$('#floatingWindow').hide(250,function(){
			$(this).remove();
			$('#floatingWrapper').fadeOut(100,function(){
				$(this).remove();
			});
		});
		return false
	}
	$('body').append('<div id="floatingWrapper"></div>')
	.append('<div id="floatingWindow"><p><img src="'+_URL+'" usemap="#'+_LINK+'" /></p><span class="moreBtn" href=""><a href="'+_LINK+'.html">詳細情報</a></span><span class="closeBtn" href="">閉じる</span></div>');
	$('#floatingWrapper').css({display:"none",height:$('body').height()+'px'}).click(function(){closeEvent()}).fadeIn(250,function(){$('#floatingWindow').find('img').each(function(){var scTop=$.browser.opera?250:$(window).height()/2;popImg=$(this);_x=$(window).width()/2-popImg.width()/2;_y=scTop+$(window).scrollTop()-popImg.height()/2}).end().css({display:"none",top:_y+'px',left:_x+'px',width:popImg.width()+'px'}).show(250).click(function(){closeEvent()})});return false;
})};

$(function(){


	//ロールオーバー
	$('a img.btn,a.btn,#localNav li a,.costNav li a,.itemNav li a').addRollOver('_on');

	//現在のページへのリンク
	$('#globalNav li a,#localNav li a,.costNav li a,.itemNav li a').addCurrentImages('_cr');	

	//外部リンクは別ウインドウを設定
	$('a[href^="http://"]:not([href^="http://www.izumo-sosai.jp/"],[href^="http://izumo-sosai.jp/"])').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;
	})

	//下階層表示
	$('#localNav li').each(function(){
		$(this).hover(function(){
				$(this).children('ul').css({display:"block",zIndex:99}).queue("fx",[]).animate({opacity: 0.98},200);
			},function(){
				$(this).children('ul').queue("fx",[]).animate({opacity: 0},200,function(){
					$(this).css({display:"none"});
				});
		});	
	});
	
	//マウスーバー時、画像を半透明にする
	$('a img.alpha').hover(function(){
		$(this).fadeTo(100,0.7);
	},function(){
		$(this).fadeTo(100,1.0);
	});
	

	//連番nxxxをクラスとして追加
	$('#flowNum li').each(function(num){
		$(this).addClass('n'+(++num));
	});


	if($('#halIndex').length){
		//画像popUp
		$('map area').click(function(){
			var target = $(this);
			var ID = $(this).attr('href');
			$('#floatingWindow img').each(function(){
				if($(this).attr('usemap')!=('#'+ID)){
					$('#floatingWindow img').fadeTo(500,0,function(){
						$(this)
						.attr('src','img/map/'+ID+'.gif')
						.attr('usemap','#'+ID)
						.fadeTo(500,1)
					});
				}else{
					if(IE='\v'=='v'){
						location.href(ID+'.html');
					}else{
						location.href = ID+'.html';
					}
				}
			});
			return false;
		});
		$('a[href$=".jpg"],a[href$=".gif"]','#main').imagePoper();
	}

	
});

//* OpenWindow
function opwin(url,wn,w,h){
	window.open(url,wn,"width="+w+",height="+h+",menubar=1,location=1,resizable=1,status=1,scrollbars=1");
}
