MJL.event.add(window, "load", function() {
    // MJL に関係するコードはこの中に記述 	
    MJL.enable.flash("flash");
    MJL.enable.window("popup-vs", { width : 800, height: 594, toolbar : "no", menubar : "no"});
	MJL.enable.window("popup-diary", { width : 620, height: 535, toolbar : "no", menubar : "no"});
	MJL.enable.window("popup-mailmagazin", { width : 620, height: 505, toolbar : "no", menubar : "no"});
	MJL.enable.window("popup-mobile", { width : 170, height: 610, toolbar : "no", menubar : "no"});
    MJL.enable.heightEqualizer("list-handwriting-01-inner", {groupBy : 3});
    MJL.enable.heightEqualizer("list-product-01-inner", {groupBy : 2});
	MJL.enable.heightEqualizer("list-related-product-01-inner");
	MJL.enable.heightEqualizer("box-look-01");
	MJL.enable.heightEqualizer("column4");
    MJL.enable.heightEqualizer("list-aisyou-04", {groupBy : 2});
	MJL.enable.heightEqualizer("list-eco-feature-01-inner", {
    groupBy : 2,
    collect : function(parent) {
        var nodes = MJL.getChildElements(parent);
        // first のみ除外 
        return (nodes.length > 0) ? nodes.slice(1) : nodes;
    }
});
    MJL.enable.heightEqualizer("column4", {
        collect : function(parent) {
            return MJL.getElementsByClassName(parent, "explanation");
        }
    });
    MJL.enable.heightEqualizer("column5", {
        collect : function(parent) {
            return MJL.getElementsByClassName(parent, "explanation");
        }
    });
    MJL.enable.heightEqualizer("column2", {
        collect : function(parent) {
            return MJL.getElementsByClassName(parent, "box-contents-01");
        }
    });

    MJL.enable.rollover("roll", { disable : "unroll" });
    MJL.enable.tab("tabs");
    //
    // 画像とテキスト (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 = $("p.image img", imgBlock).width(); // 画像幅 
            imgBlock.css("width", imgWidth+"px"); // 画像幅を強制 
            // 別カラムの margin を調整 
            $("div.column", obj).css("margin-"+side,
                                     imgBlock[0].offsetWidth+"px");
        };
    }
    // 実行 
    $(".image-parallel.image-L").each(getImgParallelStyler("left"));
    $(".image-parallel.image-R").each(getImgParallelStyler("right"));
}, false);


// ----------------------------------------------------------------------------
// not MJL Script
// ----------------------------------------------------------------------------


$(function(){
		   
    //tab
    (function(){
        var path = window.location.search;
        if(path.match(/\?/) && path != ""){
            var prm = path.substring(1,path.length);
		
            if(prm.match(/&/)){
                var prm_sp = prm.split("&");		
                jQuery.each(prm_sp, function() {
                    if(this.match(/tab_id/)){
                        var v = this.split("=")[1];
                        $(".tabs li").each(function(){
                            var getId = $(this).attr("id");
                            if(v == getId){
                                $(this).addClass("active");
                            }
                        });					
                    }
                });	
            }else{
                var v = prm.split("=")[1];
                $(".tabs li").each(function(){
                    var getId = $(this).attr("id");
                    if(v == getId){
                        $(this).addClass("active");
                    }
                });	
            }
        }
	})();
	
    //localNavi
    (function(){
        if($("#nav-primary ul").hasClass("hwList")){
           var locPath = location.pathname.replace(/([A-Za-z0-9]*)(\.html|\.cgi)/i,''),
		   locDir = locPath.split("/").slice(0,4).join("/");
            $("#nav-primary li a").each(function(){
                var ancHref = $(this).attr("href").replace(/([A-Za-z0-9]*)(\.html|\.cgi)/i,''),
                hrefDir = ancHref.split("/").slice(0,4).join("/");
                if (locDir == hrefDir){
                    $(this).closest("ul").css("display", "block");
                    $(this).closest("li").children("ul").css("display", "block");
                }else if(locPath.match(/cgi-bin/)){
				    var locCgi = locPath.replace(/cgi-bin/i, 'handwriting'),
				    locCgDir = locCgi.split("/").slice(0,4).join("/");
					if (locCgDir == hrefDir){
                        $(this).closest("ul").css("display", "block");
                        $(this).closest("li").children("ul").css("display", "block");						
					}					
				}
            });
        };
    })();


    //toggle
    $("a.chg-image-01").each(function(){
        var target = $(this).find("img"),
        imgSrc = target.attr("src"),
        imgSrcOn = imgSrc.replace(/(\.gif)$/, "_o"+"$1");
		
        $(this).toggle(function(){
            target.attr('src', imgSrcOn);
        },function(){
            target.attr('src', imgSrc);
        });
	
    });
	
    //slide-color
    $("div.slide-color").each(function(){

        var setPoint = $(this),
        listImg = setPoint.find("ul.list-colorImg-01"),
        listImages = listImg.find("li"),
        listImgSize = listImg.find("li").size(),
        listBtn = setPoint.find("ul.list-colorBtn-01"),
        listNav = setPoint.find("div.nav-color-01"),
        listNavCl = listNav.find("li"),
        listImgWd = 608,
        listLink = 1,
        listCurrent = 1,
		
        listLeft = function(listCurrent,listLink){
            listImg.find("li.use-img-" + listCurrent).css("left",listImgWd + "px");
            listImg.find("li.use-img-" + listCurrent).animate({"left" : "0px"}, 800, "swing");
            listImg.find("li.use-img-" + listLink).animate({"left" : -listImgWd + "px"}, 800, "swing");
        },
			
        listRight = function(listCurrent,listLink){
            listImg.find("li.use-img-" + listCurrent).css("left", -listImgWd + "px");
            listImg.find("li.use-img-" + listCurrent).animate({"left" : "0px"}, 800, "swing");
            listImg.find("li.use-img-" + listLink).animate({"left" : listImgWd + "px"}, 800, "swing");
        };


        listImg.find("li:first-child").animate({"left" : "0px"}, 0, "swing");
        listImages.each(function(i){
            $(this).addClass("use-img-" + (i + 1));
        });		

        listBtn.find("li.next").click(function(){
            if(!listImages.is(":animated")){
                listLink = listCurrent;
                listCurrent++;
                if(listCurrent == (listImgSize + 1)){
                    listCurrent = 1;
                }
                listLeft(listCurrent,listLink);
            }
        });

        listBtn.find("li.prev").click(function(){
            if(!listImages.is(":animated")){
                listLink = listCurrent;
                listCurrent--;
                if(listCurrent == 0){
                    listCurrent = listImgSize;
                }
                listRight(listCurrent,listLink);
            }
        });

        listNavCl.click(function(){
            if(!listImages.is(":animated")){
                var clLink = $(this).attr("class");
				
                listLink = listCurrent;
                listCurrent = parseInt(clLink.slice(10));
				
                if(listCurrent > listLink){
                    listLeft(listCurrent,listLink);
                }else if(listCurrent < listLink){
                    listRight(listCurrent,listLink);
                }
            }
        });

    });

    //window close
    $(".nav-page-close a").click(function(){
        window.close();
    });

    //label for IE
    /*@cc_on
    $(".check-label").find("label").each(function(){
        var setPoint = $(this),
        setInput = setPoint.find("input");
		
        setPoint.click(function(){
            setInput.attr({checked : "checked"});
        });
    });
    @*/


    if($("div.networks-main-visual")){
	  
        (function(){
		
            var setMap = $("map#Map"),
            setArea = setMap.children("area"),
            targetMap = $("p.networks-line-area"),
            getClass = targetMap.attr("class"),
            setLabel = $("ul.networks-label-list"),
            setLabelList = setLabel.children("li"),
            setCountry = $("ul.networks-country-list"),
            setCountryList = setCountry.children("li"),
            setDot01 = setCountry.find("li.dot01");

            //map background
            setArea.each(function(){
                var setJpOver = setLabel.find("li.japan img"),
                setJpOverSrc = setJpOver.attr("src");
		
                $(this).bind("focusin mouseover",(function(){
                    var num = $(this).index() + 1,
                    setClass =  "map" + "0" + num;		  
                    targetMap.addClass(setClass);
		  
                    if(setClass == "map01"){
                        var chgSrc = setJpOverSrc.replace(/^(.+(?!_o))(\.png)$/,"$1_o$2");
                        setJpOver.attr("src", chgSrc);
                    }
		 
                })).bind("focusout mouseout",(function(){
                    var chkSrc = setJpOverSrc.replace(/^(.+)_o(\.png)$/, "$1$2");
                    setJpOver.attr("src", chkSrc);

                    targetMap.removeClass();
                    targetMap.addClass(getClass);		  
                }));
            });
	  
            //dot active
            setCountryList.each(function(){
		  
                $(this).bind("focusin mouseover",(function(){
                    $(this).addClass("active");
                })).bind("focusout mouseout",(function(){
                    $(this).removeClass("active");
                }));
		
            });

	  	  
            //dot active (dot01)
            setDot01.each(function(){

                var ch = setLabel.find("li.china img"),
                chSrc = ch.attr("src"),
                ca = setLabel.find("li.canada img"),
                caSrc = ca.attr("src"),
                us = setLabel.find("li.usa img"),
                usSrc = us.attr("src"),
                uk = setLabel.find("li.uk img"),
                ukSrc = uk.attr("src"),
                ge = setLabel.find("li.germany img"),
                geSrc = ge.attr("src"),
                me = setLabel.find("li.mexico01 img"),
                meSrc = me.attr("src");
	  
                $(this).bind("focusin mouseover",(function(){
                    var getDotClass = $(this).attr("class").replace(/dot01|active|\s/g,"");

                    switch (getDotClass){
                        case "china":
                            var chgCh = chSrc.replace(/^(.+(?!_o))(\.png)$/,"$1_o$2");
                            ch.attr("src", chgCh);
                            break;
                        case "canada":
                            var chgCa = caSrc.replace(/^(.+(?!_o))(\.png)$/,"$1_o$2");
                            ca.attr("src", chgCa);
                            break;
                        case "usa":
                            var chgUs = usSrc.replace(/^(.+(?!_o))(\.png)$/,"$1_o$2");
                            us.attr("src", chgUs);
                            break;
                        case "uk":
                            var chgUk = ukSrc.replace(/^(.+(?!_o))(\.png)$/,"$1_o$2");
                            uk.attr("src", chgUk);
                            break;
                        case "germany":
                            var chgGe = geSrc.replace(/^(.+(?!_o))(\.png)$/,"$1_o$2");
                            ge.attr("src", chgGe);
                            break;
                        case "mexico01":
                            var chgMe = meSrc.replace(/^(.+(?!_o))(\.png)$/,"$1_o$2");
                            me.attr("src", chgMe);
                            break;
                    }

                })).bind("focusout mouseout",(function(){
                    var getDotClass = $(this).attr("class").replace(/dot01|active|\s/g,"");

                    switch (getDotClass){
                        case "china":
                            var chgCh = chSrc.replace(/^(.+)_o(\.png)$/, "$1$2");
                            ch.attr("src", chgCh);
                            break;
                        case "canada":
                            var chgCa = caSrc.replace(/^(.+)_o(\.png)$/, "$1$2");
                            ca.attr("src", chgCa);
                            break;
                        case "usa":
                            var chgUs = usSrc.replace(/^(.+)_o(\.png)$/, "$1$2");
                            us.attr("src", chgUs);
                            break;
                        case "uk":
                            var chgUk = ukSrc.replace(/^(.+)_o(\.png)$/, "$1$2");
                            uk.attr("src", chgUk);
                            break;
                        case "germany":
                            var chgGe = geSrc.replace(/^(.+)_o(\.png)$/, "$1$2");
                            ge.attr("src", chgGe);
                            break;
                        case "mexico01":
                            var chgMe = meSrc.replace(/^(.+)_o(\.png)$/, "$1$2");
                            me.attr("src", chgMe);
                            break;
                    }
                }));
	
            });
	  
	  
        })();
		
    }
	
});



