﻿// Author:  James Kind (kindwebsolutions.com)
// Date:    Tue 5th Apr 2011
    
$(document).ready(function () {
    var quotationData = 
    {
        "quotations" :
        [
            {
                "Text" : "Excellent, held my attention all day! Lots of practical advice",
                "Source" : "Nurse",
            },
            {
                "Text" : "People in our department need to be more aware of the issues covered today this was very useful",
                "Source" : "Consultant",
            },
            {
                "Text" : "People aren't aware until told, extremely useful, should be rolled out to all staff on induction",
                "Source" : "Job Centre Plus Staff",
            },
            {
                "Text" : "Having people with learning difficulties to present the training demonstrates clearly what is possible and what can be achieved",
                "Source" : "Dentist",
            },
            {
                "Text" : "Raised awareness greatly, created new ideas for work place, thank you so much",
                "Source" : "Police",
            },
            {
                "Text" : "Really enjoyed the interactive sessions. Very informative using personal real life experiences people can relate to",
                "Source" : "Debt Support",
            },
        ]
    };

    var quoteBoxes = $('.QuoteBox');
    var quoteIndex = 0;

    $(document).everyTime(10000, function()
    {
        $.each(quoteBoxes, function(i, quoteBox)
        {
            if (quoteIndex > (quotationData.quotations.length - 1))
            {
                quoteIndex = 0;
            }

            var quotationItem = quotationData.quotations[quoteIndex];

            quoteIndex++;

            // Get refs to quote box element.
            var containingDiv = $('div', quoteBox);

            // Fade out containing div, replace text and fade back in... lovely!
            containingDiv
                .fadeOut(400, function()
                {
                    $('span', containingDiv).text(quotationItem.Source);
                    $('blockquote', containingDiv).html("&quot;" + quotationItem.Text + "&quot;");
                })
                .fadeIn(400);
        });
    });
});
