﻿// default vars.  YOU CAN CHANGE THESE
var switchImageTime = 5000; // time between image switches in miliseconds
var fadeTime = 1500; // time it takes for one image to fade to another in miliseconds
var imagesDiv = 'golf_banner'; // #id of element surrounding images

// DO NOT CHANGE BELOW THIS LINE, ALTHOUGH YOU MAY PUT IN EXTERNAL JS FILE IF NEEDED

$(document).ready(function() {
    setInterval(switchImage, switchImageTime);
});

function switchImage() {
    var active = $('#' + imagesDiv + ' img.active');

    if (active.length == 0) active = $('#' + imagesDiv + ' img:last');

    var activeId = active.attr('id');
    var nextId = (activeId < 5) ? (parseInt(activeId) + 1) : 1;
    var next = $('#' + nextId);

    active.addClass('last-active');

    next.css({ opacity: 0.0 })
			.addClass('active')
			.animate({ opacity: 1.0 }, fadeTime, function() {
			    active.removeClass('active last-active');
			});
}
