/**
 * This slide show script is written and developed by Digital Simplistics, Inc.
 * Author: Alan Arthur (aarthur [at] speedscript [dot] com)
 * Version: 0.1
 */
var aImageList = [];
var i = 0;

function imageAppendtoDiv( aImgList ){
	// console.log(aImgList);
	$.each(aImgList,function(key, value){
		$("#slideshow").append('\n\t\t\t<img src="'+ value +'" alt="Image' + key + '" />\n');
	});
}

function preloadImages( imageArray ){
	for(var x = 0; x < imageArray.length; x++){
		img = new Image();
		img.src = imageArray[x];
	}
}

$(document).ready(function(){
	// If there is no slideshow div then we don't need to run the code.
	if($('#slideshow').length > 0) {
		// Get data, parse it into an array, append images to container, and start slideshow.
		$.ajax({
			url: 'xmlPictureResponse.xml',
			type: 'GET',
			dataType: 'xml',
			success: function(returnedXMLResponse){
				$('image', returnedXMLResponse).each(function(){
					var tmpImageSrc = $(this).attr("src");
					aImageList.push(tmpImageSrc);
				});
				preloadImages(aImageList);
				imageAppendtoDiv(aImageList);
				$('#slideshow').cycle('fade');
			}  // End Success
		}); // End AJAX
	} // End If
}); // End Document Ready
