﻿$(function () {

    var regexTextsize = /textsize=(normal|largest|large)/;
    var textsize = (match = regexTextsize.exec(document.cookie)) ? match[1] : 'normal';

    $('.text-size .size').click(function () {

        var $this = $(this);
        var $styleSheet = $('<link id="textsize-style" rel="stylesheet" type="text/css" />');
        var size = 'normal';

        $('#textsize-style').remove();
        $('.size.current').removeClass('current');
        $this.addClass('current');

        if ($this.hasClass('large')) {
            $styleSheet.attr('href', '/Content/text-large.css');
            $('head').append($styleSheet);
            size = 'large';
        }
        else if ($this.hasClass('largest')) {
            $styleSheet.attr('href', '/Content/text-largest.css');
            $('head').append($styleSheet);
            size = 'largest';
        }

        document.cookie = 'textsize=' + size + '; expires=Thu, 2 Aug 2050 20:47:11 UTC; path=/';

    });

    $('.text-size .' + textsize).click();

});
