$(document).ready(function() {

    // Open the testimonials.xml file
    $.get("testimonials.xml", {}, function(xml) {

        // Build an HTML string
        myQuote = '';

        // Run the function for each quote tag in the XML file
        $('testimonial', xml).each(function(i) {
            testimonial = $(this).find("quote").text();
            citation = $(this).find("quote").attr("cite");

            // Build HTML data and store in string
            mydata = buildTestimonial(testimonial, citation);
            myQuote = myQuote + mydata;
        });

        var $quotes = $(myQuote).find('q');

        var n = $quotes.length;
        var random = Math.floor(Math.random() * n);
        myQuote = $quotes.eq(random);

        // Remove any content and then update with the HTML string
        $("#testimonials blockquote").empty().append(myQuote);
        // Append the closing quote mark image to ensure it's cross-browser placement
        $("#testimonials blockquote p").append('<img src="/_assets/img/global/KCL_highlights-testimonial_closequote.gif" alt="closequote" />');
    });

});



function buildTestimonial( testimonial, clientName) {

    // Check to see if there is a "quote" attribute in the name field
    if ((testimonial) != undefined) {
        clientQuote = testimonial;
    }
    else {
        clientQuote = "";
    }

    // Build HTML string and return
    output = '<div><q>';
    output += '<p>' + clientQuote + '&nbsp;</p>';
    output += '<cite>' + clientName + '</cite>';
    output += '</q></div>';

    return output;
}

