iIndex = 0;

Content = function(id, title, type) {
  this.id    = id;
  this.title = title;
  this.type  = type;
}

// Create popup div
galleryDiv           = document.createElement('div');
galleryDiv.className = 'galleryPopup';

function openGallery(iImageIndex) {
  if(iImageIndex != undefined)
    iIndex = iImageIndex;
  galleryDiv.innerHTML  = '<a href="#" onclick="previous();">&lt;</a>';
  galleryDiv.innerHTML += '<a href="#" onclick="next();">&gt;</a>';
  galleryDiv.innerHTML += '<a href="#" onclick="document.body.removeChild(this.parentNode)">X</a>';
  galleryDiv.innerHTML += '<div><img src="userimages/' + aImages[iIndex].id + '.jpg" /></div>';

  if(iImageIndex != undefined)
    document.body.appendChild(galleryDiv);
}

function next() {
  if (iIndex < aImages.length - 1)
    iIndex ++;
  else
    iIndex = 0;
  openGallery();
}
function previous() {
  if (iIndex > 0)
    iIndex --;
  else
    iIndex = aImages.length - 1;
    
  openGallery();
}

