﻿MJL.event.add(window, "load", function() {
    MJL.enable.window("popup", {width : 800, height : 600 , menubar:"no", toolbar:"no", status:"no"});
    MJL.enable.heightEqualizer("list-col-2", {groupBy : 2});
    MJL.enable.heightEqualizer("list-col-3", {groupBy : 3});
    MJL.enable.heightEqualizer("list-col-4", {groupBy : 4});
    MJL.enable.heightEqualizer("col-2", {groupBy : 2});
    MJL.enable.heightEqualizer("col-2-bg", {groupBy : 2});
    MJL.enable.heightEqualizer("col-3", {groupBy : 3});
    MJL.enable.heightEqualizer("col-4", {groupBy : 4});
    MJL.enable.rollover("roll", {disable : "unroll"});

    // ------------------------------------------------------------------------
    // 画像とテキスト (based on jQuery)
    // ------------------------------------------------------------------------
    'jQuery' in window && (function() {
        // 画像とテキストの並列処理を行う関数を返す高階関数
        function getImgParallelStyler(side, space) {
            space = isNaN(space) ? 15 : space; // カラム間の空白 (単位:px)
            return function() {
                // img 要素を複数格納する要素
                var block = $('div.image:first-child', this),
                // 対象 img 要素群のうち、最大の横幅 (単位:px)
                    width = Math.max.apply(Math, $.makeArray(
                        block.find('p.image img').map(function() {
                            return $(this).width();
                        })
                    ));
                block.css('width', width+'px'); // 画像幅を強制
                $('div.column', this).css(      // 別カラムの margin を調整
                    'margin-'+side, block.outerWidth()+space+'px'
                );
            };
        }
        // 実行
        $('.image-parallel.image-l').each(getImgParallelStyler('left'));
        $('.image-parallel.image-r').each(getImgParallelStyler('right'));
    })();


    // ------------------------------------------------------------------------
    // サイト内検索 任意種類 URI エンコーディング 対応
    // ------------------------------------------------------------------------
    MJL.ua.trident && (function() {
        var root    = document.getElementById("form-search-word"),
            target  = (( // 対象 form 要素
                root ? root.getElementsByTagName("form") : null
            ) || [])[0],
            charset = target ? target.acceptCharset : "",
            body    = document.body;
        if (target && charset) {
            MJL.event.add(target, "submit", function() {
                var iframe = document.createElement("iframe"),
                    doc, form;
                // 不可視化
                iframe.width = iframe.height = iframe.frameborder = 0;
                iframe.style.position = "absolute";
                iframe.style.top = iframe.style.left = "-9999px";
                // DOM ツリーに存在しないと contentWindow が生成されない
                body.appendChild(iframe);
                // ドキュメント生成・form 要素コピー
                doc = iframe.contentWindow.document;
                doc.open();
                doc.charset = charset; // 指定エンコーディングに変更
                doc.write('<html><body>'+target.outerHTML+'<!-- ======================== i-search用タグここから=================================== -->

<!--#include virtual="/shared/include/word-search/i-search.html" -->

<!-- ======================== i-search用タグここまで=================================== -->
</body></html>');
                doc.close();
                form = doc.forms[0];
                form.target = "_parent"; // 遷移対象を元文書に変更
                form.submit();           // 送信
                // 不要なので掃除
                body.removeChild(iframe);
                return false;
            }, false);
        };
    })();
}, false);

// ----------------------------------------------------------------------------
// Non-MJL Scripts
// ----------------------------------------------------------------------------
'jQuery' in window && $(function() {
    // ストライプテーブル
    $('table.stripe > tbody > tr:nth-child(2n)').addClass('even');
    // 新規ウインドウ用「閉じる」ボタン挿入
    $('body.insert-btn-01 #str-main').append(
        $('<p class="doc-align-c roll"></p>').append(
            $('<input type="image" src="/toto/shared/images/contents-mod/btn-close-01.gif" alt="閉じる" />').click(function() {
                window.close();
                return false;
            })
        )
    );
});
