﻿
var conf = {
    ieInitialSize: '15px', //IE doesn't treat the font as the actual size, so starting off at 15px makes it behave like a normal browser
    maxSize: '100px',
    increase: {
        button: '.fontPlus',
        multiplier: 1.1
    },
    decrease: {
        button: '.fontMinus',
        multiplier: 0.9
    }
}

// Inspired by: http://www.shopdev.co.uk/blog/text-resizing-with-jquery/
jQuery(function($){
    // save in case we want to reset font size
    var originalFontSize = getCurrentFontSize();

    // Increase Font Size
    $(conf.increase.button).click(function(){
        changeFontSizeBy(conf.increase.multiplier);
    });

    // Decrease Font Size
    $(conf.decrease.button).click(function(){
        changeFontSizeBy(conf.decrease.multiplier);
    });
});

function changeFontSizeBy(multiplier) {
    var currentFontSize = getCurrentFontSize();
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*multiplier;
    jQuery('html').css('font-size', newFontSize + 'px');
    
    return false;
}

function getCurrentFontSize() {
    var size = jQuery('html').css('font-size');
    return (parseFloat(size) > parseFloat(conf.maxSize))
        ? conf.ieInitialSize    // if a huge number is returned (thanks IE!!), return the default from conf
        : size;
}
