$(document).ready(function(){
	var speed = 1500;
	var curSelection = 0;
	
	if(images != "undefined"){
		//fade in at the start
		var elmIn = $('#'+images[curSelection]);
		// if the element is currently being animated (to a fadeOut)...
		if (elmIn.is(':animated')) {
			// ...take it's current opacity back up to 1
			elmIn.stop().fadeTo(speed, 1);
		} else {
			// fade in quickly
			elmIn.fadeIn(speed);
		}
		
		window.setInterval(function(){
				//fade the current selection out
				var elmOut = $('#'+images[curSelection]);
				if (elmOut.is(':animated')) {
				  // ...take it's current opacity back up to 1
				  elmOut.stop().fadeTo(speed, 0);
				} else {
				  // fade in quickly
				  elmOut.fadeOut(speed);
				}		
				//fade the next one in
				curSelection++;//next one along
				//reset the selection
				if(curSelection == images.length)
					curSelection = 0;	
				var elmIn = $('#'+images[curSelection]);
				// if the element is currently being animated (to a fadeOut)...
				if (elmIn.is(':animated')) {
				  // ...take it's current opacity back up to 1
				  elmIn.stop().fadeTo(speed, 1);
				} else {
				  // fade in quickly
				  elmIn.fadeIn(speed);
				}															
		},5000); 
	}
});