jQuery(document).ready( function(){
	jQuery.ajax({
		url:'/services/rest/getOMMOTotals.php',
		type:'GET',
		success:function(data) {
			// Get total from the feed
			var desc 	= jQuery(data).find('description').text();
			var total 	= jQuery(desc).find('span').text();
			
			// Remove any commas
			total = total.replace(',', '');
			
			// Index of first none zero character
			var activeIndex = 7 - total.length;
			
			// Pad string to 7 characters
			while(total.length < 7) {
				total = '0' + total;
			}

			// Update the counter
			var index = 0;
			jQuery('#counter span.disabled').each(function() {
				// Remove disabled class if it's an active digit
				if (index >= activeIndex) {
					jQuery(this).removeClass('disabled');
				}
				
				// Set digit
				jQuery(this).html(total.charAt(index));
				
				index++;
			});
		},
		dataType:'xml'
	});
});
