﻿var timerID;

function nextItem()
{
    var img = $("#image-swapper").find('.selected');
    if (img.next().length > 0) 
    {
        img.next().find('a').click();
    }
    else
    {
        $("#image-swapper").find('.swapper-item:first').find('a').click();
    }
}

$(document).ready(function() {
    //hero image swapper
    $("#image-swapper a").click(function(e) { 
        e.preventDefault();
        var self = $(this);
        $("#image-swapper-bg").fadeOut('300', function() {
            $("#image-swapper-bg").attr("src", self.attr("title"));
        });
        $("#image-swapper-bg").fadeIn('300', function() {
           self.parent().parent().children().each(function() {
                $(this).removeClass("selected");
            });   
            self.parent().addClass("selected");
            clearTimeout ( timerID );
            timerID = setTimeout('nextItem()', 5000);
        });

        
        
    })
    
    
    
    timerID = setTimeout('nextItem()', 5000);
    
})
