DOMAssistant.DOMReady(function() {

    // Replace author name with link to toggle contact form
    var oAuthor = $(".author span");
    var oContactForm = $(".form-contact");
    var oToggler;
    if (oAuthor[0] && oContactForm[0]) {
        oContactForm = $$(oContactForm[0]);
        if (!oContactForm.hasClass("has-errors")) {
            oContactForm.addClass("hidden");
        }
        oToggler = $(document).create("a", { href: "#" }, false, oAuthor[0]);
        $(".author").addContent(oToggler);
        oToggler.addEvent("click", function(e) {
            DOMAssistant.preventDefault(e);
            oContactForm.toggleClass("hidden");
        });
    }

    // Append an arrow to all external links	
    $("#main a").each(function() {
        if (this.hostname !== "" && this.hostname !== document.domain && this.protocol !== "mailto:") {
            // Grey arrows as standard
            if (!$(this).hasClass('service')) {
                $(this).addContent('<img src="/i/arrow-up-right-grey.png" alt="(länk till annan webbplats)">');
                $(this).setAttributes({
                    'title': 'Länk till annan webbplats'
                });
            }
        }
    });
    $("#footer a").each(function() {
        if (this.hostname !== "" && this.hostname !== document.domain && this.protocol !== "mailto:") {
            // White arrows in the footer
            $(this).addContent('<img src="/i/arrow-up-right-white.png" alt="(länk till annan webbplats)">');
            $(this).setAttributes({
                'title': 'Länk till annan webbplats'
            });
        }
    });

    // Move all freetext h2's into its related m-h div
    $(".m-alt .m-h div").each(function() {
        $(this).replaceContent($(".m-w h2")[0]);
    });

});
