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



/*  for debug  */
trace = (window.console)?(console.log):(alert);


/*
 * Run
 * プラグインの初期化及び汎用化できない個別の処理の実行
 */

// ready
//  DOM構築後に実行するべき処理 または 実行が遅くなっても構わない処理
$().ready(function(){
  /*png support for ie6*/
  $.set_png_support({ spacer_path: "/shared/images/spacer.gif" });

  /*subnvigation*/
  $("#sub-navigation li>span").toggle(function(){
    if(!$(this).parent().attr("class").match("current")){
      $(this).addClass("selected").parent().addClass("hover");
    }
  },function(){
    if(!$(this).parent().attr("class").match("current")){
      $(this).removeClass("selected").parent().removeClass("hover");
    }
  });
  $("#sub-navigation .js-on span").hover(function(){
    var _this = $(this);
    if(!_this.parent().attr("class").match(/(current)|(hover)/)){
      if(_this.width()==149){
        _this.css({"background-position":"-736px 0","font-weight":"bold","color":"#fff"});
      }else{
        _this.css({"background-position":"-696px 0","font-weight":"bold"});
        _this.parent().addClass("active");
      }
    }
  },function(){
    var _this = $(this);
    if(!_this.parent().attr("class").match(/(current)|(hover)/)){
      if(_this.width()==149){
        _this.css({"background-position":"-552px 0","font-weight":"normal","color":"#333"});
      }else{
        _this.css({"background-position":"-522px 0","font-weight":"normal"});
        _this.parent().removeClass("active");
      }
    }else if(_this.width()==149){
    }
  });
  $("#sub-navigation li.concern li").hover(function(){
    $(this).addClass();
  },function(){})
  $("#sub-navigation .js-on>li.current>a").each(function(){
    if(!$(this).next().length)$(this).css("background-position","-184px 0")
  });
  /*subnvigation ここまで*/

  /*rollover*/
  $("a img,input[type='image']").set_rollovers({ menu: { "/search/": "nav_search_o.gif", "/market/": "nav_marketdata_o.gif" , "/pm/": "nav_pm_o.gif", "/buysell/": "nav_buy_o.gif", "/about/": "nav_corp_o.gif", "/judge/": "nav_judge_o.gif" } });

  /*popup*/
  $.set_links({ ".popup": { width:800, height: 600, toolbar: "yes", scrollbars: "yes", resizable:"yes" } });
  $("img.close").set_rollovers();
  $("img.close").css("cursor","pointer");
  $("img.close").click(function(){window.close()});

  /*icon*/
  $('a[href$=".pdf"]').each(function(){
    if($.browser.msie&&!$("img",this).length&&$(this).parents("ul.list-2")){
      $(this).css("zoom","1").append('<img src="/shared/images/ico_pdf.gif" class="icon" alt="pdfを開きます。" style="margin-left:0.3em;" />')
    }else if(!$("img",this).length){
      $(this).css("zoom","1").after(' <img src="/shared/images/ico_pdf.gif" class="icon" alt="pdfを開きます。" />');
    }
  });
  $('a[target="_blank"]').each(function(){
    if(!$(this).attr("href").match(/\.pdf$/)&&!$("img",this).length) $(this).css("zoom","1").after(' <img src="/shared/images/ico_external.gif" class="icon" alt="新規ウィンドウを開きます" />')
  });
  $('a.new').css("zoom","1").after(' <img src="/shared/images/ico_new.gif" class="icon" alt="新着情報" />')

});



// onHtmlLoad
//  DOMの構築を待たずに最速で実行するべき処理
//  全てのHTMLのbody最下部にscript要素にてonHtmlLoadを呼び出す
var onHtmlLoad = function(){
  /*navigation first render*/
  path=document.location.pathname.replace(/\/$/,"/index.html");
  if(path.match(/^\/market\//)){$("body").addClass("market")}
  $("#sub-navigation dd>ul").addClass("js-on");
  $("#sub-navigation li li li:last-child").addClass("last-child");
  $("#sub-navigation .current").each(function(){
    $(this).parents("li").addClass("current");
  });

  /*navigation market*/
  if(path.match(/^\/market/)){
    $("#sub-navigation li a").each(function(){
      var _this = $(this)
      if(_this.attr("href").replace(/\/$/,"/index.html")==path){
        _this.parents("li").addClass("current");
      }
    });
  }
}

// onHtmlLoad
// 画像読み込みなど全て終わってから実行すべき処理
var onLoaded = function(){
  /*img-and-txt*/
  $(".img-and-txt").each(function(){
    $(".txt",this).css("width",($(this).width()-$(".img img,.img-r img,.img-l img",this).width()-10)+"px");
    $(".img,.img-r,.img-l",this).css("width",($(".img img,.img-r img,.img-l img",this).width())+"px");
  });
  /*frame
  if($("ul.property-list,div.property-list").length){
    var _frame = $(document.createElement('div')).addClass("frame").html('<div class="frame1"></div><div class="frame2"></div><div class="frame3"></div><div class="frame4"></div>');
    $("table.property-list td").each(function(){
      var _this = $(this);
      $("dd",this).css({"height":(_this.height()-$("dt",this).height())+"px"});
    })
    $("ul.property-list div.img img,ul.property-list p.img img,div.property-list div.img img,div.property-list p.img img").each(function(){
      var _this=$(this);
      if(_frame){
        _this.after(_frame.clone().css({"height": _this.height(),"left": _this.parents("p").css("padding-left")}));
      }else{
        _this.next().css({"height": _this.height()});
      }
    });
  }*/
  $("table.property-list td").each(function(){
    var _this = $(this);
    $("dd",this).css({"height":(_this.height()-$("dt",this).height())+"px"});
  
  });

/*setTimeout(function(){
  if(!$("table.property-list").length){
    var _frame = $(document.createElement('div')).addClass("frame").html('<div class="frame1"></div><div class="frame2"></div><div class="frame3"></div><div class="frame4"></div>');
  }else{
    try {
      document.execCommand('BackgroundImageCache', false, true);
    } catch(e) {
    }
  }
  $("table.property-list td").each(function(){
    var _this = $(this);
    $("dd",this).css({"height":(_this.height()-$("dt",this).height())+"px"});
  
  })
  $("table.property-list p.img img,ul.property-list div.img img,ul.property-list p.img img,div.property-list div.img img,div.property-list p.img img").each(function(){
    var _this=$(this);
    if(_frame){
      _this.after(_frame.clone().css({"height": _this.height()}));
    }else{
      _this.next().css({"height": _this.height()});
    }
  });
},0);*/

  /*tab*/
  var tab_links=[];
  $(".set_tab a").each(function(){
    tab_links.push($(this).attr("href").match(/#(.*)/)[0]);
  });
  for(i=1;i<tab_links.length;i++){
    $(tab_links[i]).hide()
  }
  $(".set_tab a").click(function(){
    for(i=0;i<tab_links.length;i++){
      $(tab_links[i]).hide();
      var _img = $("a[href$='"+tab_links[i]+"'] img");
      _img.attr("src",_img.attr("src").replace("_h.","_o."));
      _img.set_rollovers();
    }
    $($(this).attr("href").match(/#(.*)/)[0]).show();
    var _img = $("img",this);
    _img.attr("src",_img.attr("src").replace("_o.","_h."));
      _img.unbind();
    
    return false;
  });
  /*tabここまで*/
  /*setHeight*/
  $("ul.column-double").each(function(){if(!$(".set_tab").length){$(">li",this).set_height({items_per_row: 2,delay: 2000})}});
  $("ul.property-list").each(function(){$(">li",this).set_height({items_per_row: 2})});
  $("div.column-double").each(function(){if(!$(".set_tab").length){$(">div",this).set_height({items_per_row: 2,delay: 2000})}});
  $("ul.column-triple").each(function(){$(">li",this).set_height({items_per_row: 3,delay: 2000})});
}

if (window.attachEvent){
	window.attachEvent('onload', onLoaded);
}
else {
	window.addEventListener('load', onLoaded, false);
}
