// ################### image_fader.js #################
// #
// #  Coded By Adam Plante @ Dinkum Interactive (dinkuminteractive.com)
// #
// #  Copyright 2008 Dinkum Interactive
// #  This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.
// #  http://creativecommons.org/licenses/by-sa/3.0/us/

function ImageFader(containerID, imageID, fadeColor, theImages) {
 //get length of array
   arrayLength = theImages.length;
   var currentPosition = 0; //offset by 1 because first image already present
 //loop through images
   function FadeIt() {
		 $(imageID).animate({opacity: "0.0"}, 6000) //show background image for a while
		 .animate({opacity: "1.0"}, 800, function () { //fade in black image
			 currentPosition++; //get next position in the array
			 if (currentPosition >= arrayLength) { currentPosition = 0; }
			 $(containerID).css('background-image', 'url("'+theImages[currentPosition]+'")'); //set next image
			 $(imageID).animate({opacity: "0.0"}, 800, FadeIt); //fade out black image
		 });
   }
   FadeIt();//call for the first time;
}