// File: readXML.js

// Start function when DOM has completely loaded
$(document).ready(function() {

    // Open the quotes.xml file
    $.get("/psp/javascript/quotes.xml", {}, function(xml) {

        loopCount = 0;
        // TODO: Make collection
        var col = new CCollection();

        // Run the function for each quote tag in the XML file
        $('quote', xml).each(function(i) {
            var quote = $(this).find("text").text();
            var quoted = $(this).find("author").text();
            var quoteItem = new QuoteObject(quote, quoted);

            // Add object to collection
            col.add(quoteItem);
            loopCount = i;
        });

        loopCount = loopCount + 1;

        // Get random number within the size of the array
        var randomnumber = Math.floor(Math.random() * loopCount)

        $("#quoted").text(col[randomnumber].Quoted);
        $("#quote").text(col[randomnumber].Quote);
    });
});

function QuoteObject(quote, quoted) 
{
    this.Quote = quote;
    this.Quoted = quoted;
}
