﻿//Created by: Damaris Zarco 3/3/2010
//Last updated by: Damaris Zarco 7/14/2010
//Last updated by: Cameron Dumas 7/15/2010

// vars
var total = 0;
var current = 0;
var percentage = 0;
var meterWidth = 400;

$(document).ready(function() {
    ajax();
    setTimeout(function() {
        $('.modalWindow').removeClass("dummy");
    }, 200);
});

function ajax() {
    $.ajax({
        url: '/scripts/pledge.xml',
        type: 'GET',
        dataType: 'xml',
        timeout: 1000,
        success: function(xml) {
            $(xml).find('pledge').each(function() {
                //create the array of images
                total = $(this).find('amount').text();
                current = $(this).find('current').text();
            }); //xml

            percentage = current / total;
            color();
        }, //success
        error: function() {
            alert("error loading");
        } //error function
    });      //ajax
} //doAjax

function color() {
    $('.meterFill').css('width', meterWidth * percentage + 'px');
    $('.meterOverlay').css('width', meterWidth + 'px');
    $('.meter').css('width', parseInt(meterWidth) + 2 + 'px');
    $('.meter').css('left', '-22px');
    //$("#meter").css({ 'width': meterWidth + 2 + 'px' , 'left':'-22px'});
    //$("#meterFill").css({ 'width': meterWidth * percentage + 'px' });
    //$("#meterOverlay").css({ 'width': meterWidth + 'px' });
    $(".meterNumbersEnd").html("$" + total);

}
