var images = new Array();
var currentpic = 0;

function picmoveto(n) {
  switchtopicture(currentpic + n);
}

function switchtopicture(n)
{
  if (n < 0) n = images.length - 1;
  if (n > (images.length - 1)) n = 0;

  //switch to image
  document.mainpicture.src = images[n];
  fixSize(document.mainpicture);
  currentpic = n;
}

function fixSize(imgObj)
{
  var realImg = new Image();
  realImg.src = imgObj.src;

  imgObj.width  = realImg.width;
  imgObj.height = realImg.height;

  //image verkleinen als groter dan max size
  if (maxheight && imgObj.height > maxheight) {
    var tmp = imgObj.height;
    imgObj.height = maxheight;
    imgObj.width = imgObj.width / (tmp / imgObj.height);
  }
  if (maxwidth && imgObj.width > maxwidth) {
    var tmp = imgObj.width;
    imgObj.width = maxwidth;
    imgObj.height = imgObj.height / (tmp / imgObj.width);
  }
}
