//     JQuery Text resize + Cookie recall
//     Ben Hayes, January 2010 | info@jackfruitdesign.com
//     Based initially on a script from http://www.shopdev.co.uk/blog/text-resizing-with-jquery/
//     This script gives a simplified binary option: normal or large text

$(document).ready(function() {

    // declare a few constants:
    var SMALL = 1.0; //small font size in pixels
    var MEDIUM = 1.3;
    var LARGE = 1.5; //larger size in pixels
    var COOKIE_NAME = "CourageCenter-Fontresizer"; //Maybe give this the name of your site.

    //make it small by default
    var fontsize = SMALL;

    // Only show text resizing links if JS is enabled
    $(".fontresize").show();

    // if cookie exists set font size to saved value, otherwise create cookie
    if ($.cookie(COOKIE_NAME)) {
        fontsize = $.cookie(COOKIE_NAME);
        //set initial font size for this page view:div[class=freeFormHTML]
        $("#mainContent").css("font-size", fontsize + "em");
        //set up appropriate class on font resize link:
        if (fontsize == LARGE) {
            $("#large").addClass("current");
            $("li[class=orangePromote]").css("font-size", "0.67em");
            $("li[class=greenPromote]").css("font-size", "0.67em");
            }
        else {
            if (fontsize == MEDIUM) {
                $("#medium").addClass("current");
                $("li[class=orangePromote]").css("font-size", "0.78em");
                $("li[class=greenPromote]").css("font-size", "0.78em");
                }
                else {
                    $("#small").addClass("current");
                    $("li[class=orangePromote]").css("font-size", "0.91em");
                    $("li[class=greenPromote]").css("font-size", "0.91em");
                    }
        }
    } else {
        $("#small").addClass("current");
        $.cookie(COOKIE_NAME, fontsize);
    }

    // large font-size link:
    $("#large").bind("click", function() {
        if (fontsize != LARGE) {
            fontsize = LARGE;
            $("#mainContent").css("font-size", fontsize + "em");
            $("li[class=orangePromote]").css("font-size", "0.67em");
            $("li[class=greenPromote]").css("font-size", "0.67em");
            $("#large").addClass("current");
            $("#medium").removeClass("current");
            $("#small").removeClass("current");
            $.cookie(COOKIE_NAME, fontsize);
        }
        return false;
    });
    // medium font-size link:
    $("#medium").bind("click", function() {
        if (fontsize != MEDIUM) {
            fontsize = MEDIUM;
            $("#mainContent").css("font-size", fontsize + "em");
            $("li[class=orangePromote]").css("font-size", "0.78em");
            $("li[class=greenPromote]").css("font-size", "0.78em");
            $("#large").removeClass("current");
            $("#medium").addClass("current");
            $("#small").removeClass("current");
            $.cookie(COOKIE_NAME, fontsize);
        }
        return false;
    });
    // small font-size link:
    $("#small").bind("click", function() {
        if (fontsize != SMALL) {
            fontsize = SMALL;
            $("#mainContent").css("font-size", fontsize + "em");
            $("li[class=orangePromote]").css("font-size", "0.91em");
            $("li[class=greenPromote]").css("font-size", "0.91em");
            $("#large").removeClass("current");
            $("#medium").removeClass("current");
            $("#small").addClass("current");
            $.cookie(COOKIE_NAME, fontsize);
        }
        return false;
    });
});

