// JavaScript Document
var view = {};
var imwidth=0;
var imheight=0;
var imtop=0;
var imleft=0;
var im=null;
var viewer=null;
var grabx=0;
var graby=0;
var orix=0;
var oriy=0;
var mousex=0;
var mousey=0;


view.viewer = function(pan,left,txt){
viewer = this;	
this.viewframe = document.createElement('div');
this.viewframe.className = "viewframe";
this.viewshadow = document.createElement('div');
this.viewshadow.className = "viewshadow";
this.viewcell = document.createElement('div');
this.viewcell.className = "viewcell";
this.navcell = document.createElement('div');
this.navcell.className = "navcell";
this.txtspan = document.createElement('span');
this.txtspan.className = "txtspan";
this.exitspan = document.createElement('span');
this.navcell.appendChild(this.txtspan);
this.navcell.appendChild(this.exitspan);
this.exitimage = new Image();
this.exitimage.style.cursor="hand"
this.exitimage.onclick=this.closeviewer;
this.exitimage.src = "../images/exit.gif";
this.exitspan.appendChild(this.exitimage);
this.viewframe.appendChild(this.viewcell)
this.viewframe.appendChild(this.navcell)
this.im = new Image();
this.im.style.top = "0px";
this.im.style.left = left + "px";
this.im.style.position="absolute"
im = this.im;
this.im.className="viewimage";
this.viewcell.appendChild(this.im)
this.txtspan.innerHTML = txt
if(pan==true){
this.im.onmousedown = this.grab
}

}


view.viewer.prototype.openviewer=function(){

var a = vImg.split(".")
im.src= a[a.length-2]+"_large.jpg"
document.body.appendChild(this.viewshadow);
document.body.appendChild(this.viewframe);
}

view.viewer.prototype.changeimage=function(txt){	
var a = vImg.split(".")
im.src= a[a.length-2]+"_large.jpg"
this.txtspan.innerHTML = txt
}



view.viewer.prototype.closeviewer=function(closer){
if(closer==this.exitimage){
	
document.body.removeChild(viewer.viewshadow);
document.body.removeChild(viewer.viewframe);
}else{
document.body.removeChild(this.viewshadow);
document.body.removeChild(this.viewframe);
}
im.src="";
vr=null;
}

view.viewer.prototype.zoomin=function(){
imwidth = im.width;
imheight=im.height;
imtop = im.style.top.substring(0,im.style.top.indexOf("px"));
imleft = im.style.left.substring(0,im.style.left.indexOf("px"));
im.width = imwidth *1.2;
im.height=imheight*1.2;
im.style.top =  imtop - imheight*.1
im.style.left = imleft - imwidth*.1
}


view.viewer.prototype.getMouseXY =function(e)  // works on IE6,FF,Moz,Opera7
{ 
  if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)

  if (e)
  { 
    if (e.pageX || e.pageY)
    { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
      mousex = e.pageX;
      mousey = e.pageY;
     
      algor = '[e.pageX]';
      if (e.clientX || e.clientY) algor += ' [e.clientX] '
    }
    else if (e.clientX || e.clientY)
    { // works on IE6,FF,Moz,Opera7
      mousex = e.clientX + document.body.scrollLeft;
      mousey = e.clientY + document.body.scrollTop;
      algor = '[e.clientX]';
      if (e.pageX || e.pageY) algor += ' [e.pageX] '
    }  
  }

}


view.viewer.prototype.grab=function(e)
{
  viewer.getMouseXY()
  //document.onmousedown = falsefunc; // in NS this prevents cascading of events, thus disabling text selection
dragobj = this;
  if(dragobj==im){
	  
  //dragobj.style.zIndex = 10; // move it to the top
  this.onmousemove = viewer.drag;
 this.onmouseup = viewer.drop;
  grabx = mousex;
  graby = mousey;
 
  elex = orix = dragobj.offsetLeft;
  eley = oriy = dragobj.offsetTop;
  }
}




view.viewer.prototype.drag=function(e) // parameter passing is important for NS family 
{
  if (dragobj)
 
  {
   
	
        viewer.getMouseXY(e)
         elex = orix + (mousex-grabx);
         eley = oriy + (mousey-graby);
         dragobj.style.position = "absolute";
         dragobj.style.left = (elex).toString(10) + 'px';
         dragobj.style.top  = (eley).toString(10) + 'px';
  }
	
  return false; 
}


view.viewer.prototype.drop=function ()
{
  if (dragobj)
  {
    //dragobj.style.zIndex = 0;
    dragobj = null;
    
  }


  document.onmouseup = null;
  document.onmousedown = null;   // re-enables text selection on NS
}