﻿/*!
 * Filename:		Header.js
 * Project:		    www.BuckeyeCorrugated.com/js
 * Description:	    Box header animation script
 * Dependencies:    jquery-1.4.4.min.js
 */

// Instantiate the interval object for the header box animation
var objHeaderInterval = null;

function AnimateHeaderImages()
{
    // Get the active image
    var $activeImg = $(".HeaderImages .ActiveHeaderImage");

    // Determine the next image based on where we currently are in the sequence of images
    // We either go next or back to the beginning
    var $nextImg = ($activeImg.next().length) ? $activeImg.next() : $(".HeaderImages img:first");

    // Set the visibility property for the first time through
    $nextImg.css("visibility", "visible");

    // Make the current image the previously active slide
    // This preserves the image transition effect when we go back to the beginning
    $activeImg.addClass("PreviousHeaderImage");

    // Fade in/animate the next image
    $nextImg.css({ opacity: 0.0 }).addClass("ActiveHeaderImage").animate({ opacity: 1.0 }, 1000, function ()
    {
        // Clear the class info of the now previously visible slide
        $activeImg.removeClass("ActiveHeaderImage PreviousHeaderImage");
    });
}

$(".HeaderImages").ready(function ()
{
    // Set the interval for the header box animation
    objHeaderInterval = setInterval("AnimateHeaderImages()", 4000);
});

