/*
**	listingSlideShow.js
**	JavaScript functions to handle slide show of listings. 
**
**                      Call InitializeListing() in the onLoad event of the page body.
**                      Each listing element must be enclosed in a div tag whose id
**                      is "listingX" (X : incremental number from 1 .. n). All listings
**                      should be enclosed in a parent "listings" div.
**
*/

  var visibleListing = null;
  var totalListings = 1;
  var slideShowOn = false;
  var timerId = null;
  var timerDelay = 3000;

  function InitializeListings(num) {

    totalListings = num;

    // show first listing, hide the rest and set visible listing to 1
    xShow('listing1');
    for (i = 2; i <= totalListings; i++) {
        eval("xHide('listing"+i+"');");
    }
    visibleListing = 1;

    StartListingSlideShow();
  }

  function StopListingSlideShow() {
    if (slideShowOn) clearInterval(timerId);
    slideShowOn = false;
  }

  function StartListingSlideShow() {
    StopListingSlideShow();
    timerId = setInterval("ShowListing()", timerDelay);
    slideShowOn = true;
  }

  function ShowListing() {
    // hide currently visible listing
    eval("xHide('listing"+visibleListing+"');");
    // increment visible listing
    if (visibleListing == totalListings) visibleListing = 1;
    else ++visibleListing;
    // show listing for current iteration
    eval("xShow('listing"+visibleListing+"');");
  }

