$(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(
			$('#rightcol'),
			$('#rightcol h1'),
			$('#rightcol h2'),
			$('#rightcol h3'),
			$('#leftnav a'),
			$('#breadcrumb'),
            $('#breadcrumb a'),
            $('#topnav'),
            $('#topnav a'),
            $('#print'),
            $('#email'),
            $('#btn'),
            $('#btn .btn'),
			$('#rightcol li'),
			$('#rightcol a'),
			$('#rightcol .txt'),
			$('#rightcol .ddl'),
			$('#rightcol label'),
			$('#rightcol .valsum'),
			$('#isi'),
			$('#isi h1'),
			$('#footer #nav'),
			$('#footer #copy'),
            $('#topNav'),
            $('#calloutcol'),
            $('#background')

		);
    var size = 0;
    var userPreferences = 'zemairaTextSize'; //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 */

});
