//MGuesdon - Oxymium
function firstParentOfType(Elem,type)
{
  var anElem=Elem.parentNode;
  while(anElem)
    {
      if (anElem.tagName==type)
        {
          return anElem;
        }
      else
        {
          anElem=anElem.parentNode;
        }
    }
  return null;
}


function enlargeImage(open, iref, maxScale)
{
  if (open) 
    {
      if (1)
	{
	  var docWidth = 0; 
	  var docHeight = 0; 
	  //opera Netscape 6 Netscape 4x Mozilla 
	  if (window.innerWidth || window.innerHeight)
	    { 
	      docWidth = window.innerWidth; 
	      docHeight = window.innerHeight; 
	    } 
	  if (document.body.clientWidth || document.body.clientHeight)
	    { 
	      docWidth = document.body.clientWidth; 
	      docHeight = document.body.clientHeight; 
	    } 
	  // top for popup image 10 pixels
	  // below corresponding thumb
	  var nWidth=0;
	  var nHeight=0;
	  if (iref.naturalWidth==null)
	    {
	      nWidth=parseInt(maxScale*iref.clientWidth);
	      nHeight=parseInt(maxScale*iref.clientHeight);
	    }
	  else
	    {
	      nWidth=iref.naturalWidth;
	      nHeight=iref.naturalHeight;
	      var xScale=nWidth/iref.clientWidth;
	      var yScale=nHeight/iref.clientHeight;
	      if (xScale>maxScale
		  || yScale>maxScale)
		{
		  nWidth=parseInt(maxScale*iref.clientWidth);
		  nHeight=parseInt(maxScale*iref.clientHeight);
		}
	    }
	  if (nWidth!=iref.clientWidth
	      ||nHeight!=iref.clientHeight)
	    {
	      var offsX=0;
	      var offsY=0;
	      var aP=iref;
	      while(aP)
		{
		  aP=aP.offsetParent;
		  if (aP && (aP.offsetLeft || aP.offsetTop))
		    {
		      offsX+=aP.offsetLeft;
		      offsY+=aP.offsetTop;
		    }
		}
	      var centerX=0;
	      centerX+=iref.offsetLeft;
	      centerX+=(iref.offsetWidth/2);
	      var centerY=0;
	      centerY+=iref.offsetTop;
	      centerY+=(iref.offsetHeight/2);
	      var left=parseInt(centerX-nWidth/2)+offsX;
	      var top=parseInt(centerY-nHeight/2)+offsY;
	      if (docWidth>0 && (left+nWidth)>(docWidth+50))
		left=(docWidth+50)-nWidth;
	      if (left<0)
		left=0;
	      if (docHeight>0 && (top+nHeight)>(docHeight+50))
		top=(docHeight+50)-nHeight;
	      if (top<0)
		top=0;
	      var img = '<img border="0" width="'+nWidth+'" height="'+nHeight+'" src="' +iref.src + '" />';
	      var parentA=firstParentOfType(iref,'A');
	      if (parentA)
		{
		  img="<a id='enlargeImageDivA'>"+img+"</a>";
		}

	      // if popup hasn't yet been added,  create and append to body
	      if (null ==  document.getElementById('enlargeImageDiv')) 
		{
		  var pop = document.createElement('DIV');
		  pop.id = 'enlargeImageDiv';
		  pop.style.position = 'absolute';
		  pop.onmouseout = function() { enlargeImage(false,iref,0); };
		  document.body.appendChild(pop);		  
		}
	      // get reference to popup image container div
	      var pop =  document.getElementById('enlargeImageDiv');
	      // set image element into div
	      pop.innerHTML = img;
	      if (parentA)
		{
		  var aA=document.getElementById('enlargeImageDivA');
		  aA.href = parentA.href;
		  aA.target = parentA.target;
		  aA.title = parentA.title;
		  aA.onclick = parentA.onclick;		  
		}
	      // position relative to thumbnail
	      pop.style.left = left+'px';
	      pop.style.top = top+'px';
	      // show the div and its image
	      pop.style.display = 'block';
	      pop.style.visibility = 'visible';
	    }
	}
    }
  else 
    {
      // since request was for close,  hide the div -don't destroy it, since it can be recycled cheaper
      var pop =  document.getElementById('enlargeImageDiv');
      pop.style.display = 'none';
      pop.style.visibility = 'hidden';
    }
}
