
/**** EVENT GALLERY FUNCTIONS ****/
/* assumes the following globals have been set*/
var currPage; // the current page we are on
var lastPage; // the last page we can flip to
var galleryId; // the id of the gallery element
var prevId; // the id of the previous button
var nextId; // the id of the next button

// turns the "page" in the gallery for the specified number of pages - assumes 1 or -1
function turnPage(pages)
{
  // hide and show relevant items
  $('#'+galleryId+' .page'+currPage).hide();
  currPage += pages;
  $('#'+galleryId+' .page'+currPage).fadeIn();
  // previous button - should it be displayed?
  if (currPage > 1) {
    $('#'+prevId).show();
  }
  else {
    $('#'+prevId).hide();
  }
  // next button - should it be displayed?
  if (currPage < lastPage) {
    $('#'+nextId).show();
  }
  else {
    $('#'+nextId).hide();
  }
  hideCurrDiv();
/*
alert ('gallery id: ' + galleryId +
       ', prevId: ' + prevId +
       ', nextId: ' + nextId +
       ', currPage: ' + currPage +
       ', lastPage: ' + lastPage);
*/
}

// only 1 div at a time
var currDivId;
var nextDivId;
function showDiv (divId) {
  if (currDivId == divId) {
    isTrueMouseOut = false;
  }
  else {
    nextDivId = divId;
    setTimeout("showDiv2('"+divId+"')", 500);
    hideCurrDiv();
  }
}

function showDiv2(divId) {
  if (currDivId == undefined && divId == nextDivId)
  {
    $('#'+divId).fadeIn();
    currDivId = divId;
    nextDivId = undefined;
  }
}

function cancelShowDiv(divId) {
  if (divId == currDivId) {
    hideCurrDiv();
  }
  else if (divId == nextDivId) {
    nextDivId = undefined;
  }
}

var isTrueMouseOut = false;
function mouseOverNotOut() {
  isTrueMouseOut = false;
}

function hideCurrDiv() {
  if (currDivId != undefined) {
    isTrueMouseOut = true;
    setTimeout("hideCurrDiv2()", 1);
  }
}

function hideCurrDiv2() {
  if (isTrueMouseOut) {
    $('#'+currDivId).fadeOut();
    currDivId = undefined;
  }
}
