/***********************************************
* 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
***********************************************/

/* ------ */
/* setup */

// please look at the enlarge function 

/* ----- */


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_preload(which, content, e, position, imgwidth, imgheight){
	// preload image //
	var newImg = new Image();
	newImg.src = which;
	setTimeout("enlarge_exec('"+which+"', "+content+", "+e+", '"+position+"', "+imgwidth+", "+imgheight+");", 100);

}

function enlarge(which, content, e, position, imgwidth, imgheight){

/* ------ */
/* setup */
var orientation = 'horizontal';           // 'horizontal' or 'vertical'
                                          //when vertical the width is set to defaultWidth
var defaultHeight = 300;
var defaultWidth = 300;
var measureUnits = "px";
var addStyle = "background-color: #FFEBC9;";
var tableStyle = "background-color: #FFEBC9;";
/* end setup */
/* ----- */


if (ie||ns6){

var dimensions;
var newImgHeight = 0;
var newImageWidth = 0;

var newImg = new Image();
newImg.src = which;
var newContent = document.getElementById(content).innerHTML;

if ( (newImg.naturalHeight==undefined) )
{
  
  //not gecko check for ie
  if (newImg.complete == undefined) { 
    // not gecko or ie
    return;
  } else {
    //we have ie
    if (newImg.complete) {
      //it loaded get dimensions
      newImgHeight = newImg.height
      newImgWidth = newImg.width
    }
  }
} else {
  newImgHeight = newImg.naturalHeight;
  newImgWidth = newImg.naturalWidth;
}

if (newImgHeight == 0 || newImgWidth == 0) {
  // use default
  newImgHeight = defaultHeight;
  newImgWidth = defaultWidth;
  
}

//override then passed in imgwidth and imgheight
imgheight = newImgHeight;
imgwidth = newImgWidth;
//add a bit of padding
imgheight = imgheight;
imgwidth = imgwidth+25;


  if (orientation == 'vertical')
  {
    dimensions = 'height: ' +  newImgHeight + '; '
               + 'width: ' + defaultWidth + '; ';

  } else if ( orientation = 'horizontal') 
  {
    dimensions = 'width:' + newImgWidth + '; '; 
  }

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 if (position=="top_left")
{
var horzpos=ns6? pageXOffset : ietruebody().scrollLeft
var vertpos=ns6? pageYOffset : ietruebody().scrollTop
}
else if (position=="top_right")
{
pgyoffset=ns6? parseInt(pageYOffset) : parseInt(ietruebody().scrollTop)
horzpos=ns6? pageXOffset+window.innerWidth-imgwidth : ietruebody().scrollLeft+ietruebody().clientWidth-imgwidth
var vertpos=ns6? pageYOffset : ietruebody().scrollTop
}
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='<table style="' + tableStyle + '"'+ 'cellpadding="0" cellspacing="0" border="0">'
                    +'<tr><td><div align="right" id="dragbar" style="padding-right:5px;">'
                    +'<span id="closetext" onClick="closepreview()" >CLOSE</span></div>'
                    +'<div style="' +dimensions + addStyle + '"' +'>'+newContent+'</div></td></tr>'
                    +'<tr><td>'
                    +'<img src="'+which+'"></td></tr>'
                    +'</table>'
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.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")



