$(document).ready(function() {
    
    // font zooming
    var elements = "#middle, .disabilitypunchline, h2.aip-detail-heading";
        elements += ", h1.lookingfor, h1.disabilityservices";
        elements += ", h1.lighttitle, .disabilitypunchline1";
        elements += ", .subtitletext, .subtitletextpeach";
        elements += ", h1.darkertitle, .biglink";
        elements += ", #middle input[type='text'], #middle textarea";
    var options = {
        increment: 2,
        cookieParams: {expires: 360, path: '/'}
    }
    
    $("#view-controls a.size-increase").click(function (e) {
        // curr_inc is a multiplier of options.increment
        var curr_inc = $.cookie('font-inc') ? parseInt($.cookie('font-inc'), 10) : 0;
        var new_inc = curr_inc += 1;
        $.cookie('font-inc', new_inc, options.cookieParams);
        $(elements).each(function () {
            var curr_size = parseInt($(this).css('font-size'), 10);
            var new_size = curr_size + options.increment;
            $(this).css('font-size', new_size + 'px');
        });
        e.preventDefault();
    });
            
    $("#view-controls a.size-decrease").click(function (e) {
        // curr_inc is a multiplier of options.increment
        var curr_inc = $.cookie('font-inc') ? parseInt($.cookie('font-inc'), 10) : 0;
        var new_inc = curr_inc -= 1;
        $.cookie('font-inc', new_inc, options.cookieParams);
        $(elements).each(function () {
            var curr_size = parseInt($(this).css('font-size'), 10);
            var new_size = curr_size - options.increment;
            $(this).css('font-size', new_size + 'px');
        });
        e.preventDefault();
    });
    
    // font zoom on load
    var curr_inc = $.cookie('font-inc') ? parseInt($.cookie('font-inc'), 10) : 0;
    var change = curr_inc * options.increment;
    $(elements).each(function () {
        var curr_size = parseInt($(this).css('font-size'), 10);
        //var curr_size = parseInt( $(this).get(0).style.fontSize.replace("px", ""), 10 );console.log(curr_size);
        var new_size = curr_size + change;
        $(this).css('font-size', new_size + 'px');
    });
    
    // stylesheet change
    var wob_sheet = $("head > link[title='white-on-black']");
    
    $("#view-controls a.style-switch").click(function (e) {
        if (wob_sheet.attr('disabled')) {
            wob_sheet.attr('disabled', false);
            $.cookie('wob', 'active', {expires: 360, path: '/'});
        } else {
            wob_sheet.attr('disabled', true);
            $.cookie('wob', null, {expires: 360, path: '/'});
        }
        e.preventDefault();
    });
    
    // stylesheet change on page load
    wob_sheet.attr('disabled', true); // needed for ie.
    
    if ($.cookie('wob')) {
        wob_sheet.attr('disabled', false);
    }
    
    // prevent clicking submit button twice
    $('form').submit(function(){
        $(this).find('input[type=submit]').attr('disabled', 'disabled');
    });
    
});

