var $ = jQuery.noConflict();
var this_js_script = $('script[src*=accessibilitymenu]'); // or better regexp to get the file name..

var debugMode = false;

//var lang = this_js_script.attr('data-language');
//if (typeof lang === "undefined") {
//    var lang = 'heb';
//}

var lang = getScriptAttribute(this_js_script, "language", "eng");
var accessibilitySign = getScriptAttribute(this_js_script, "sign", "classic");
var sourceMenu = getScriptAttribute(this_js_script, "oemsource", "regular");

if (sourceMenu == "accessible+") {
    if (typeof curLang != "undefined") {
        if (debugMode) console.log(curLang);
        lang = curLang;
    } else {
        switch (lang) {
            case "heb":
                lang = "he_IL";
                break;
            case "eng":
                lang = "en_US";
        }
    }
} else {
    switch (lang) {
        case "heb":
            lang = "he_IL";
            break;
        case "eng":
            lang = "en_US";
    }
}

var accessibilityIconStr = (accessibilitySign === "classic") ? 'accessibility-menu/accessibility.png' : 'accessibility-menu/access.png';

if (debugMode) console.log("loaded with language: " + lang);

var accessibilityShown = false;
var textSizeBigger = false;
var areLinksYellow = false;
var isGrayscale = false;
var isHighContrast = false;
var areLinksUnderlined = false;


var delimiter = "|";
var cookieName = "accessibility";

var init = true;


prepMenu();

setAccessibityFromCookie();
makeAccessible();

function getScriptAttribute(scriptObject, attributeName, defaultValue) {
    var tmp = scriptObject.attr('data-' + attributeName);
    if (typeof tmp === "undefined") {
        var tmp = defaultValue;
    }
    return tmp;
}

function prepMenu() {
    console.log("############################prepMenu");

    var cssText = "<link href='accessibility-menu/yellow-links.css' title='yellow' type='text/css' rel='stylesheet' disabled='true'/>";
    cssText += "<link href='accessibility-menu/underline-links.css' title='underline' type='text/css' rel='stylesheet' disabled='true'/>";
    cssText += "<link href='accessibility-menu/grayscale.css' title='grayscale' type='text/css' rel='stylesheet' disabled='true'/>";

    if (sourceMenu == "accessible+") {
        cssText += "<link href='accessibility-menu/night.css' title='contrast' type='text/css' rel='stylesheet' disabled='true'/>";
        cssText += "<link href='accessibility-menu/biggest.css' title='textsize' type='text/css' rel='stylesheet' disabled='true'/>";
    } else {
        cssText += "<link href='accessibility-menu/high-contrast.css' title='contrast' type='text/css' rel='stylesheet' disabled='true'/>";
        cssText += "<link href='accessibility-menu/bigger.css' title='textsize' type='text/css' rel='stylesheet' disabled='true'/>";
    }





    $("head").append(cssText);



    $("nav.navPlacementStyle").append("<div id='slideout'></div>");
    var menuHTML = "";



    menuHTML += "<button class='transparentButton pull-right' onclick='toggleAccessibilityMenu()'><img class='accessibilityimage' src='" + accessibilityIconStr + "' alt='Accessible Menu Icon' role='navigation' title='Accessible Menu'/></button>";


    switch (lang) {
        case "he_IL":
            menuHTML += "<ul class='rtl'>";
            menuHTML += "<li class='accessibilityMenuButton alignRight' id='btnTextSizeOn' onclick='setTextSize(true);'><i class='fa fa-text-height' aria-hidden='true'></i>&nbsp;&nbsp;גודל גופן גדול</li>";
            menuHTML += "<li class='accessibilityMenuButton alignRight' id='btnTextSizeOff' onclick='setTextSize(false);'><i class='fa fa-font' aria-hidden='true'></i>&nbsp;&nbsp;גודל גופן רגיל </li>";
            menuHTML += "<li class='accessibilityMenuButton alignRight' id='btnHighContrastOn' onclick='ToggleHighContrastMode(true);'><i class='fa fa-adjust' aria-hidden='true'></i>&nbsp;&nbsp;מצב ניגודיות גבוהה</li>";
            menuHTML += "<li class='accessibilityMenuButton alignRight' id='btnHighContrastOff' onclick='ToggleHighContrastMode(false);'><i class='fa fa-adjust' aria-hidden='true'></i>&nbsp;&nbsp;מצב ניגודיות רגילה</li>";
            menuHTML += "<li class='accessibilityMenuButton alignRight' id='btnYellowLinksOn'onclick='ToggleLinksYellow(true);'><i class='fa fa-pencil' aria-hidden='true'></i>&nbsp;&nbsp;הדגש קישורים בצהוב</li>";
            menuHTML += "<li class='accessibilityMenuButton alignRight' id='btnYellowLinksOff' onclick='ToggleLinksYellow(false);'><i class='fa fa-pencil' aria-hidden='true'></i>&nbsp;&nbsp;הצג קישורים כרגיל</li>";
            menuHTML += "<li class='accessibilityMenuButton alignRight' id='btnGrayscaleOn' onclick='ToggleGrayscaleMode(true);'><i class='fa fa-barcode' aria-hidden='true'></i>&nbsp;&nbsp;מצב גווני אפור</li>";
            menuHTML += "<li class='accessibilityMenuButton alignRight' id='btnGrayscaleOff' onclick='ToggleGrayscaleMode(false);'><i class='fa fa-barcode' aria-hidden='true'></i>&nbsp;&nbsp;מצב צבע רגיל</li>";
            menuHTML += "<li class='accessibilityMenuButton alignRight' id='btnLinksOn' onclick='ToggleUnderlineLinks(true);'><i class='fa fa-underline' aria-hidden='true'></i>&nbsp;&nbsp;הצג קו תחת קישורים</li>";
            menuHTML += "<li class='accessibilityMenuButton alignRight' id='btnLinksOff' onclick='ToggleUnderlineLinks(false);'><i class='fa fa-underline' aria-hidden='true'></i>&nbsp;&nbsp;הצג קישורים כרגיל</li>";
            break;
        case "en_US":
            menuHTML += "<ul class='ltr pull-left '>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnTextSizeOn' onclick='setTextSize(true);'><i class='fa fa-text-height' aria-hidden='true'></i>&nbsp;&nbsp;large font</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnTextSizeOff' onclick='setTextSize(false);'><i class='fa fa-font' aria-hidden='true'></i>&nbsp;&nbsp;normal font </li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnHighContrastOn' onclick='ToggleHighContrastMode(true);'><i class='fa fa-adjust' aria-hidden='true'></i>&nbsp;&nbsp;high contrast mode</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnHighContrastOff' onclick='ToggleHighContrastMode(false);'><i class='fa fa-adjust' aria-hidden='true'></i>&nbsp;&nbsp;regular contrast mode</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnYellowLinksOn'onclick='ToggleLinksYellow(true);'><i class='fa fa-pencil' aria-hidden='true'></i>&nbsp;&nbsp;yellow colored links</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnYellowLinksOff' onclick='ToggleLinksYellow(false);'><i class='fa fa-pencil' aria-hidden='true'></i>&nbsp;&nbsp;normal colored links</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnGrayscaleOn' onclick='ToggleGrayscaleMode(true);'><i class='fa fa-barcode' aria-hidden='true'></i>&nbsp;&nbsp;grayscale color mode</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnGrayscaleOff' onclick='ToggleGrayscaleMode(false);'><i class='fa fa-barcode' aria-hidden='true'></i>&nbsp;&nbsp;regular color mode</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnLinksOn' onclick='ToggleUnderlineLinks(true);'><i class='fa fa-underline' aria-hidden='true'></i>&nbsp;&nbsp;underline links</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnLinksOff' onclick='ToggleUnderlineLinks(false);'><i class='fa fa-underline' aria-hidden='true'></i>&nbsp;&nbsp;default links</li>";


            break;
        case "es_ES":
            menuHTML += "<ul class='ltr'>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnTextSizeOn' onclick='setTextSize(true);'><i class='fa fa-text-height' aria-hidden='true'></i>&nbsp;&nbsp;letra grande</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnTextSizeOff' onclick='setTextSize(false);'><i class='fa fa-font' aria-hidden='true'></i>&nbsp;&nbsp;letra normal</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnHighContrastOn' onclick='ToggleHighContrastMode(true);'><i class='fa fa-adjust' aria-hidden='true'></i>&nbsp;&nbsp;modo de contraste alto</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnHighContrastOff' onclick='ToggleHighContrastMode(false);'><i class='fa fa-adjust' aria-hidden='true'></i>&nbsp;&nbsp;modo de contraste regulares</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnYellowLinksOn'onclick='ToggleLinksYellow(true);'><i class='fa fa-pencil' aria-hidden='true'></i>&nbsp;&nbsp;amarillo eslabones de color</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnYellowLinksOff' onclick='ToggleLinksYellow(false);'><i class='fa fa-pencil' aria-hidden='true'></i>&nbsp;&nbsp;eslabones de color normales</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnGrayscaleOn' onclick='ToggleGrayscaleMode(true);'><i class='fa fa-barcode' aria-hidden='true'></i>&nbsp;&nbsp;modo de color en escala de grises</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnGrayscaleOff' onclick='ToggleGrayscaleMode(false);'><i class='fa fa-barcode' aria-hidden='true'></i>&nbsp;&nbsp;modo de color normal</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnLinksOn' onclick='ToggleUnderlineLinks(true);'><i class='fa fa-underline' aria-hidden='true'></i>&nbsp;&nbsp;subrayar los enlaces</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnLinksOff' onclick='ToggleUnderlineLinks(false);'><i class='fa fa-underline' aria-hidden='true'></i>&nbsp;&nbsp;enlaces normales</li>";
            break;
        case "pt_PT":
            menuHTML += "<ul class='ltr'>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnTextSizeOn' onclick='setTextSize(true);'><i class='fa fa-text-height' aria-hidden='true'></i>&nbsp;&nbsp;letra grande</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnTextSizeOff' onclick='setTextSize(false);'><i class='fa fa-font' aria-hidden='true'></i>&nbsp;&nbsp;fonte normal</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnHighContrastOn' onclick='ToggleHighContrastMode(true);'><i class='fa fa-adjust' aria-hidden='true'></i>&nbsp;&nbsp;modo de alto contraste</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnHighContrastOff' onclick='ToggleHighContrastMode(false);'><i class='fa fa-adjust' aria-hidden='true'></i>&nbsp;&nbsp;modo de contraste regulares</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnYellowLinksOn'onclick='ToggleLinksYellow(true);'><i class='fa fa-pencil' aria-hidden='true'></i>&nbsp;&nbsp;ligações de cor amarela</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnYellowLinksOff' onclick='ToggleLinksYellow(false);'><i class='fa fa-pencil' aria-hidden='true'></i>&nbsp;&nbsp;ligações coloridas normais</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnGrayscaleOn' onclick='ToggleGrayscaleMode(true);'><i class='fa fa-barcode' aria-hidden='true'></i>&nbsp;&nbsp;modo de cor em tons de cinza</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnGrayscaleOff' onclick='ToggleGrayscaleMode(false);'><i class='fa fa-barcode' aria-hidden='true'></i>&nbsp;&nbsp;modo de cor normal</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnLinksOn' onclick='ToggleUnderlineLinks(true);'><i class='fa fa-underline' aria-hidden='true'></i>&nbsp;&nbsp;sublinhar os links</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnLinksOff' onclick='ToggleUnderlineLinks(false);'><i class='fa fa-underline' aria-hidden='true'></i>&nbsp;&nbsp;ligações normais</li>";
            break;
        case "ja_JP":
            menuHTML += "<ul class='ltr'>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnTextSizeOn' onclick='setTextSize(true);'><i class='fa fa-text-height' aria-hidden='true'></i>&nbsp;&nbsp;大きなフォント</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnTextSizeOff' onclick='setTextSize(false);'><i class='fa fa-font' aria-hidden='true'></i>&nbsp;&nbsp;通常のフォント </li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnHighContrastOn' onclick='ToggleHighContrastMode(true);'><i class='fa fa-adjust' aria-hidden='true'></i>&nbsp;&nbsp;ハイコントラストモード</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnHighContrastOff' onclick='ToggleHighContrastMode(false);'><i class='fa fa-adjust' aria-hidden='true'></i>&nbsp;&nbsp;定期的なコントラストモード</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnYellowLinksOn'onclick='ToggleLinksYellow(true);'><i class='fa fa-pencil' aria-hidden='true'></i>&nbsp;&nbsp;黄色のリンク</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnYellowLinksOff' onclick='ToggleLinksYellow(false);'><i class='fa fa-pencil' aria-hidden='true'></i>&nbsp;&nbsp;通常の着色されたリンク</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnGrayscaleOn' onclick='ToggleGrayscaleMode(true);'><i class='fa fa-barcode' aria-hidden='true'></i>&nbsp;&nbsp;グレースケールカラーモード</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnGrayscaleOff' onclick='ToggleGrayscaleMode(false);'><i class='fa fa-barcode' aria-hidden='true'></i>&nbsp;&nbsp;レギュラーカラーモード</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnLinksOn' onclick='ToggleUnderlineLinks(true);'><i class='fa fa-underline' aria-hidden='true'></i>&nbsp;&nbsp;リンクに下線</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnLinksOff' onclick='ToggleUnderlineLinks(false);'><i class='fa fa-underline' aria-hidden='true'></i>&nbsp;&nbsp;デフォルトのリンク</li>";
            break;
        case "it_IT":
            menuHTML += "<ul class='ltr'>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnTextSizeOn' onclick='setTextSize(true);'><i class='fa fa-text-height' aria-hidden='true'></i>&nbsp;&nbsp;font grande</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnTextSizeOff' onclick='setTextSize(false);'><i class='fa fa-font' aria-hidden='true'></i>&nbsp;&nbsp;carattere normale </li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnHighContrastOn' onclick='ToggleHighContrastMode(true);'><i class='fa fa-adjust' aria-hidden='true'></i>&nbsp;&nbsp;modalità ad alto contrasto</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnHighContrastOff' onclick='ToggleHighContrastMode(false);'><i class='fa fa-adjust' aria-hidden='true'></i>&nbsp;&nbsp;modalità di contrasto regolare</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnYellowLinksOn'onclick='ToggleLinksYellow(true);'><i class='fa fa-pencil' aria-hidden='true'></i>&nbsp;&nbsp;giallo collegamenti colorati</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnYellowLinksOff' onclick='ToggleLinksYellow(false);'><i class='fa fa-pencil' aria-hidden='true'></i>&nbsp;&nbsp;normali collegamenti colorati</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnGrayscaleOn' onclick='ToggleGrayscaleMode(true);'><i class='fa fa-barcode' aria-hidden='true'></i>&nbsp;&nbsp;modalità a colori in scala di grigi</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnGrayscaleOff' onclick='ToggleGrayscaleMode(false);'><i class='fa fa-barcode' aria-hidden='true'></i>&nbsp;&nbsp;modalità colore normale</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnLinksOn' onclick='ToggleUnderlineLinks(true);'><i class='fa fa-underline' aria-hidden='true'></i>&nbsp;&nbsp;sottolineare i collegamenti</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnLinksOff' onclick='ToggleUnderlineLinks(false);'><i class='fa fa-underline' aria-hidden='true'></i>&nbsp;&nbsp;collegamenti predefiniti</li>";
            break;
        case "fr_FR":
            menuHTML += "<ul class='ltr'>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnTextSizeOn' onclick='setTextSize(true);'><i class='fa fa-text-height' aria-hidden='true'></i>&nbsp;&nbsp;grande police</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnTextSizeOff' onclick='setTextSize(false);'><i class='fa fa-font' aria-hidden='true'></i>&nbsp;&nbsp;police normale</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnHighContrastOn' onclick='ToggleHighContrastMode(true);'><i class='fa fa-adjust' aria-hidden='true'></i>&nbsp;&nbsp;mode de contraste élevé</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnHighContrastOff' onclick='ToggleHighContrastMode(false);'><i class='fa fa-adjust' aria-hidden='true'></i>&nbsp;&nbsp;mode de contraste régulier</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnYellowLinksOn'onclick='ToggleLinksYellow(true);'><i class='fa fa-pencil' aria-hidden='true'></i>&nbsp;&nbsp;liens de couleur jaune</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnYellowLinksOff' onclick='ToggleLinksYellow(false);'><i class='fa fa-pencil' aria-hidden='true'></i>&nbsp;&nbsp;liens de couleur normale</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnGrayscaleOn' onclick='ToggleGrayscaleMode(true);'><i class='fa fa-barcode' aria-hidden='true'></i>&nbsp;&nbsp;mode couleur en niveaux de gris</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnGrayscaleOff' onclick='ToggleGrayscaleMode(false);'><i class='fa fa-barcode' aria-hidden='true'></i>&nbsp;&nbsp;mode couleur régulière</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnLinksOn' onclick='ToggleUnderlineLinks(true);'><i class='fa fa-underline' aria-hidden='true'></i>&nbsp;&nbsp;souligner les liens</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnLinksOff' onclick='ToggleUnderlineLinks(false);'><i class='fa fa-underline' aria-hidden='true'></i>&nbsp;&nbsp;liens par défaut</li>";
            break;
        case "de_DE":
            menuHTML += "<ul class='ltr'>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnTextSizeOn' onclick='setTextSize(true);'><i class='fa fa-text-height' aria-hidden='true'></i>&nbsp;&nbsp;große Schrift</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnTextSizeOff' onclick='setTextSize(false);'><i class='fa fa-font' aria-hidden='true'></i>&nbsp;&nbsp;normale Schrift</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnHighContrastOn' onclick='ToggleHighContrastMode(true);'><i class='fa fa-adjust' aria-hidden='true'></i>&nbsp;&nbsp;Modus mit hohem Kontrast</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnHighContrastOff' onclick='ToggleHighContrastMode(false);'><i class='fa fa-adjust' aria-hidden='true'></i>&nbsp;&nbsp;regelmäßige Kontrastmodus</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnYellowLinksOn'onclick='ToggleLinksYellow(true);'><i class='fa fa-pencil' aria-hidden='true'></i>&nbsp;&nbsp;gelb gefärbte Links</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnYellowLinksOff' onclick='ToggleLinksYellow(false);'><i class='fa fa-pencil' aria-hidden='true'></i>&nbsp;&nbsp;normale farbige Links</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnGrayscaleOn' onclick='ToggleGrayscaleMode(true);'><i class='fa fa-barcode' aria-hidden='true'></i>&nbsp;&nbsp;Graustufen-Farbmodus</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnGrayscaleOff' onclick='ToggleGrayscaleMode(false);'><i class='fa fa-barcode' aria-hidden='true'></i>&nbsp;&nbsp;regelmäßige Farbmodus</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnLinksOn' onclick='ToggleUnderlineLinks(true);'><i class='fa fa-underline' aria-hidden='true'></i>&nbsp;&nbsp;Links unterstreichen</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnLinksOff' onclick='ToggleUnderlineLinks(false);'><i class='fa fa-underline' aria-hidden='true'></i>&nbsp;&nbsp;Standard Links</li>";
            break;
        case "zh_CN":
            menuHTML += "<ul class='ltr'>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnTextSizeOn' onclick='setTextSize(true);'><i class='fa fa-text-height' aria-hidden='true'></i>&nbsp;&nbsp;大字体</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnTextSizeOff' onclick='setTextSize(false);'><i class='fa fa-font' aria-hidden='true'></i>&nbsp;&nbsp;正常字体</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnHighContrastOn' onclick='ToggleHighContrastMode(true);'><i class='fa fa-adjust' aria-hidden='true'></i>&nbsp;&nbsp;高对比度模式</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnHighContrastOff' onclick='ToggleHighContrastMode(false);'><i class='fa fa-adjust' aria-hidden='true'></i>&nbsp;&nbsp;定期对比度模式</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnYellowLinksOn'onclick='ToggleLinksYellow(true);'><i class='fa fa-pencil' aria-hidden='true'></i>&nbsp;&nbsp;黄色链接</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnYellowLinksOff' onclick='ToggleLinksYellow(false);'><i class='fa fa-pencil' aria-hidden='true'></i>&nbsp;&nbsp;正常颜色的链接</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnGrayscaleOn' onclick='ToggleGrayscaleMode(true);'><i class='fa fa-barcode' aria-hidden='true'></i>&nbsp;&nbsp;灰度色彩模式</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnGrayscaleOff' onclick='ToggleGrayscaleMode(false);'><i class='fa fa-barcode' aria-hidden='true'></i>&nbsp;&nbsp;常色模式</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnLinksOn' onclick='ToggleUnderlineLinks(true);'><i class='fa fa-underline' aria-hidden='true'></i>&nbsp;&nbsp;链接下划线</li>";
            menuHTML += "<li class='accessibilityMenuButton alignLeft' id='btnLinksOff' onclick='ToggleUnderlineLinks(false);'><i class='fa fa-underline' aria-hidden='true'></i>&nbsp;&nbsp;默认链接</li>";

            break;

    }

    menuHTML += "</ul>";



    $("#slideout").html(menuHTML);

    //$("body").prepend("<div id='slideout'>" + menuHTML + "</div>");






}

function toggleAccessibilityMenu() {

    if (accessibilityShown) {
        $("#slideout").css("left", "-250px");

    } else {
        $("#slideout").css("left", "0");


    }

    accessibilityShown = !accessibilityShown;
}


function setTextSize(newSize) {
    if (debugMode) console.log("set size: " + newSize);
    if (newSize === "true" || newSize === true) {

        textSizeBigger = true;

        if ($('link[title=textsize]').length == 0) {
            $("<link/>", {
                rel: "stylesheet",
                type: "text/css",
                href: "bigger.css",
                title: "textsize"
            }).appendTo("head");
            $('link[title=textsize]')[0].disabled = false;
        } else {
            $('link[title=textsize]')[0].disabled = false;
        }



        $("#btnTextSizeOff").removeClass("disabled");
        $("#btnTextSizeOff").attr("aria-disabled", false);
        $("#btnTextSizeOn").addClass("disabled");
        $("#btnTextSizeOn").attr("aria-disabled", true);

    } else {

        if ($('link[title=textsize]').length > 0) {
            $('link[title=textsize]')[0].disabled = true;
        }


        textSizeBigger = false;

        $("#btnTextSizeOff").addClass("disabled");
        $("#btnTextSizeOff").attr("aria-disabled", true);
        $("#btnTextSizeOn").removeClass("disabled");
        $("#btnTextSizeOn").attr("aria-disabled", false);
    }

    var str = textSizeBigger + delimiter + areLinksYellow + delimiter + isGrayscale + delimiter + isHighContrast + delimiter + areLinksUnderlined + delimiter;
    if (!init) createCookie(cookieName, str);

}

function ToggleUnderlineLinks(mode) {
    if (!(mode === "true" || mode === true)) {
        if ($('link[title=underline]').length > 0) {
            $('link[title=underline]')[0].disabled = true;
        }

        areLinksUnderlined = false;
        $("#btnLinksOff").addClass("disabled");
        $("#btnLinksOff").attr("aria-disabled", true);
        $("#btnLinksOn").removeClass("disabled");
        $("#btnLinksOn").attr("aria-disabled", false);

    } else {
        if (debugMode) console.log("0");
        if ($('link[title=underline]').length == 0) {
            if (debugMode) console.log("1");
            $("<link/>", {
                rel: "stylesheet",
                type: "text/css",
                href: "underline-links.css",
                title: "underline"
            }).appendTo("head");
        } else {
            if (debugMode) console.log("2");
            $('link[title=underline]')[0].disabled = false;
        }
        areLinksUnderlined = true;
        $("#btnLinksOff").removeClass("disabled");
        $("#btnLinksOff").attr("aria-disabled", false);
        $("#btnLinksOn").addClass("disabled");
        $("#btnLinksOn").attr("aria-disabled", true);


    }

    var str = textSizeBigger + delimiter + areLinksYellow + delimiter + isGrayscale + delimiter + isHighContrast + delimiter + areLinksUnderlined + delimiter;
    if (!init) createCookie(cookieName, str);
}

function ToggleLinksYellow(mode) {
    if (!(mode === "true" || mode === true)) {
        if ($('link[title=yellow]').length > 0) {
            $('link[title=yellow]')[0].disabled = true;
        }

        areLinksYellow = false;
        $("#btnYellowLinksOff").addClass("disabled");
        $("#btnYellowLinksOff").attr("aria-disabled", true);
        $("#btnYellowLinksOn").removeClass("disabled");
        $("#btnYellowLinksOn").attr("aria-disabled", false);

    } else {
        if ($('link[title=yellow]').length == 0) {
            $("<link/>", {
                rel: "stylesheet",
                type: "text/css",
                href: "yellow-links.css",
                title: "yellow"
            }).appendTo("head");
        } else {
            $('link[title=yellow]')[0].disabled = false;
        }
        areLinksYellow = true;

        $("#btnYellowLinksOff").removeClass("disabled");
        $("#btnYellowLinksOff").attr("aria-disabled", false);
        $("#btnYellowLinksOn").addClass("disabled");
        $("#btnYellowLinksOn").attr("aria-disabled", true);
    }

    var str = textSizeBigger + delimiter + areLinksYellow + delimiter + isGrayscale + delimiter + isHighContrast + delimiter + areLinksUnderlined + delimiter;
    if (!init) createCookie(cookieName, str);
}

function ToggleHighContrastMode(mode) {
    if (!(mode === "true" || mode === true)) {
        if ($('link[title=contrast]').length > 0) {
            $('link[title=contrast]')[0].disabled = true;
        }
        isHighContrast = false;
        $("#btnHighContrastOff").addClass("disabled");
        $("#btnHighContrastOff").attr("aria-disabled", true);
        $("#btnHighContrastOn").removeClass("disabled");
        $("#btnHighContrastOn").attr("aria-disabled", false);
    } else {
        if ($('link[title=contrast]').length == 0) {
            $("<link/>", {
                rel: "stylesheet",
                type: "text/css",
                href: "high-contrast.css",
                title: "contrast"
            }).appendTo("head");
            $('link[title=contrast]')[0].disabled = false;
        } else {
            $('link[title=contrast]')[0].disabled = false;
        }
        isHighContrast = true;
        $("#btnHighContrastOff").removeClass("disabled");
        $("#btnHighContrastOff").attr("aria-disabled", false);
        $("#btnHighContrastOn").addClass("disabled");
        $("#btnHighContrastOn").attr("aria-disabled", true);
    }
    var str = textSizeBigger + delimiter + areLinksYellow + delimiter + isGrayscale + delimiter + isHighContrast + delimiter + areLinksUnderlined + delimiter;
    if (!init) createCookie(cookieName, str);
}

function ToggleGrayscaleMode(mode) {
    if (!(mode === "true" || mode === true)) {
        if ($('link[title=grayscale]').length > 0) {
            $('link[title=grayscale]')[0].disabled = true;
        }
        isGrayscale = false;
        $("#btnGrayscaleOff").addClass("disabled");
        $("#btnGrayscaleOff").attr("aria-disabled", true);
        $("#btnGrayscaleOn").removeClass("disabled");
        $("#btnGrayscaleOn").attr("aria-disabled", false);
    } else {
        if ($('link[title=contrast]').length == 0) {
            $("<link/>", {
                rel: "stylesheet",
                type: "text/css",
                href: "grayscale.css",
                title: "grayscale"
            }).appendTo("head");
            $('link[title=grayscale]')[0].disabled = false;
        } else {
            $('link[title=grayscale]')[0].disabled = false;
        }
        isGrayscale = true;
        $("#btnGrayscaleOff").removeClass("disabled");
        $("#btnGrayscaleOff").attr("aria-disabled", false);
        $("#btnGrayscaleOn").addClass("disabled");
        $("#btnGrayscaleOn").attr("aria-disabled", true);
    }



    var str = textSizeBigger + delimiter + areLinksYellow + delimiter + isGrayscale + delimiter + isHighContrast + delimiter + areLinksUnderlined + delimiter;
    if (!init) createCookie(cookieName, str);
}

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "" + date.toGMTString();
    } else {
        var date = new Date();
        date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000));
        var expires = "" + date.toGMTString();
    }
    document.cookie = name + "=" + value + expires + ";SameSite=Lax; path=/";
    if (debugMode) console.log("create cookie: " + value);

}



function readCookie(name) {
    if (debugMode) console.log("trying to get cookie: " + name);
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) {
            if (debugMode) console.log("cookie: " + name + " found!");
            c = c.substring(nameEQ.length, c.length);
            //alert("in read cookie. got: " + c);
            var parts = c.split(delimiter);
            if (parts.length > 4) {
                areLinksUnderlined = parts[3];
                if (debugMode) console.log("underlined: " + areLinksUnderlined);
            }
            if (parts.length > 3) {
                isHighContrast = parts[3];
                if (debugMode) console.log("contrast: " + isHighContrast);
            }
            if (parts.length > 2) {
                isGrayscale = parts[2];
                if (debugMode) console.log("grayscale: " + isGrayscale);
            }
            if (parts.length > 1) {
                areLinksYellow = parts[1];
                if (debugMode) console.log("yellow: " + areLinksYellow);
            }
            if (parts.length > 0) {
                //alert("read from cookie:" + parts[0]);
                textSizeBigger = parts[0];
                if (debugMode) console.log("size: " + textSizeBigger);
            }

        }
    }
    return null;
}

function setAccessibityFromCookie() {
    readCookie(cookieName);
    setTextSize(textSizeBigger);
    ToggleGrayscaleMode(isGrayscale);
    ToggleHighContrastMode(isHighContrast);
    ToggleLinksYellow(areLinksYellow);
    ToggleUnderlineLinks(areLinksUnderlined);

    init = false;
}

function makeAccessible() {

    // set empty alt attribute to any image that does not contain an alt tag:
    $('img:not([alt])').attr('alt', '');

    // copy link title into aria-label:
    $('a[title]').each(function () {
        $(this).attr('aria-label', $(this).attr('title'));
    });

    if ($("nav").attr('role') == undefined) {
        $("nav").attr('role', "navigation");
    }

}
