﻿$(document).ready(function(){
    
        // Use jQuery to get the XML file
    $.get('/water_tips.xml', {
        preventCache: new Date().getTime()
    }, function(data, textStatus) {
        
        // Select the <tip> elements
            var tip_collection = [];
            var count = -1;
            $('tip', $(data)).each(function() {
                count = count + 1;
                var text = $(this).text();
                tip_collection[count] = text;
            });
        
        // Generate a random collection index
        var idx = Math.floor(Math.random() * tip_collection.length);
        
        // Populate "randomDisplay" with the random element's contents
        $('#randomFact').html(tip_collection[idx]);
    }, 'xml');
});
