MJL.event.add(window, "load", function(event) {
    //
    // 画像とテキスト (based on jQuery)
    //
    // 画像とテキストの並列処理を行う関数を返す高階関数
    function getImgParallelStyler(side) {
        // side は既定値しか認めない
        if ("left" != side && "right" != side) {
            throw Error("invalid side type: '"+side+"'");
        }
        // 実行関数
        return function() {
            var obj = $(this);
            var imgBlock = $("div.image:first-child", obj);
            var imgWidth = $("img", imgBlock).width(); // 画像幅
            imgBlock.css("width", imgWidth+"px"); // 画像幅を強制
            // 別カラムの width を調整
            $("div.column", obj).css("width",618-
                                     imgBlock[0].offsetWidth+"px");
        };
    }
// 実行
    $(".image-parallel.image-L").each(getImgParallelStyler("left"));
    $(".image-parallel.image-R").each(getImgParallelStyler("right"));

    function getImgParallelStyler2() {
        // 実行関数
        return function() {
            var imgBlock2 = $(this);
            var imgWidth2 = $("img", imgBlock2).width(); // 画像幅
            imgBlock2.css("width", imgWidth2+"px"); // 画像幅を強制
        };
    }

    $(".lyt-news-image p.image").each(getImgParallelStyler2());


    MJL.enable.rollover("roll", {disable : "unroll"});
    MJL.enable.flash("flash", {version:8});
    MJL.enable.styleSwitcher("styleSwitcher");
    MJL.enable.heightEqualizer("column-col2", {
        groupBy : 2,
        collect : function(parent) {
            return MJL.getElementsByClassName(parent, "hdg-l3-02");
        }
    });
    MJL.enable.heightEqualizer("column-col2", {
        groupBy : 2,
        collect : function(parent) {
            return MJL.getElementsByClassName(parent, "list-service-01");
        }
    });
    MJL.enable.heightEqualizer("column-col2", {
        groupBy : 2,
        collect : function(parent) {
            return MJL.getElementsByClassName(parent, "box-relation-03");
        }
    });
    MJL.enable.heightEqualizer("column-col2", {
        groupBy : 2,
        collect : function(parent) {
            return MJL.getElementsByClassName(parent, "box-relation-02");
        }
    });
    MJL.enable.heightEqualizer("column-col2", {groupBy : 2});
    MJL.enable.heightEqualizer("column-col3", {
        groupBy : 3,
        collect : function(parent) {
            return MJL.getElementsByClassName(parent, "hdg-l3-02");
        }
    });
    MJL.enable.heightEqualizer("column-col3", {
        groupBy : 3,
        collect : function(parent) {
            return MJL.getElementsByClassName(parent, "list-service-01");
        }
    });
    MJL.enable.heightEqualizer("column-col3", {
        groupBy : 3,
        collect : function(parent) {
            return MJL.getElementsByClassName(parent, "box-relation-03");
        }
    });
    MJL.enable.heightEqualizer("column-col3", {
        groupBy : 3,
        collect : function(parent) {
            return MJL.getElementsByClassName(parent, "box-relation-02");
        }
    });
    MJL.enable.heightEqualizer("column-col3", {groupBy : 3});
    MJL.enable.heightEqualizer("column-col4", {
        groupBy : 4,
        collect : function(parent) {
            return MJL.getElementsByClassName(parent, "hdg-l3-02");
        }
    });
    MJL.enable.heightEqualizer("column-col4", {
        groupBy : 4,
        collect : function(parent) {
            return MJL.getElementsByClassName(parent, "box-relation-02");
        }
    });
    MJL.enable.heightEqualizer("column-col4", {groupBy : 4});
    MJL.enable.heightEqualizer("list-index-01-col2", {
        groupBy : 2,
        collect : function(parent) {
            return MJL.getElementsByClassName(parent, "content");
        }
    });
    MJL.enable.heightEqualizer("list-index-01-col3", {
        groupBy : 3,
        collect : function(parent) {
            return MJL.getElementsByClassName(parent, "content");
        }
    });
    MJL.enable.heightEqualizer("list-index-01-col4", {groupBy : 4});
}, false);

$(document).ready(function(){
  $('ul.list-index-02 li:first-child').addClass('first-child');
  $("h1 + .hdg-l2-01").css("margin-top", "0px");
  $("h1 + .hdg-l2-02").css("margin-top", "0px");
  $("h1 + .hdg-l2-03").css("margin-top", "0px");
  $("h1 + .hdg-l2-05").css("margin-top", "0px");
  $(".hdg-l2-01 + .hdg-l3-01").css("margin-top", "0px");
  $(".hdg-l2-02 + .hdg-l3-01").css("margin-top", "0px");
  $(".hdg-l2-03 + .hdg-l3-01").css("margin-top", "0px");
  $(".hdg-l2-05 + .hdg-l3-01").css("margin-top", "0px");
});

$(document).ready(function(){
//検索フォーム文字入力エリアの背景画像
  $('.form-search-keywords')
    .blur(function(){
      var $$=$(this);
      if($$.val()==''){
        $$.css('background-image', 'url(/shared/images/str-header/bg_form-search-keywords.gif)')
          .css('background-position', '5px 50%')
          .css('background-repeat', 'no-repeat');
      }
    })
    .focus(function(){
      var $$=$(this);
      if($$.val()==''){
        $$.removeAttr('style');
      }
    })
    .blur();

  $('.form-search-keywords-eng')
    .blur(function(){
      var $$=$(this);
      if($$.val()==''){
        $$.css('background-image', 'url(/shared/images/str-header/eng_bg_form-search-keywords.gif)')
          .css('background-position', '5px 50%')
          .css('background-repeat', 'no-repeat');
      }
    })
    .focus(function(){
      var $$=$(this);
      if($$.val()==''){
        $$.removeAttr('style');
      }
    })
    .blur();
  });

$(document).ready(function(){
    /* Local navigation control */
    $('ul#nav-local li > ul').css("display","none"); //入れ子のリストを非表示

    var $path = window.location.pathname;
    if($path.match(/\/index.html/)){
        $path = $path.replace("/index.html", "/");
    }
    $('ul#nav-local a').each(function(){
        if($(this).attr("href").match(/\/index.html/)){
            this.href = this.href.replace("/index.html", "/");
        }
    });
    var $folders = $path.split("/");
    var $cur_folder = "";
    var $pathmatch = 0;
    for(var i=$folders.length; i>=2; i--){
        $cur_folder = $folders[i];
        var $path2 = $path.replace($folders[i], "").replace(/(\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]*)$/, "/");
        if($pathmatch==0){
            $('ul#nav-local a[href$="'+$path2+'"]').each(function(){
                $(this).parent("li").addClass("selected");
                $pathmatch++;
            });
            $('ul#nav-local a[href$="'+$path2+'#china"]').each(function(){
                $(this).parent("li").addClass("selected");
                $pathmatch++;
            });
            $('ul#nav-local a[href$="'+$path2+'#austria"]').each(function(){
                $(this).parent("li").addClass("selected");
                $pathmatch++;
            });
            $('ul#nav-local a[href$="'+$path2+'#hungary"]').each(function(){
                $(this).parent("li").addClass("selected");
                $pathmatch++;
            });
            $('ul#nav-local a[href$="'+$path2+'#poland"]').each(function(){
                $(this).parent("li").addClass("selected");
                $pathmatch++;
            });
            $('ul#nav-local a[href$="'+$path2+'#sweden"]').each(function(){
                $(this).parent("li").addClass("selected");
                $pathmatch++;
            });
            $('ul#nav-local a[href$="'+$path2+'#spain"]').each(function(){
                $(this).parent("li").addClass("selected");
                $pathmatch++;
            });
            $('ul#nav-local a[href$="'+$path2+'#turkey"]').each(function(){
                $(this).parent("li").addClass("selected");
                $pathmatch++;
            });
            $('ul#nav-local a[href$="'+$path2+'#belgium"]').each(function(){
                $(this).parent("li").addClass("selected");
                $pathmatch++;
            });
            $('ul#nav-local a[href$="'+$path2+'#luxembourg"]').each(function(){
                $(this).parent("li").addClass("selected");
                $pathmatch++;
            });
        }
    }
    
    $('ul#nav-local li.selected').parents("ul").css("display", "block"); //現在地のリンクのあるすべての親ulを表示
    $('ul#nav-local li.selected > ul').css("display", "block"); //現在地のリンクのある子供ulを表示

    //リンクのないliの直下のulを表示
/*    $('ul#nav-local li.selected > ul > li > span').parent("li").addClass("directory");
    $('ul#nav-local li.selected > ul > li.directory > ul').css("display", "block");
*/
    //上位階層とurlが同じ場合、上位階層のカレント表示オフにする
    $('ul#nav-local li.selected > ul > li.selected').parent("ul").parent("li.selected").removeClass("selected");

    // span:hoverに対応しないIE6対策
    $('div#str-sub ul#nav-local li span').mouseover(
      function () {
        $(this).css('background', '#c7dbec url(/shared/images/str-sub/bullet_nl_01_o.gif) 8px 0.2em no-repeat');
      }
    );
    $('div#str-sub ul#nav-local li ul li span').mouseover(
      function () {
        $(this).css('background', '#c7dbec url(/shared/images/str-sub/bullet_nl_02_o.gif) 16px 0.6em no-repeat');
      }
    );
    $('div#str-sub ul#nav-local li ul li ul li span').mouseover(
      function () {
        $(this).css('background', '#c7dbec url(/shared/images/str-sub/bullet_nl_03_o.gif) 27px 0.9em no-repeat');
      }
    );
    $('div#str-sub ul#nav-local li ul li ul li ul li span').mouseover(
      function () {
        $(this).css('background', '#c7dbec url(/shared/images/str-sub/bullet_nl_04.gif) 39px 1em no-repeat');
      }
    );
    $('div#str-sub ul#nav-local li span').mouseout( function () {$(this).removeAttr('style'); } );

    $('ul#nav-local li > span').click(function () { $(this).next().toggle(); });

});


$(document).ready(function(){
/* global navigation scanner */
  var gnscan = $("body").attr("id");
  $("li#ng-"+gnscan+" a").addClass("unroll");
  $("li#ng-"+gnscan+" a img").attr("src", "/shared/images/nav-global/ng-"+gnscan+"_o.gif");

  //topグローバルナビゲーション
  $('body#home div#nav-global > ul > li').hover(
    function () {
      var homescan = $(this).attr("id");
      $(this).css('background-image', 'url(/images/home/bg_nav-global_o.gif)');
      $(this).children("a").children("img").attr("src", "/shared/images/nav-global/"+homescan+"_o.gif");
    },
    function () {
      var homescan = $(this).attr("id");
      $(this).removeAttr('style');
      $(this).children("a").children("img").attr("src", "/shared/images/nav-global/"+homescan+".gif");
    }
  );
});




//画像のロールオーバー
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



// QuickSearch初期画面時の入力チェック
function select() {
  i = 0
  T1_Text=document.YASHPTOP.T1.value
  while (T1_Text.indexOf(" ")==0) {
    T1_Text = T1_Text.replace(" ","");
  }
  LineLength=T1_Text.length
  while (T1_Text.charAt(LineLength-1)==" ") {
    LineLength=LineLength-1
  }
  T1_Text=T1_Text.slice(0,LineLength)
  if (T1_Text != "YAS-" && document.YASHPTOP.T1.value != "YAS-") {
    if (document.YASHPTOP.T1.value != "" && (document.YASHPTOP.T1.value.match("^[\\s]+$") == null)){
      i = i + 1;
    }
  }
  if (i > 1) {
    alert("Please input only one number");
    document.YASHPTOP.T1.focus();
    return(false);
  }
  if (i == 0) {
    alert("Please input a correct number.");
    document.YASHPTOP.T1.focus();
    return(false);
  }
  return(true);
}

