/**
 * This slide show script is written and developed by Digital Simplistics, Inc.
 * Author: Alan Arthur (aarthur [at] speedscript [dot] com)
 * Version: 1.0
 */
var aImageList = [];
var i = 0;
var xmlDirectory = "xml/";

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) {
	// Gather the file to load from the slideshow div tag
	var fileName = $("#slideshow").attr("title");
	// Get data, parse it into an array, append images to container, and start slideshow.
		$.ajax({
			url: xmlDirectory+fileName+".xml",
			type: 'GET',
			dataType: 'xml',
			success: function(returnedXMLResponse){
				$('image', returnedXMLResponse).each(function(){
					var tmpImageSrc = $(this).attr("src");
					aImageList.push(tmpImageSrc);
				});
				preloadImages(aImageList);
                // Remove original static image
                var originalImage = $("#slideshow").children("img");
                originalImage.remove();
                // Append list of images
				imageAppendtoDiv(aImageList);
				$('#slideshow').cycle('fade');
			}  // End Success
		}); // End AJAX
	} // End If
}); // End Document Ready

