var dsHMPGList = new Spry.Data.XMLDataSet("/featuredlistingsxml.asp", "root/listings/listing");
dsHMPGList.setColumnType("listing_image_url", "image");

var gEffectInProgress = null;
var gPendingSetRowIDRequest = -1;



function fadeInContent(notificationType, notifier, data)
{
if (notificationType != "onPostUpdate")
return;
var effect = new Spry.Effect.Fade('listings', { to: 100, from: 0, duration: 500, finish: function() {
// The region is now showing. Process any pending row change request.
gEffectInProgress = null;
if (gPendingSetRowIDRequest >= 0)
{
var id = gPendingSetRowIDRequest;
gPendingSetRowIDRequest = -1;
fadeOutContentThenSetRow(id);
}
}});
effect.start();
}

Spry.Data.Region.addObserver('listings', fadeInContent);

function fadeOutContentThenSetRow(rowID)
{
// If we have an effect already in progress, don't do anything
// We'll set the rowID when we're done.

if (gEffectInProgress)
{
gPendingSetRowIDRequest = rowID;
return;
}

// If the correct row is already showing, don't do anything!

if (rowID == dsHMPGList.getCurrentRowID())
return;

gEffectInProgress = new Spry.Effect.Fade('listings', { to: 0, from: 100, duration: 500, finish: function() {
dsHMPGList.setCurrentRow(rowID);
}});
gEffectInProgress.start();
}

function getNext(){
var curList = dsHMPGList.getCurrentRowID(); // get the current rowID
if(dsHMPGList != null && dsHMPGList.getData() != null){ // check to see if the last one in the xml tree has already passed
if(curList+1 >= dsHMPGList.getData().length){
fadeOutContentThenSetRow(0); // if so, start over
}else if( dsHMPGList.getData().length == curList){ // check to see if it's the last one in the xml tree
fadeOutContentThenSetRow(curList); // if so, set it to the last one
}else{ // if not
fadeOutContentThenSetRow(dsHMPGList.getCurrentRowID()+1); // increase the row ID
}
}}
checkFoIt = setInterval(getNext, 7000); // Start the auto update