/***********************************************
* Image Thumbnail viewer- © Dynamic Drive (www.dynamicdrive.com)
* Last updated Sept 26th, 03'. This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

/*
instructions
put the following between the <HEAD> tags
  <SCRIPT SRC="imagepop.js" TYPE="text/javascript"></SCRIPT>
  <LINK REL="stylesheet" TYPE="text/css" HREF="imagepop.css">

put the following right behind the <BODY> tag
<div id="showimage"></div>

The image link should look something like this
<A HREF="#"><IMG SRC="myimage_small.jpg" CLASS="imgpopup"></A>
where the important thing is CLASS="imgpopup"
When the large image name is myimage.jpg
The thumbnail name has to be myimage_small.jpg

*/
function waitForDimensions(imgName) { 
  var img = eval(imgName); 
  if ( img.width==0 || img.height==0 ) 
    setTimeout("waitForDimensions('"+imgName+"')",500); 
  else 
    enlarge(img.src, event, 'center', img.width, img.height);
} 

function initRollovers() {

  if (!document.getElementById) return
  
  var aImages = document.getElementsByTagName('img');

  for (var i = 0; i < aImages.length; i++) {    
    if (aImages[i].className == 'imgpopup') {
      var src = aImages[i].getAttribute('src');
      var ftype = src.substring(src.lastIndexOf('.'), src.length);
      var hsrc = src.replace('_small','');

      aImages[i].setAttribute('hsrc', hsrc);
      
      aImages[i].onclick = function() {
       aPreLoad = new Image();
       aPreLoad.src = this.getAttribute('hsrc');
       enlarge(aPreLoad.src, event, 'center', aPreLoad.width, aPreLoad.height);
      }
    }
  }
}

window.onload = initRollovers;

var ie=document.all
var ns6=document.getElementById&&!document.all

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat" && !window.opera)? document.documentElement : document.body
}

function enlarge(which, e, position, imgwidth, imgheight){
if (ie||ns6){
crossobj=document.getElementById? document.getElementById("showimage") : document.all.showimage
if (position=="center"){
pgyoffset=ns6? parseInt(pageYOffset) : parseInt(ietruebody().scrollTop)
horzpos=ns6? pageXOffset+window.innerWidth/2-imgwidth/2 : ietruebody().scrollLeft+ietruebody().clientWidth/2-imgwidth/2
vertpos=ns6? pgyoffset+window.innerHeight/2-imgheight/2 : pgyoffset+ietruebody().clientHeight/2-imgheight/2
if (window.opera && window.innerHeight) //compensate for Opera toolbar
vertpos=pgyoffset+window.innerHeight/2-imgheight/2
vertpos=Math.max(pgyoffset, vertpos)
}
else{
var horzpos=ns6? pageXOffset+e.clientX : ietruebody().scrollLeft+event.clientX
var vertpos=ns6? pageYOffset+e.clientY : ietruebody().scrollTop+event.clientY
}
crossobj.style.left=horzpos+"px"
crossobj.style.top=vertpos+"px"

crossobj.innerHTML='<div align="right" id="dragbar"><span id="closetext" onClick="closepreview()">Sluiten</span> </div><img src="'+which+'">'
crossobj.style.visibility="visible"
return false
}
else //if NOT IE 4+ or NS 6+, simply display image in full browser window
return true
}

function closepreview(){
crossobj.innerHTML=''
crossobj.style.visibility="hidden"
}

function drag_drop(e){
if (ie&&dragapproved){
crossobj.style.left=tempx+event.clientX-offsetx+"px"
crossobj.style.top=tempy+event.clientY-offsety+"px"
}
else if (ns6&&dragapproved){
crossobj.style.left=tempx+e.clientX-offsetx+"px"
crossobj.style.top=tempy+e.clientY-offsety+"px"
}
return false
}

function initializedrag(e){
if (ie&&event.srcElement.id=="dragbar"||ns6&&e.target.id=="dragbar"){
offsetx=ie? event.clientX : e.clientX
offsety=ie? event.clientY : e.clientY

tempx=parseInt(crossobj.style.left)
tempy=parseInt(crossobj.style.top)

dragapproved=true
document.onmousemove=drag_drop
}
}

document.onmousedown=initializedrag
document.onmouseup=new Function("dragapproved=false")
