// ----------------------------------------------------------------------------
// MJL
// ----------------------------------------------------------------------------
MJL.event.add(window, "load", function() {
    MJL.enable.rollover("roll", { 
        disable : "unroll",
        switchers : { on : { cond : /(_a)?(\.[^\.]+)$/g, replace : "_o$2" },
                      off : { cond : "", replace : "" }}
    });
    MJL.enable.window("window");
    MJL.enable.window("imgDownload");
    MJL.enable.window("share", {
        width : 650,
        height : 465,
        toolbar : "no",
        menubar : "no",
        scrollbars : "no"
    });
}, false);


// ----------------------------------------------------------------------------
// Extend Scripts with MJL
// ----------------------------------------------------------------------------
(function(){
    // --------------------------------
    // IE6アップグレード促進
    // http://www.ie6countdown.com/
    // --------------------------------
    function promoteIEUpgrade() {
        //バナーはhttp://tumblr.com/x9o1ofzdciを利用。
        var html = "<p class='doc-promote-ie-upgrade'>" + 
                   "<a href='http://www.microsoft.com/japan/windows/products/winfamily/ie/function/default.mspx'>" + 
                   "<img src='/shared/images/bnr_ieupgrade.jpg' width='820' height='42' " + 
                   "alt='あなたが使用中のブラウザはすでに時代遅れです。今すぐ無料で最新のブラウザにアップグレードして快適なネットライフを！' />" + 
                   "</a></p>";
        
        var nodes = MJL.convNode(html);
        var headerElem = document.getElementById("headerArea");
        headerElem.appendChild(nodes);
        headerElem.style.height = "154px";
    }
    
    
    // ------------------------
    // イベントバインド
    // ------------------------
    if(MJL.ua.trident && MJL.ua.version < 7) {
        MJL.event.add(window, "load", function() {
            promoteIEUpgrade();
        });
    }
}());


// ----------------------------------------------------------------------------
// Extend Scripts with Skyward Design JavaScript Library
// ----------------------------------------------------------------------------
/*jslint browser: true, forin: true, eqeqeq: true, undef: true */
var SDJL;
if(!SDJL) {
    SDJL = {};
} else if(typeof SDJL !== "object") {
    throw new Error("Namespace 'SDJL' already exists.");
}

// ------------------------
// User-Agent簡易判定
// ------------------------
SDJL.mobile = (function() {
    var ua = navigator.userAgent;
    var ret = {
        ios        : false,
        android    : false,
        windows    : false,
        smartphone : false
    };
    
    if(ua.indexOf("iPhone") > 0 || ua.indexOf("iPad") > 0 || ua.indexOf("iPod") > 0) {
        // iOS搭載端末
        ret.ios = true;
        if(ua.indexOf("iPad") === -1) {
            ret.smartphone = true;
        }
    } else if(ua.indexOf("Android") > 0) {
        // Android搭載端末
        ret.android = true;
        if(ua.indexOf("Mobile") > 0) {
            // 標準ブラウザ利用のAndroidスマートフォン
            ret.smartphone = true;
        }
    } else if(ua.indexOf("IEMobile") > 0) {
        // Windows搭載端末
        ret.windows = true;
        ret.smartphone = true;
    }
    
    return ret;
}());


// ----------------------------------------------------------------------------
// Extend Scripts with jQuery
// ----------------------------------------------------------------------------
"jQuery" in window && (function($) {
    // スマートフォン向けCSS追加
    if(SDJL.mobile.smartphone) {
        $("head").append("<link rel=\"stylesheet\" type=\"text/css\" href=\"/shared/css/smartphone.css\" />");
    }
    
    $(function() {
        // ARIA role属性設定
        $("body").attr("role", "document");
        $("#headerArea").attr("role", "banner");
        $("#globalNav").attr("role", "navigation");
        $("#mainContentsArea").attr("role", "main");
        $("#mainContentsArea .hentry").attr("role", "article");
        $("#subArea").attr("role", "complementary");
        $("#footerArea").attr("role", "contentinfo");
        
        // jquery.lightbox
        $.fn.lightBox && $("a[rel *= 'lightbox']").lightBox();
        
        // スマートフォン対応
        if(SDJL.mobile.smartphone) {
            if($("body[class != 'home']")) {
                // 見出し画像の変更
                var $target = $("h1 > img");
                var orgSrc = $target.attr("src");
                var minSrc = orgSrc.replace(".jpg", "_min.jpg");
                $target.attr("src", minSrc).attr("width", "580");
            }
        }
        
        // IE8以下likeボタン非表示化
        if(MJL.ua.trident && MJL.ua.version <= 8) {
            $(".sharing .facebook").css("display", "none");
        }
    });
})(jQuery);

