﻿$(document).ready(function() {
    FontSize_Load();
    FontSize_Click();
});

function FontSize_Load() {
    var size = getUrlVars()["size"];
    var fontSize = '1em';
    if (size == 2) {
        fontSize = '1.1em';
        ReplaceHrefs(2)
    }
    if (size == 3) {
        fontSize = '1.2em';
        ReplaceHrefs(3)
    }
    $('.mainContainer').css({ 'font-size': fontSize })
    
}

function FontSize_Click() {
    $('.fontSize').click(function() {
        var result = "";
        if (window.location.toString().indexOf('?') > -1) {
            if (window.location.toString().indexOf('size=') > -1) {
                result = window.location.toString().replace("size=" + getUrlVars()["size"], "size=" + this.id);
            }
            else {
                result = window.location + '&size=' + this.id;
            }
        } else {
            result = window.location + '?size=' + this.id;
        }

        if (result != "") {
            window.location = result;
        }
    });
}

function ReplaceHrefs(id) {
    var result = $("a").attr("href");
    
    $("a").attr("href", result + "?size=" + id)
}

function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.toLowerCase().slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

function UrlContainsParameters() {
    var hashes = window.location.href.toLowerCase().slice(window.location.href.indexOf('?') + 1).split('&');
    return hashes > 0;
}
