////// Define all the functions used to enhance the home page.



////// Define the components of the image carousel.
////// Each component array should be the same size as every other array.
var theCarouselTitles    = new Array('Your Future Starts Here', 'Your Future Starts Here', 'Your Future Starts Here', 'Your Future Starts Here', 'Your Future Starts Here', 'Your Future Starts Here', 'Your Future Starts Here', 'Your Future Starts Here');
var theCarouselLinks     = new Array('', '', '', '', '', '', '', '');
var theCarouselImages    = new Array('carousel_eight.jpg', 'carousel_one.jpg', 'carousel_two.jpg', 'carousel_three.jpg', 'carousel_four.jpg', 'carousel_five.jpg', 'carousel_six.jpg', 'carousel_seven.jpg');
//var theCarouselLinkPath  = "about/stories/";
var theCarouselLinkPath  = "/";
var theCarouselImagePath = "_common/img/";
var theCarouselCount     = 0;
var theCarouselWait      = 5500; // Delay between turns, in milliseconds



////// Run the image carousel.
function runCarousel()
    {

    if (document.getElementById)
        {
        var theCarouselLink  = document.getElementById('carousel_link');
        var theCarouselImage = document.getElementById('carousel_image');

        if (
               (theCarouselLink  != null)
            && (theCarouselImage != null)
            && (theCarouselLink.setAttribute)
            && (theCarouselImage.setAttribute)
            && (theCarouselTitles.length > 0)
            && (theCarouselLinks.length  > 0)
            && (theCarouselImages.length > 0)
            && (theCarouselImages.length == theCarouselLinks.length)
            && (theCarouselImages.length == theCarouselTitles.length)
           )
            {
            var theCarouselTotal = theCarouselImages.length;

            // Wait until the last component from the current set of components,
            // the image itself, has completely loaded onto the page
            // before turning the carousel to the next set of components.
            if (theCarouselImage.complete)
                {
                theCarouselCount++;
                if (theCarouselCount == theCarouselTotal) { theCarouselCount = 0; }

                theCarouselLink.setAttribute('alt',    theCarouselTitles[theCarouselCount]);
                theCarouselLink.setAttribute('title',  theCarouselTitles[theCarouselCount]);
                theCarouselLink.setAttribute('href',   theCarouselLinkPath + theCarouselLinks[theCarouselCount]);

                theCarouselImage.setAttribute('alt',   theCarouselTitles[theCarouselCount]);
                theCarouselImage.setAttribute('title', theCarouselTitles[theCarouselCount]);
                theCarouselImage.setAttribute('src',   theCarouselImagePath + theCarouselImages[theCarouselCount]);
                }
            }

        }

    setTimeout("runCarousel()", theCarouselWait);
    }



////// Call all the functions common to the home page.
addToPage(runCarousel);
