MJL.event.add(window, "load", function() {
    // MJL に関係するコードはこの中に記述
    MJL.enable.window("window");
    MJL.enable.window("window_map", { width : 670,  height : 510, toolbar : "no" });
    MJL.enable.heightEqualizer("equalize");
	MJL.enable.rollover("roll-active", { active : "active" });
	MJL.enable.rollover("roll", { disable : "unroll" });
});

// MJL と無関係なコードはこの先に記述

/**
 * jQuery setLocalMenuActive plugin
 * ローカルナビゲーション現在地表示の自動化処理
 */
(function($){
    var name_space = 'setLocalMenuActive';
    $.fn[name_space] = function(options){
		$('dl#nav-local dd ul li ul').hide();
        var elements = $(this);
        var pagePathA = location.pathname.replace('index.html','').split('#')[0];
        function get(){
            return function(){
				//通常の処理。（表示しているページと同じリンクパスのローカルナビに現在地表示を実行。）
                var hrefA = $(this).attr('href').replace('index.html','').split('#')[0];
                if(pagePathA == hrefA){
                    $(this).addClass("active");
                    $(this).parents('li').addClass("current"); 
					$('dl#nav-local dd ul li.current > ul').show();
					return false;
                }else{
				//「取扱品一覧」、「ニュース」専用の処理。（表示しているページと同じ最深ディレクトリのローカルナビに現在地表示を実行。）
					var exception = location.pathname.replace('index.html','').split('#')[0];
					if(exception == "/products/pc-supply/"){return false;} //例外処理　「PCサプライ」インデックスページでは動作させない。
					else{
						var category = location.pathname.replace('index.html','').split('/')[1];
						if((category == "chinese")|| (category == "english")){//中文サイト、グローバルサイトの場合の処理。
							var category = location.pathname.replace('index.html','').split('/')[2];
						}
						if((category == "products")|| (category == "news")){
							var pagePathB = location.pathname.replace(/(.+)\/(.+)\.html/, '$1/').split('#')[0];
							var hrefB = $(this).attr('href').replace(/(.+)\/(.+)\.html/, '$1/').split('#')[0];
							if(pagePathB == hrefB){
							$(this).addClass("active");
							$(this).parents('li').addClass("current"); 
							$('dl#nav-local dd ul li.current > ul').show();
							}
						}
					}
				}
            }
        }
        elements.each(get());
        return this;
    };
    $(function(){
        $('dl#nav-local dd ul li a').setLocalMenuActive();
    });
})(jQuery);

/**
 * jQuery setImgParallelStyler plugin
 * 画像とキャプションの幅を揃える
 * 
 */
 $(document).ready(function(){
    $('p.image_L').setImgAndCaptionStyler();
    $('p.image_R').setImgAndCaptionStyler();
	$('ul.image_02 li').setImgAndCaptionStyler();
	$('ul.image_03 li').setImgAndCaptionStyler();
});

(function($){
    var name_space = 'setImgAndCaptionStyler';
    $.fn[name_space] = function(options){
        var elements = $(this);
        function getImgAndCaptionStyler(){
            return function(){
                var elm = $(this);
                var img = $("img", elm);
                function resize(){
                    var imgWidth = img.width();
                    var caption = $(">span", elm)
                    if(imgWidth){
                        caption.css("width", imgWidth);
                    }
                }
                resize();
                img.load(function(){resize()});
            }
        }
        elements.each(getImgAndCaptionStyler());
        return this;
    };
})(jQuery);

/**
 * :focus が効かないIE6向けに .focus を付与する
 * （1行テキスト入力欄とテキストエリアにフォーカス時、背景色を変更させるため）
 */
(function ($) { 
	$(document).ready(function(){
		if(!$.support.style){
			$('input[type="text"], textarea').focus(function(){
				this.className += ' focus';
			}).blur(function(){
				this.className = this.className.replace(/focus/, '');
			});
		}
	});
})(jQuery);

/**
 * jQuery setLightBox plugin
 * ColorBox jQuery pluginの実行
 */
(function ($) {
    var name_space = 'setLightBox';
    $.fn[name_space] = function () {
        var elements = $(this);
        function get() {
            return function () {
				var target1 = $(this).attr('rel');
				if(target1.match('lightbox_01')){
					$("a[rel='lightbox_01']").colorbox();
				}
				var target2 = $(this).attr('rel');
				if(target2.match('lightbox_02')){
					$("a[rel='lightbox_02']").colorbox();
				}
            }
        }
        elements.each(get());
        return this;
    };
    $(function () {
        $('#main p.image_01 a').setLightBox();
        $('#main ul.image_02 a').setLightBox();
        $('#main ul.image_03 a').setLightBox();
        $('#main p.image_L a').setLightBox();
        $('#main p.image_R a').setLightBox();
    });
})(jQuery);
