 <!--//--><![CDATA[//><!--
function loadXML(url) {
   // This function accepts a file name and returns an XML document.
   // Note we're doing no error checking.

   var AJAX = null;                                 // Initialize the AJAX variable.
   if (window.ActiveXObject){
      // Since IE has so much trouble with responseXML
      // we'll load the XML with the XMLDOM activeX object
      var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
      // Handle ready state changes ( ignore them until readyState = 4 )
      xmlDoc.onreadystatechange= function() { if (xmlDoc.readyState!=4) return false; }
      // This is a synchronous call!   The script will stall until the document
      // has been loaded.
      xmlDoc.async="false";
      xmlDoc.load(url);
      return xmlDoc;
   }
  
   // Initialize the AJAX object.
   if (window.XMLHttpRequest) {  AJAX=new XMLHttpRequest(); }  

   // Handle ready state changes ( ignore them until readyState = 4 )
   AJAX.onreadystatechange= function() { if (AJAX.readyState!=4) return false; }
   // we're passing false so this is a syncronous request.
   // The script will stall until the document has been loaded.
   AJAX.open("GET", url, false);
   AJAX.send(null);

   return AJAX.responseXML;
}

function crawlXML(doc) {                             // Crawls an XML document
	if(doc.hasChildNodes()) {
		for(var i=0; i<doc.childNodes.length; i++) {
		 crawlXML(doc.childNodes[i]);
		}
	} else {
		if( doc.nodeValue.length > 1 ){
			//alert(doc.nodeValue);
			gblImg.push(
				"/asset/images/slideshow/"+doc.nodeValue
			);
		}
	}
}

var gblImg = new Array();					// Initialize a global variable
xmlDoc = loadXML('directoryxml.php');		// Load the document
crawlXML(xmlDoc.documentElement);			// Crawl the document -- passing it the top element

var gblPhotoShufflerDivId = "photodiv";
var gblPhotoShufflerImgId = "photoimg"; 
var gblPauseSeconds = 2.00;
var gblFadeSeconds = .85;
var gblRotations = 999;

// End Customization section

var gblDeckSize = gblImg.length;
var gblOpacity = 100;
var gblOnDeck = 0;
var gblStartImg;
var gblImageRotations = gblDeckSize * (gblRotations+1);

window.onload = photoShufflerLaunch;

function photoShufflerLaunch()
{
var theimg = document.getElementById(gblPhotoShufflerImgId);
	gblStartImg = theimg.src; // save away to show as final image

document.getElementById(gblPhotoShufflerDivId).style.backgroundImage='url(' + gblImg[gblOnDeck] + ')';
setTimeout("photoShufflerFade()",gblPauseSeconds*1000);
}

function photoShufflerFade()
{
var theimg = document.getElementById(gblPhotoShufflerImgId);

// determine delta based on number of fade seconds
// the slower the fade the more increments needed
	var fadeDelta = 100 / (30 * gblFadeSeconds);

// fade top out to reveal bottom image
if (gblOpacity < 2*fadeDelta ) 
{
  gblOpacity = 100;
  // stop the rotation if we're done
  if (gblImageRotations < 1) return;
  photoShufflerShuffle();
  // pause before next fade
	  setTimeout("photoShufflerFade()",gblPauseSeconds*1000);
}
else
{
  gblOpacity -= fadeDelta;
  setOpacity(theimg,gblOpacity);
  setTimeout("photoShufflerFade()",30);  // 1/30th of a second
}
}

function photoShufflerShuffle()
{
var thediv = document.getElementById(gblPhotoShufflerDivId);
var theimg = document.getElementById(gblPhotoShufflerImgId);

// copy div background-image to img.src
theimg.src = gblImg[gblOnDeck];
// set img opacity to 100
setOpacity(theimg,100);

	// shuffle the deck
gblOnDeck = ++gblOnDeck % gblDeckSize;
// decrement rotation counter
if (--gblImageRotations < 1)
{
  // insert start/final image if we're done
  gblImg[gblOnDeck] = gblStartImg;
}

// slide next image underneath
thediv.style.backgroundImage='url(' + gblImg[gblOnDeck] + ')';
}

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  

  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;

  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;

  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

//--><!]]>