﻿var fontSize = ''; // zmienna globalna - moze przyjac jedna z 3-ech wartosci: small, normal, big
var fontSizeCookieName = 'orlentpl_font_size'; //nazwa cookie dla rozmiaru czcionki

function changeFontSize(newSize) {

    if (fontSize != newSize) {
        fontSize = newSize;

        jQuery.cookie(fontSizeCookieName, fontSize, { expires: 7, path: '/' });

        jQuery("#fontSmall, #fontNormal, #fontBig").css('font-weight', 'normal');
        jQuery("body").removeClass('fontNormal').removeClass('fontBig');

        switch (fontSize) {
            case 'small':
                jQuery("#fontSmall").css('font-weight', 'bold');
                break;
            case 'normal':
                jQuery("#fontNormal").css('font-weight', 'bold');
                jQuery("body").addClass('fontNormal');
                break;
            case 'big':
                jQuery("#fontBig").css('font-weight', 'bold');
                jQuery("body").addClass('fontBig');
                break;
        }
    }
}


function checkFontSize() {
    var fontSizeCookie;
    fontSizeCookie = jQuery.cookie(fontSizeCookieName);
    if (fontSizeCookie != null) {
        if (fontSizeCookie != 'small') {
            changeFontSize(fontSizeCookie);
        }
        else {
            jQuery("#fontSmall").css('font-weight', 'bold');
        }
        fontSize = fontSizeCookie;
    }
    else {
        fontSize = 'small';
        jQuery("#fontSmall").css('font-weight', 'bold');
        jQuery.cookie(fontSizeCookieName, fontSize, { expires: 7, path: '/' });
    }
}

function getUrlParamByName(name) {
    var i, group;
    var url = new String(window.location);
    var paramsStringWithQ = String(document.location.search);
    var urlSplit = url.split("?");

    if (urlSplit.length < 2) return "";
    paramsString = urlSplit[1];

    if (paramsStringWithQ.match(/%20\w+=/)) // jest #
    {
        groups = paramsString.split(escape("&"));
    }
    else // nie ma #
    {
        groups = paramsString.split("&");
    }
    i = 0;
    while (i < groups.length) {
        groupString = groups[i];
        group = groupString.split("=");
        if (group[0] == name) {
            return group[1];
        }
        i++;
    }
    return "";
}


jQuery(document).ready(function () {
    if (jQuery('#siteActions .authoringContainer').children().length < 1) {
        jQuery('#siteActions .authoringContainer').hide();
    }

    jQuery('#fontSmall').click(function () {
        changeFontSize('small');
    });
    jQuery('#fontNormal').click(function () {
        changeFontSize('normal');
    });
    jQuery('#fontBig').click(function () {
        changeFontSize('big');
    });
    checkFontSize();
});

