var maxWidth = 400;

function scaleImage(im) {

  if (typeof im.naturalWidth == 'undefined'){
	orim = new Image();
	orim.src = im.src;
	im.naturalWidth = orim.width;
	im.naturalHeight = orim.height;
  }

  if (im.naturalWidth > maxWidth) {

    im.width = maxWidth;
    var factor = maxWidth/im.naturalWidth;
    im.height = Math.round(im.naturalHeight*factor);
    im.style.maxWidth = im.naturalWidth + 'px';
    im.className = 'resized';
    im.title = 'Klik om de hele afbeelding te zien';
    im.onclick = unscaleImage;

  }
  
  if (im.naturalWidth < maxWidth) {

    im.width = im.naturalWidth;
    im.className = 'small';

  }
  

}

function unscaleImage() {

  if (this.width == maxWidth) {
    
	height = this.naturalHeight + 30;
	width = this.naturalWidth + 20;
	
	if(width > 800) width = 600;
	if(height > 450) height = 450;
	
	properties = "width=" + width + ",height=" + height + ",scrollbars=yes,resizable=yes,personalbar=no,status=no";
	htmltxt = "<html><head><title>Afbeelding</title></head><body>";
	htmltxt = htmltxt + "<img title='Klik om venster te sluiten' src='" + this.src + "' onClick='self.close();'/>";
	htmltxt = htmltxt + "</body></html>";
	
    popupImage =window.open('', 'Afbeelding', properties);
	popupImage.document.open();
    popupImage.document.write(htmltxt);
	popupImage.document.close();
  } else {
    this.width = maxWidth;
    this.style.borderWidth = '2px';
    this.title = 'Click for original size';
  }

}

