var xhr = false;
var dataArray = new Array();
var url = "gallery.xml";
var currImg = 0;

//var mySlideList1 = ['images/home/1.jpg','images/home/2.jpg','images/home/3.jpg','images/home/4.jpg','images/home/5.jpg','images/home/6.jpg'];
var mySlideList1 = new Array();
var myCaptionList1 = new Array();
//var mySlideShow1;


if (window.XMLHttpRequest) {
	xhr = new XMLHttpRequest();
}
else {
	if (window.ActiveXObject) {
		try {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e) { }
	}
}

if (xhr) {

	xhr.open("GET", url, true);
	xhr.onreadystatechange = setDataArray;

	xhr.send(null);
	
}
else {
	alert("Sorry, but I couldn't create an XMLHttpRequest");
}

    
function setDataArray() {
	if (xhr.readyState == 4) {
		if (xhr.status == 200) {
			if (xhr.responseXML) {
				var allData = xhr.responseXML.getElementsByTagName("gallery");

				for (var i=0; i<allData.length; i++) {
					var tempObj = new Object;
					tempObj.picture = getVal(allData[i],"picture");
					tempObj.caption = getVal(allData[i],"caption");
					dataArray[i] = tempObj;
					
					mySlideList1[i] = tempObj.picture;
					myCaptionList1[i] = tempObj.caption;
				}
			}
		}
		else {
			alert("There was a problem with the request " + xhr.status);
		}
	}
	
		function getVal(theData,theTag) {
		return theData.getElementsByTagName(theTag)[0].firstChild.nodeValue;
	}

	

}



	
	



// * Dependencies * 

// this function requires the following snippets:

// JavaScript/images/switchImage

//

// BODY Example:

// <body onLoad="mySlideShow1.play(); mySlideShow2.play();">

// <img src="originalImage1.gif" name="slide1">

// <img src="originalImage2.gif" name="slide2">

//

// SCRIPT Example:




var mySlideShow1 = new SlideShow(mySlideList1, 'slide1', 6000, "mySlideShow1");

// var mySlideList2 = ['image4.gif', 'image5.gif', 'image6.gif'];

// var mySlideShow2 = new SlideShow(mySlideList2, 'slide2', 1000, "mySlideShow2");

function SlideShow(slideList, image, speed, name)          

{

  this.slideList = slideList;

  this.image = image;

  this.speed = speed;

  this.name = name;

  this.current = 0;

  this.timer = 0;

}

SlideShow.prototype.play = SlideShow_play;  	

function SlideShow_play()       

{

  with(this)

  {

    if(current++ == slideList.length-1) current = 0;

    switchImage(image, slideList[current]);

    clearTimeout(timer);

    timer = setTimeout(name+'.play()', speed);

  }
  

}



function switchImage(imgName, imgSrc) 

{

  if (document.images)

  {

    if (imgSrc != "none")

    {

      document.images[imgName].src = imgSrc;
	  

    }

  }

}





