//  global values
// HAS  ############ FIXED offset LEFT  ####################

// ==================================================================
var VertOffset    =0;  // Half Vertical Menu/Border? - up  + Down
var HorzOffset    =0;  // Half Horizontal Menu   - Left  + Right

var BarHeight=2*30;  // 2 bars 30px each
var AutoPopupStyle="position:absolute;left:-100px;top:-100px;visibility:hidden;border: 1px solid rgb(0,0,0);"
var CloseBarStyle ="border: 0px solid #000000; padding:3px; background-color: #3E2D01;min-width: 100px; /*NS6 style to overcome bug*/"
var CloseTextStyle="color:rgb(255,255,255); font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-weight:bold; margin-right:1px;"
var LoadingStyle  ="cursor: pointer;cursor: hand;cursor: move;background: url(/images/loading.gif) no-repeat; background-position: center center;"
var DragTitle     ="Click and Drag"
var DragAreaStyle ="padding: 0px;border-top: 1px solid rgb(0,0,0);border-bottom: 1px solid rgb(0,0,0);"  // gets rid of the 1 px border in Cell

var EnablePrint=1  // 0=False or 1=True
var PrintLink =""

if (EnablePrint) {
 PrintLink ='&nbsp;&nbsp;&nbsp;<a href="#" id="closetext" onclick="AutoPopupPrint();return false">Print</a>'
}

var AutoPopupTableStyle="background-color:rgb(0,0,0);"

// ==================================================================

//var LoadingStyle="background: url(/images/loading.gif) no-repeat; background-position: 50% 50%;"

var AutoPopupPrintURL;

function changeLinks()
    {
      var as,i,islink;
// grab all links, loop over them;
      as=document.getElementsByTagName('a');
      for(i=0;i<as.length;i++)
      {
// check which link has a target attribute, and send this one to popup
      if (as[i].getAttribute('href')) 
       {
        if( (Right( (as[i].getAttribute('href')).toLowerCase(),4) == '.jpg') ||
            (Right( (as[i].getAttribute('href')).toLowerCase(),4) == '.gif')  )
        {
//if (typeof as[i].onclick != 'function') {
           as[i].onclick=function(event){return(AutoPopupEnlarge(this.href,event,'center',500,500,"NotURL"));};
//    }           
         }
        }  
      }
    }


/* Extended Window 'onload' */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
      window.onload = func;
   }
  else {
   window.onload = function() { oldonload(); func(); }
   }
}


// if the browser can deal with DOM, call the function onload
    if(document.getElementById && document.createTextNode)
    {
    }

// #####################################
function Left(str, n){
  if (n <= 0)
      return "";
  else if (n > String(str).length)
      return str;
  else
      return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

// ######################### NEW POPUP #############################
// EXAMPLE:
// onClick="return AutoPopupEnlarge('lemoncake.jpg',event,'center',300,375)">

document.write('<style type="text/css">');
document.write('#AutoPopupShow{'+AutoPopupStyle+'}');
document.write('#Closebar{'+CloseBarStyle+'}');
document.write('.loading {'+LoadingStyle+'}');
document.write('#CloseBar #closetext{'+CloseTextStyle+'}');
document.write('.AutoPopupTable{'+AutoPopupTableStyle+'}');
document.write('#DragArea {'+DragAreaStyle+'}');
document.write('</style>');
document.write('<div id="AutoPopupShow" STYLE="z-index:32767;"></div>')

// ### script
/***********************************************
* 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
***********************************************/
var ie=document.all
var ns6=document.getElementById&&!document.all

  if (ie||ns6)
   {
    crossobj=document.getElementById? document.getElementById("AutoPopupShow") : document.all.AutoPopupShow
   }
function ietruebody(){
return (document.compatMode &&
document.compatMode!="BackCompat" && !window.opera)?
document.documentElement : document.body
}

var lastimgwidth=0;
var lastimgheight=0;


function AutoPopupEnlarge(which, e, position, imgwidth, imgheight, Dtype){

AutoPopupPrintURL=which;

if (lastimgwidth==0||lastimgheight==0) {
lastimgwidth=imgwidth;
lastimgheight=imgheight;
}
RePosition=false;  // if False, don't show until loaded
 x= ResetEnlarge(e,position, lastimgwidth, lastimgheight)
RePosition=true;
if (x==false) {
var InnerParts;
//InnerParts='<table width=0 border="0" CELLSPACING=0 BGCOLOR="white"><tr ><td align="Left"><font color=black>Drag</font></td><td width="5%"><a id="closetext" href="#" onClick="closepreview();return false;"><font color=black>X</font></a></td></tr><tr><td COLSPAN="2" >'
//InnerParts='<table width=1 border="1" CELLSPACING=0 BGCOLOR="white"><tr><td>'
//

// 
InnerParts='<table width=150 height=150 border="0" CELLSPACING=0 class="AutoPopupTable"><tr><td align="Center" height=1 id="CloseBar"><a id="closetext" href="#" onClick="closepreview();return false;">Close</a>'+PrintLink+'</td></tr><tr><td COLSPAN="1" Class="loading" id="DragArea" title="'+DragTitle+'" >'

  if (Dtype=="URL") {
   InnerParts+='<iframe id="AudoImageiFrame" width="'+imgwidth+'" height="'+imgheight+'" src="'+which+'" onload="ResetEnlarge(this ,\'center\', this.offsetWidth, this.offsetHeight)"></iframe>';
  }
  else
  {
//InnerParts+='<A HREF="#" STYLE="text-decoration: none" onClick="closepreview();return false;">'+PrintLink+'<img src="'+which+'" border=2></A>'
InnerParts+='<center><img src="'+which+'" id="DragArea"  onload="ResetEnlarge(this ,\'center\', this.offsetWidth, this.offsetHeight+BarHeight)" border=0></center>'
  }
InnerParts+='</td></tr><tr><td align="Center" height=1 id="CloseBar"><a id="closetext" href="#" onClick="closepreview();return false;">Close</a>'+PrintLink+'</td></tr></table>'

crossobj.innerHTML=InnerParts

//crossobj.style.visibility="visible"
return false
}
else {//if NOT IE 4+ or NS 6+, simply display image in full browser window
return true
}
}

function ResetEnlarge(e, position, imgwidth, imgheight)
 {
  
  if (ie||ns6)
   {
    crossobj=document.getElementById? document.getElementById("AutoPopupShow") : document.all.AutoPopupShow
    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
     }
if (RePosition==true) {
  crossobj.style.left=(horzpos+HorzOffset)+"px"
// ############ FIXED offset LEFT  ####################
//  crossobj.style.left=(330)+"px"

   crossobj.style.top=(vertpos+VertOffset)+"px"
   crossobj.style.visibility="visible"
//         crossobj.focus();
//         crossobj.onblur="closepreview();"

   }

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=="DragArea"||ns6&&e.target.id=="DragArea")
{
  offsetx=ie? event.clientX : e.clientX
  offsety=ie? event.clientY : e.clientY
  tempx=parseInt(crossobj.style.left)
  tempy=parseInt(crossobj.style.top)
  dragapproved=true
 crossobj.onmousemove=drag_drop

}
return false
}

function AutoPopupInit(){
 if (ie||ns6)
   {
   crossobj=document.getElementById? document.getElementById("AutoPopupShow") : document.all.AutoPopupShow
   crossobj.onmousedown=initializedrag
   crossobj.onmouseup=new Function("dragapproved=false")

   }
}
addLoadEvent(changeLinks);
addLoadEvent(AutoPopupInit)

var PrintPopup;

function AutoPopupPrint(){
// uses AutoPopupPrintURL for last popup info
//var printwindow=window.open("/AutoImagePrint.html","emptypage","width=400,height=200")
  var printwindow=window.open("/AutoImagePrint.html","emptypage","width="+lastimgwidth+",height="+lastimgheight)
}
