﻿//GLOBAL VARIABLE USED TO DETERMINE WHICH IMAGE TO FADEIN / FADEOUT
var iterator = 1;

function switchImages(image1, image2) {
    //TIMEOUT IS USED TO INITIATE THE SWITCH BECAUSE IT WILL ONLY OCCUR 
    //ONCE AFTER THE SPECIFIED AMOUNT OF TIME
    setTimeout(function() { beginSwitch(image1, image2) }, 3000);
}

function beginSwitch(image1, image2) {
    //DETERMIN WHICH IMAGES TO FADEIN / FADEOUT
    if (iterator % 2 == 0) {
        $("." + image1).fadeOut(700, function() {
            $("." + image2).fadeIn(700);
        });
    }
    else {
        $("." + image2).fadeOut(700, function() {
            $("." + image1).fadeIn(700);
        });
    }

    if (iterator == 1) {
        setInterval(function() { beginSwitch(image1, image2) }, 5000);
    }

    iterator += 1;

}