$(document).bind('ready', function() {
    /* Text Resize: Allows text within the content area and ISI to be resized, setting set in a cookie */
    /* REQUIRES JQUERY.COOKIE.JS */
    var resizable = new Array(
			$('#content p'),
			$('#content h3'),
			$('#content h6'),
			$('#content li'),			
			$('#form .txt'),
			$('#content .ddl'),
			$('#content label'),
			$('#content .valsum'),
			$('#header #topnav'),
			$('#footer #nav'),
			$('#footer #copy'),
			$('#formTop h4'),
			$('#signUpThanks #col1 p'),
			$('#signUpThanks #col1 a'),
			$('#signUpThanks #col2 p'),
			$('#signUpThanks #col2 a'),
			$('#home #main p'),
			$('#home #info a'),
			$('#home #main a'),
			$('.callout div'),
			$('.callout p'),
			$('#homepageContent p'),
			$('#homepageContent h1'),
			$('#homePageCalloutPanel h2'),
			$('#homePageCalloutPanel p'),
			$('.contentBox div'),
			$('#diagnosingHaeTable,td'),
			$('#glossary .glossaryText'),
			$('#questions *'),
			$('#diagnosingHaeTable td'),
			$('#tableHeader td')
			
		);
    var size = 0;
    var userPreferences = 'userPreferences'; //Name of the cookie

    //Stores the initial font-size value
    $(resizable).each(function(i) {
        resizable[i]['initial'] = parseInt($(this).css('font-size'));
    });

    //Checks for cookie, if found, sets the appropriate size
    if ($.cookie(userPreferences)) {
        size = parseInt($.cookie(userPreferences));
        setPreferences(size, false);
    }

    $('#normal').click(function() {
        size = 0;
        setPreferences(size, true);
    });
    $('#large').click(function() {
        size = 2;
        setPreferences(size, true);
    });
    $('#xlarge').click(function() {
        size = 4;
        setPreferences(size, true);
    });
    $('#cycle').click(function() {
        if (size == 0) {
            size = 2;
        }
        else if (size == 2) {
            size = 4;
        }
        else {
            size = 0;
        }
        setPreferences(size, true);
    });

    //This function actually sets the user settings on the page
    function setPreferences(size, cache) {
        size = size;
        var cache = cache; //Bool, whether or not we need to set a cookie

        $(resizable).each(function(i) {
            if (($(this).attr('id') != 'userRating') && !($(this).hasClass('nore'))) { //Clearly this has a few exceptions
                $(this).css('font-size', size + resizable[i]['initial']);
            }
        });
        if (size == 2) {
            $('#normal').removeClass('selected');
            $('#large').addClass('selected');
            $('#xlarge').removeClass('selected');
        }
        else if (size == 4) {
            $('#normal').removeClass('selected');
            $('#large').removeClass('selected');
            $('#xlarge').addClass('selected');
        }
        else {
            $('#normal').addClass('selected');
            $('#large').removeClass('selected');
            $('#xlarge').removeClass('selected');
        }

        if (cache) {
            $.cookie(userPreferences, size, { path: '/', expires: 365 });
        }
    }
    /* End Text Resize */

});
