/*
 * Plugins
 */
//  set_smooth_scroll
(function(){
  var d=document;
  jQuery.fn._set_smooth_scroll= function(target_x,target_y) {
    return this.each(function(){
      _self = this;
      var pos = {
      target_x: target_x,
      target_y: target_y
      }
      pos._x = d.body.scrollLeft || d.documentElement.scrollLeft || window.pageXOffset;
      if(typeof pos._x == "undefined"){ pos._x = 0 }
      pos._y = d.body.scrollTop  || d.documentElement.scrollTop  || window.pageYOffset;
      if(typeof pos._y == "undefined"){ pos._y = 0 }
      pos.y = pos.target_y - pos._y + 2;
      pos.x = pos.target_x - pos._x;
      pos.x = pos._x + Math.floor(pos.x / 2);
      pos.y = pos._y + Math.floor(pos.y - (pos.y*4 / 5));
      window.scrollTo(pos.x, pos.y);
      if (pos.x == pos._x && pos.y == pos._y) {
        setTimeout("location.href = _self.href", 100)
      }else{
        setTimeout("jQuery(_self)._set_smooth_scroll(\""+pos.target_x+"\",\""+pos.target_y+"\")", 1);
      }
    });
  }

  jQuery.fn.set_smooth_scroll= function(){
    var myLocation = location.href.split('#')[0];
    return this.each(function(){
      var myLink = this.href;
      if(this.href.match(/(.+)#([^?]+)/)){
        myLink = RegExp.$1
        var target = d.getElementById(RegExp.$2);
        if(target){
          if(myLocation == myLink){
            this.onclick = function(){
              var target_y = 0;
              var target_x = 0;
              for (var i = target;i.offsetParent;i=i.offsetParent ){
                target_y += i.clientTop||0;
                target_y += i.offsetTop||0;
                target_x += i.offsetleft||0;
              }
              var viewport_y = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
              var document_y = document.documentElement.scrollHeight || document.body.scrollHeight;
              target_y = (document_y - viewport_y < target_y) ? document_y - viewport_y : target_y;
              jQuery(this)._set_smooth_scroll(target_x,target_y);
              return false;
            }
          }
        }
      }
    });
  }
})(jQuery);

//  set_rollovers
(function(A){jQuery.fn.set_rollovers=function(C){var D={extension:"_o",active_hover:true,hover_extension:"_h",active_extension:false,fade:false,menu:{},menu_type:"files"};if(C){jQuery.extend(D,C)}if(!D.active_extension){D.active_extension=D.hover_extension}var F=String(document.location);var E=false;var B=0;A.each(D.menu,function(G){if(D.menu_type=="files"){if(G.match(/|/)){menu_path_arr=G.split("|");for(k=0;k<menu_path_arr.length;k++){if(F.match(menu_path_arr[k])&&menu_path_arr[k].length>B){E=D.menu[menu_path_arr[k]];B=menu_path_arr[k].length}}}else{if(F.match(G)&&G.length>B){E=D.menu[G];B=G.length}}}else{if(D.menu_type=="nodes"){if(A(G).length){E=D.menu[G]}}}});return this.filter("[@src*="+D.extension+".]").each(function(){var H=new Image;H.src=this.src.replace(D.extension+".",D.hover_extension+".");if(this.src.match(/[^\/]+$/)[0]==E){this.src=this.src.replace(new RegExp(D.extension+"(.[a-z]+)$"),D.active_extension+"$1");if(D.active_hover){A(this).hover(function(){this.src=this.src.replace(new RegExp(D.active_extension+"(.[a-z]+)$"),D.hover_extension+"$1")},function(){this.src=this.src.replace(new RegExp(D.hover_extension+"(.[a-z]+)$"),D.active_extension+"$1")})}}else{if(!D.fade){A(this).hover(function(){this.src=this.src.replace(new RegExp(D.extension+"(.[a-z]+)$"),D.hover_extension+"$1")},function(){this.src=this.src.replace(new RegExp(D.hover_extension+"(.[a-z]+)$"),D.extension+"$1")})}else{var G=A(this).wrap('<span style="position:relative; display:block;"></span>').parent();G.append('<img src="'+H.src+'" style="position:absolute; top:0; left:0;" />');G.find("> :last-child").hide();G.hover(function(){A("> img:last-child",this).fadeIn(D.fade)},function(){A("> img:last-child",this).fadeOut(D.fade)})}if(this.parentNode.nodeName.match(/^a$/i)){A(this).parent().focus(function(){A(">img",this).trigger("mouseover")}).blur(function(){A(">img",this).trigger("mouseout")})}else{if(this.parentNode.nodeName.match(/span/i)&&this.parentNode.parentNode.nodeName.match(/a/i)){A(this).parents("a").focus(function(){A("> span > img:last-child",this).fadeIn(D.fade)}).blur(function(){A("> span > :last-child",this).fadeOut(D.fade)})}}}})}})(jQuery);
//  set_links
(function(A){A.set_links=function(B){A("a[@rel=popup],a[@class=popup],a[@rel=external],area[@rel=popup],area[@rel=external]").click(function(){if(this.rel=="external"){window.open(this.href,"_blank");return false}var I="";var D=0;var C="";for(i in B){if(i.match(">>")){data=i.split(">>");if(String(window.location).match(data[0])&&this.href.match(data[1])){C=i;break}}if(i.match(/^\.(.*)/)){var E=new RegExp("\\b"+RegExp.$1+"\\b");if(this.className.match(E)){for(param in B[i]){if(param=="name"){continue}I+=param+"="+B[i][param]+","}if(this.href.match(/width=(\d+).*height=(\d+)/)){var F=RegExp.$1;var H=RegExp.$2;if(I.match("width")&&I.match("height")){I=I.replace(/width=\d+/,"width="+F);I=I.replace(/height=\d+/,"height="+H)}else{I+="width="+F+",height="+H}}var G=B[i]["name"]?B[i]["name"]:"popup";window.open(this.href,G,I.split(/,$/)[0]).focus();this.blur();return false}}else{if(this.href.match(i)&&i.length>D){C=i;D=i.length}}}for(param in B[C]){if(param=="name"){continue}I+=param+"="+B[C][param]+","}var G=B[C]["name"]?B[C]["name"]:"popup";window.open(this.href,G,I.split(/,$/)[0]).focus();this.blur();return false});return this}})(jQuery);
//  set_height
(function(A){A.fn.set_height=function(P){var G={items_per_row:false,one_height:false,delay:1000,group_by_parent:false};if(P){jQuery.extend(G,P)}if(A("#js_etalon").length){var N=A("#js_etalon").get(0)}else{var N=A("body").append('<span style="position:absolute;left:-9999px;top:0;" id="js_etalon">&nbsp;</span>').find("#js_etalon").get(0)}var E=function(S,R){for(var Q=0;Q<S.length;Q++){if(S[Q]==R){return }}S.push(R)};var B=this;var F=[];var L=[];var K=[];var J=function(){for(var S=0;S<F.length;S++){var R=0;var T=F[S][0].currentStyle?parseInt(F[S][0].currentStyle.paddingTop)+parseInt(F[S][0].currentStyle.paddingBottom):parseInt(document.defaultView.getComputedStyle(F[S][0],null).getPropertyValue("padding-top"))+parseInt(document.defaultView.getComputedStyle(F[S][0],null).getPropertyValue("padding-bottom"));for(var Q=0;Q<F[S].length;Q++){F[S][Q].style.height="auto";R=Math.max(F[S][Q].offsetHeight-T,R)}for(var Q=0;Q<F[S].length;Q++){F[S][Q].style.height=R+"px"}}};var M=function(){var Y=0;var W=0;var Q=null;var T=null;F[Y]=[];var Z=false;for(var U=0;U<B.length;U++){if(G.group_by_parent){Q=A(B[U]).parents(G.group_by_parent)[0];if(U>0&&Q!=T&&!Z){F[++Y]=[];W=0}T=Q}if(G.items_per_row){B[U].className+=" nb"+parseInt(W%G.items_per_row+1);if(!(W%G.items_per_row)&&W>0){F[++Y]=[];W=0;Z=true}}F[Y][W++]=B[U];Z=false}for(var U=0;U<F.length;U++){if(!F[U][0].offsetHeight){var X=F[U][0];while(X.style.display!="none"){X=X.parentNode}L.push(X)}for(var S=0;S<F[U].length;S++){var V=F[U][S].getElementsByTagName("img");for(var R=0;R<V.length;R++){E(K,V[R].src)}}}};if(B.length){M();var D=N.offsetHeight;var C=setInterval(function(){var S=N.offsetHeight;if(S!=D){D=S;J()}for(var R=0;R<L.length;R++){if(L[R].style.display!="none"){J();L=[];for(var Q=0;Q<F.length;Q++){if(!F[Q][0].offsetHeight){var T=F[Q][0];while(T.style.display!="none"){T=T.parentNode}L.push(T)}}}}},G.delay);J();if(K.length){var H=[];var O=0;for(var I=0;I<K.length;I++){H[I]=document.createElement("img");H[I].onload=function(){O++;if(O==K.length){J()}};H[I].src=K[I]}}}if(navigator.userAgent.match("MSIE 5.5")&&B.length){setTimeout(function(){main(B),0})}return this}})(jQuery);
//  set_flash
(function(A){A.fn.set_flash=function(B){var C={version:6,movie:"",name:"",title:"",height:0,width:0,no_version:"no version",no_flash:"no flash"};if(B){jQuery.extend(C,B)}return this.each(function(F){_flash_version=function(){if(navigator.plugins&&navigator.plugins.length){if(!navigator.plugins["Shockwave Flash"]){return false}if(navigator.plugins["Shockwave Flash"].description){navigator.plugins["Shockwave Flash"].description.match(/(\d+)\.\d/);return parseInt(RegExp.$1)}}else{for(var I=15;I>=0;I--){try{new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+I);return I}catch(J){}}return false}return false};var D={};if(C.height&&C.width&&C.movie!=""){D=C}else{var E=this.className.match(/[a-z]+\[[^\]]+\]/g);for(F=0;F<E.length;F++){E[F].match(/([a-z]+)\[([^\]]+)\]/);D[RegExp.$1]=RegExp.$2}}var H="";var G="";if(D.wmode){H+=' wmode="'+D.wmode+'"';G+='<param name="wmode" value="'+D.wmode+'">'}if(!_flash_version()){A(this).html(C.no_flash);return }if(_flash_version()<(D.version||C.version)){A(this).html(C.no_version);return }A("> *",this).hide();A(this).html('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" height="'+D.height+'" width="'+D.width+'" name="'+D.name+'" title="'+D.title+'"><param name="movie" value="'+D.movie+'"><param name="name" value="'+D.name+'"><param name="quality" value="high">'+G+'<embed src="'+D.movie+'" quality="high" type="application/x-shockwave-flash" height="'+D.height+'" width="'+D.width+'"'+H+"></object>")})}})(jQuery);
//  set_png_support
jQuery.set_png_support=function(B){var C={spacer_path:"/images/spacer.gif"};if(B){jQuery.extend(C,B)}navigator.userAgent.match(/msie\s*(\d)/i);var A=RegExp.$1;if((A<=6&&A>5)&&$.browser.msie){$("img[@src$=png]").each(function(){$(this).css({filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.src+"', sizingMethod='scale')"}).attr({src:C.spacer_path,width:this.width,height:this.height})})}};
//  set_viewer
(function(A){A.fn.set_viewer=function(D){var F={bg_opacity:0.5,html_height:480,html_width:640,line_break:" -- ",speed:3000,on_show:null,on_hide:null};if(D){jQuery.extend(F,D)}var H=false;var B=false;var E=A("body").append('<div id="viewer-holder"></div>').children("#viewer-holder").css({position:"absolute",display:"none",zIndex:"101"});A("body").append('<div id="viewer-bg" style="display:none;"></div>');var C=A("div#viewer-bg");C.css({position:"absolute",width:"100%",top:0,left:0,zIndex:"100"}).click(function(){_close_viewer()});C.fadeTo(1,0,function(){A(this).hide()});var G;_repos_holder=function(){var J=((A(document).scrollTop()+A(window).height())>=A(document).height())&&(E[0].clientHeight>=A(window).height());var I=E[0].clientHeight>A(window).height()?A(document).scrollTop():A(document).scrollTop()+A(window).height()/2-E[0].clientHeight/2;if(J){E.css({top:I+"px"});return }if(!H){return }E.css({top:I+"px",left:A(window).width()/2-E[0].clientWidth/2+"px"})};_resize_bg=function(){C.css({height:A(document).height()+"px",width:A(document).width()+"px"})};_close_viewer=function(){if(!B){return }if(G){G.onLoad=null}E.empty().hide();C.fadeTo("slow",0,function(){A(this).hide()});H=false;if(F.on_hide){F.on_hide.call()}};_resize_viewer=function(J,I,K){E.animate({left:A(window).width()/2-J/2-parseInt(E.css("padding-left")),top:A(document).scrollTop()+A(window).height()/2-I/2},(F.speed/3),function(){});A("#viewer-loader").animate({width:J,height:I},(F.speed/3),K)};_switch_image=function(O){B=false;var R='<div id="info_area" style="display:none;">';var N=A(O).parents()[0].tagName=="LI";var P="";if(N){var K=A(O).parents()[1];var L=A("li",K).size();var J=A(O).parents()[0];A("li",K).each(function(U){if(this==J){list_index=U+1}});var M=A("a",K).get(list_index-2);var Q=A("a",K).get(list_index);var I=list_index!=L?'<a href="#" id="viewer-next">&gt;</a>':"";var S=list_index!=1?'<a href="#" id="viewer-prev">&lt;</a>':"";R+=L>1?'<p id="viewer-nav">'+S+' <span id="viewer-state">'+list_index+" / "+L+"</span> "+I+"</p>":""}var T=(A("img",O).get(0)?A("img",O).get(0).alt:"")||O.title||"";R+=T!=""?'<p id="viewer-caption">'+T.replace(F.line_break,"<br />")+"</p>":"";R+="</div>";A("#viewer-loader img").remove();G=new Image();G.onload=function(){_resize_viewer(G.width,G.height,function(){A("#viewer-loader").append('<img id="viewer-image" src="'+G.src+'" alt="'+T+'" style="opacity:0;filter:alpha(opacity=0);" />');A("#viewer-loader img").fadeTo((F.speed/3),1,function(){E.append(R+'<a href="#" id="viewer-close">X</a>');if(N||T!=""){A("#info_area").css({width:G.width}).slideDown((F.speed/3),function(){E.animate({top:A(document).scrollTop()+A(window).height()/2-G.height/2-A("#info_area").outerHeight()/2-(parseInt(E.css("padding-top"))+parseInt(E.css("padding-bottom")))},(F.speed/3),function(){B=true;_repos_holder()})})}else{B=true;_repos_holder()}if(N){A("#viewer-prev").click(function(){A("#info_area").slideUp((F.speed/3),function(){A("#info_area").remove();A("#viewer-close").remove();_switch_image(M)});A("#viewer-loader img").fadeTo((F.speed/3.5),0,function(){A("#viewer-loader img").remove()});B=false;return false});A("#viewer-next").click(function(){A("#info_area").slideUp((F.speed/3),function(){A("#info_area").remove();A("#viewer-close").remove();_switch_image(Q)});A("#viewer-loader img").fadeTo((F.speed/3.5),0,function(){A("#viewer-loader img").remove()});B=false;return false})}A("#viewer-close").click(function(){_close_viewer();return false})})})};G.src=O.href};_show_viewer=function(J){E.empty().show();H=true;_resize_bg();if(F.on_show){F.on_show.call()}var I=(A("img",J).get(0)?A("img",J).get(0).alt:"")||J.title||"";var K=J.href.toLowerCase().match(/jpg$|jpeg$|png$|gif$|bmp$/)?"image":"page";C.show().fadeTo("slow",F.bg_opacity);if(K=="image"){E.addClass("image").removeClass("html");E.append('<div id="viewer-loader"></div>');_repos_holder();_switch_image(J)}else{if(K=="page"){B=true;E.addClass("html").removeClass("image");A("#viewer-holder").append('<p id="viewer-title">'+I+'</p><a href="#" id="viewer-close">X</a><iframe src="'+J+'" id="viewer-frame" border="0" style="width:'+F.html_width+"px;height:"+F.html_height+'px;"></iframe>');A("#viewer-close").click(function(){_close_viewer();return false});_repos_holder()}}};A(window).scroll(function(){if(!H){return }_repos_holder()}).resize(function(){if(!H){return }_repos_holder();_resize_bg()});return this.click(function(){_show_viewer(this);return false})}})(jQuery);

/*  for debug  */
trace = (window.console)?(console.log):(alert);


/*
 * Run
 * プラグインの初期化及び汎用化できない個別の処理の実行
 */

// $.ready
//  DOM構築後に実行するべき処理 または 実行が遅くなっても構わない処理
$().ready(function(){
	/* rollovers */
	$("a img,input:image").set_rollovers()
	$("#sub-nav>li").hover(function(){
		$(this).addClass("active");
	},function(){
		$(this).removeClass("active");
	});
	/* end of rollovers */
	
	/* icons */
	$('a[href$=".pdf"]').each(function(){
		var _this=$(this);
		if(!_this.parents(".pdf").length){
			_this.after(' <img src="/shared/images/ico_pdf.gif" class="icon" alt="pdfを開きます。" />');
		}
	});
	$('#main-contents a[target="_blank"]').each(function(){
		var _this = $(this);
		if(_this.parents("ul.link-01,ul.link-01-r,ul.link-02,ul.link-02-r,ul.link-03,ul.quad-link-01").length&&!this.href.match(/\.pdf$/)){
			_this.after(' <img src="/shared/images/ico_external_01.gif" class="icon" alt="新しいウィンドウで開きます。" />');
		}else if(!$("img",_this).length&&!this.href.match(/\.pdf$/)){
			_this.after(' <img src="/shared/images/ico_external_01.gif" class="icon" alt="新しいウィンドウで開きます。" />');
		}
	});
	$('#sub-contents a[target="_blank"]').each(function(){
		var _this = $(this);
		_this.after(' <img src="/shared/images/ico_external_01.gif" class="icon" alt="新しいウィンドウで開きます。" />');
	});
	/* end of icons */
	
	/*column-index-01*/
	$("ul.column-index-01 li,ul.column-index-04 li").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	})
	$("ul.column-index-01 li,ul.column-index-04 li").click(function(){
		location.href=$("a",this)[0].href;
	})
	/*end of column-index-01*/
	$("ul.offices-01 p.to-top").css({"position":"absolute","bottom":"5px","right":"0"})

	/*table.table-04*/
	$("table.table-04 tbody tr").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	})
	/*end of table.table-04*/
});



// onHtmlLoad
//  DOMの構築を待たずに最速で実行するべき処理
//  全てのHTMLのbody最下部にscript要素にてonHtmlLoadを呼び出す
var onHtmlLoad = function(){
	/*local navigation*/
	$("#sub-nav").addClass("js-on");
	$("#sub-nav a").each(function(){
		var _this     = $(this);
		var _li       = _this.parent("li");
		var _li_parents       = _li.parents("li");
		var _href     = _this.attr("href").replace(/index\.html$/,"");
		var _location = location.pathname.replace(/index\.html$/,"");
		if(_location==_href){
			_li.addClass("current");
			_li_parents.each(function(){
				$(this).addClass("parent");
			});
		}
	});
	/*local navigation*/
}

// window.onload
// 画像読み込みなど全て終わってから実行すべき処理
var onLoaded = function(){
	/* form control*/
	$("input:text,textarea").focus(function(){$(this).addClass("focus")});
	$("input:text,textarea").blur(function(){$(this).removeClass("focus")});
	/* end of form control*/
	
	/* smooth_scroll */
	$("a").set_smooth_scroll();
	/* end of smooth_scroll */
	/*作業用*/
	$("#main-contents .img img,#main-contents .float-r img,#main-contents .float-l img,").each(function(){
		var _this = $(this);
		if(_this.width()<30){
			_this.attr("src","/_etc/dummy/images/spacer.gif")
			_this.css({"width":"100%","height":"150px","background-color":"#ccc","display":"block"});
		}
	})
}

if (window.attachEvent){
	window.attachEvent('onload', onLoaded);
}
else {
	window.addEventListener('load', onLoaded, false);
}

// set_flash
(function(A){A.fn.set_flash=function(B){var C={version:6,movie:"",name:"",title:"",height:0,width:0,no_version:"no version",no_flash:"no flash"};if(B){jQuery.extend(C,B)}return this.each(function(F){_flash_version=function(){if(navigator.plugins&&navigator.plugins.length){if(!navigator.plugins["Shockwave Flash"]){return false}if(navigator.plugins["Shockwave Flash"].description){navigator.plugins["Shockwave Flash"].description.match(/(\d+)\.\d/);return parseInt(RegExp.$1)}}else{for(var I=15;I>=0;I--){try{new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+I);return I}catch(J){}}return false}return false};var D={};if(C.height&&C.width&&C.movie!=""){D=C}else{var E=this.className.match(/[a-z]+\[[^\]]+\]/g);for(F=0;F<E.length;F++){E[F].match(/([a-z]+)\[([^\]]+)\]/);D[RegExp.$1]=RegExp.$2}}var H="";var G="";if(D.wmode){H+=' wmode="'+D.wmode+'"';G+='<param name="wmode" value="'+D.wmode+'">'}if(!_flash_version()){A(this).html(C.no_flash);return }if(_flash_version()<(D.version||C.version)){A(this).html(C.no_version);return }A("> *",this).hide();A(this).html('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" height="'+D.height+'" width="'+D.width+'" name="'+D.name+'" title="'+D.title+'"><param name="movie" value="'+D.movie+'"><param name="name" value="'+D.name+'"><param name="quality" value="high">'+G+'<embed src="'+D.movie+'" quality="high" type="application/x-shockwave-flash" height="'+D.height+'" width="'+D.width+'"'+H+"></object>")})}})(jQuery);

$(function(){
    $('#top-flash').set_flash({ movie:"/index.swf", width:840, height:260, version:8, no_version:"<p><img src='/images/flash.jpg' alt='人と共に、次代を見据えたまちづくり。80年を超える歴史のなかで培ってきた総合的な技術力で、真に豊かなまちづくりを実現していきます。' width='840' height='260' /></p>", no_flash:"<p><img src='/images/flash.jpg' alt='人と共に、次代を見据えたまちづくり。80年を超える歴史のなかで培ってきた総合的な技術力で、真に豊かなまちづくりを実現していきます。' width='840' height='260' /></p>" });
});
