var pictureItems = new Array();
var zoomparamsItems = new Array();
var detailItems = new Array();
var downloadItems = new Array();

var imageviewurl = '';

var currentDisplayed = new Array();

function setImageViewURL(param) {
  imageviewurl = param;
}

function addPictureItem(pictureItem) {
  pictureItems[pictureItems.length] = pictureItem;
}

function addZoomparamsItem(zoomparamsItem) {
  zoomparamsItems[zoomparamsItems.length] = zoomparamsItem;
}

function addDetailItem(detailItem) {
  detailItems[detailItems.length] = detailItem;
}

function addDownloadItem(downloadItem) {
  downloadItems[downloadItems.length] = downloadItem;
}

function showPictures() {
  for (var i = 0; i < pictureItems.length; i++) {
    showPicture(i + 1, 1);
  }
}

function popupPic(itemNo) {
  var number = currentDisplayed[itemNo];
  var currentItem = pictureItems[itemNo - 1];
  var currentZoomparams = zoomparamsItems[itemNo - 1];
  var currentdetailurls = detailItems[itemNo - 1];
  var currentImageSrc = currentItem[number - 1];
  var currentZoomparam = currentZoomparams[number - 1];
  var currentDetailurl = currentdetailurls[number - 1];
     
  window.open(currentDetailurl, '', currentZoomparam);
} 

function showPicture(itemNo, number) {
  var currentItem = pictureItems[itemNo - 1];
  var currentdownloadurls = downloadItems[itemNo - 1];

  var image = document.getElementById('man-image' + itemNo);
  image.src = currentItem[number - 1];

  var iconimgprevious = null;

  if (number == 1) {
    iconimgprevious = document.getElementById('icon-img-previous-inactive' + itemNo);
    document.getElementById('icon-img-previous' + itemNo).style.visibility = 'hidden';
  } else {
    iconimgprevious = document.getElementById('icon-img-previous' + itemNo);    
    document.getElementById('icon-img-previous-inactive' + itemNo).style.visibility = 'hidden';
  }
  iconimgprevious.style.visibility = 'visible';

  var iconimgdownload = document.getElementById('icon-img-download' + itemNo);    
  iconimgdownload.style.visibility = 'visible';

  var currentDownloadurl = currentdownloadurls[number - 1];
  var linkimgdownload = document.getElementById('link-img-download' + itemNo);    
  linkimgdownload.href = currentDownloadurl;

  var iconimgzoom = document.getElementById('icon-img-zoom' + itemNo);    
  iconimgzoom.style.visibility = 'visible';

  var iconimgnext = null;
  if (number == currentItem.length) {
    iconimgnext = document.getElementById('icon-img-next-inactive' + itemNo);
    document.getElementById('icon-img-next' + itemNo).style.visibility = 'hidden';
  } else {
    iconimgnext = document.getElementById('icon-img-next' + itemNo);    
    document.getElementById('icon-img-next-inactive' + itemNo).style.visibility = 'hidden';
  }
  document.getElementById('icon-img-next' + itemNo);
  iconimgnext.style.visibility = 'visible';

  currentDisplayed[itemNo] = number;
}

function nextPicture(itemNo) {
  showPicture(itemNo, currentDisplayed[itemNo] + 1);
}

function previousPicture(itemNo) {
  showPicture(itemNo, currentDisplayed[itemNo] - 1);
}

