﻿$(document).ready(function()
{
    $('body').addClass('js');
    
    // Hide "noscript" text immediately to avoid flickering while AJAX loads
    $('#waterStorage .no-js').hide();
    
    $.ajax({
        type:     'POST', 
        url:      '/getWaterLevels.aspx', 
        dataType: 'xml', 
        success: function(xml) {
            // Update water level percentage.
            var percentFull = $('MWC_storage totalstorage percentfull', xml);
            if ($('error', xml).length == 0 && percentFull.length == 1) {
                $('#waterStorage .waterRemaining').text(percentFull.text() + '%');
                $('#waterStorage .js-only').fadeIn('fast');
            } else {
                $('#waterStorage .no-js').fadeIn('fast');
            }
            
            // Show water level percentage area.
            //$('#waterStorage .waterRemaining').css({display: 'block', opacity: 0.0});
            //$('#waterStorage .waterRemaining').animate({opacity: 1.0}, 300);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            $('#waterStorage .no-js').fadeIn('fast');
        }
    });
    
});