﻿$(document).ready(function() {
    $('a.switcher').click(function(ev) {
        var title = $(this).attr('class').replace('switcher', '').replace(' ', '');
        $.switchStylesheet(title);
        $.cookie('fontsize', title, { path: '/' });
        ev.stopPropagation();
        return false;
    });
});
$.switchStylesheet = function(title, onlyThisOne, switchOn) {
    $('link[rel*=\'style\'][title]').each(function(index) {
        var disableLink = false;
        if (onlyThisOne) {
            if ($(this).attr('title') != title) { return; }
            disableLink = !switchOn;
        } else {
            if ($(this).attr('title') == title) {
                disableLink = false;
            } else {
                disableLink = true;
            }
        }
        
        if (disableLink) {
            if (!this.disabled) { this.disabled = true; }
        } else {
            var re = new RegExp('alt.+?($|\\s)', 'gi');
            if (this.disabled) { this.disabled = false; }
            else if ($(this).attr('rel').match(re)) {
                $(this).attr('rel', $.trim($(this).attr('rel').replace(re, '')));
                this.disabled = false;
            }
        }
    });
};