//                  360 Degree Panorama Image Viewer
// **************************************************************************
// 			Written by Martin Krolik
// 			http://krolik.net
// 			martin@krolik.net
// **************************************************************************
// Original Cross Browser (NS4+,NS6+/Mozilla1+,IE4+,Safari1+) DHTML 360 Degree Panormic Image Javascript Viewer
// Version 3.2 
// Works by putting two of the same image adjacent.  A viewport scrolls thru the images
// as the images moves to compensate.
// vars below
var mytimer,xdist,ydist,xoffset,yoffset,xviewport,yviewport,defaulttravel,defaulttimeout,borderheight,borderwidth,bwidth,bheight,myobject,outerimgdiv,mypframe,myloadingdiv,myimage,mysecondimage,initialized,loaded,xoffsetwithinpic,yoffsetwithinpic,origimagewidth,origimageheight,maxtravel;
 
var imgNW,imgN,imgNE,imgW,imgE,imgSW,imgS,imgSE; 
 
// vars above
// ----------------------  Parameters below --------------------------------//
xoffset = 0;   
yoffset = 0;
xoffsetwithinpic = 0; // messes everything up... see note in code - not implemented 
yoffsetwithinpic = 0; // messes everything up... see note in code - not implemented
xviewport = 615;   // size of view window ... must be less than size of image
yviewport = 240;
defaulttravel = 3; // how many pixels at a time we move .... choppy'ness VS. slowness
defaulttimeout = 20; // how many milliseconds between moves
maxtravel = 8; // max number of pixels to move with mouse move event
borderheight = 0; // actually should be derived from NORTH or SOUTH BORDER image, but isn't
borderwidth = 25; // actualy should be derived from EAST or WEST BORDER image, but isn't
var dblZoom = 1.0;
// ----------------------  Parameters above --------------------------------//
// init code below - no modifications required
initialized = false;
loaded = false;
var pOldOnLoadPIV = null;
var pOldOnResizePIV = null;
if (window.onload != null) {
  pOldOnLoadPIV = window.onload;
}
if (window.onresize != null) {
  pOldOnResizePIV = window.onresize;
}

var vstate = false;
var startx = 0;
var starty = 0;

function initpiv() 
{
  myobject = xGetElementById("dimg");
  outerimgdiv = xGetElementById("dimgOuter");
  mypframe = xGetElementById("mypicframe");
  myloadingdiv = xGetElementById("nowloading");
  myimage = xGetElementById("ione");
  
  imgNW = xGetElementById("borderNW");
  imgN = xGetElementById("borderN");
  imgNE = xGetElementById("borderNE");
  imgW = xGetElementById("borderW");
  imgE = xGetElementById("borderE");
  imgSW = xGetElementById("borderSW");
  imgS = xGetElementById("borderS");
  imgSE = xGetElementById("borderSE");
 
 
  origimagewidth = xWidth(myimage);
  origimageheight = xHeight(myimage); 
  loaded = true;
  positionpiv();
  if (pOldOnLoadPIV != null) {
    pOldOnLoadPIV();
  }	
}
function positionpiv()
{
  xoffset = xPageX('PlaceHolderDiv') + borderwidth;
  yoffset = xPageY('PlaceHolderDiv') + borderheight;
  if (loaded) 
  {
    xMoveTo(outerimgdiv,xoffset,yoffset);
    xMoveTo(mypframe,xoffset-borderwidth,yoffset-borderheight+1);
  }
  xHide(myloadingdiv);
  xClip(myloadingdiv,0,0,0,0);
  xShow(outerimgdiv);
  xShow(myobject);
  xShow(mypframe);
  xClip(mypframe,0,(xviewport+borderwidth+borderwidth),(yviewport+borderheight+borderheight),0);
  xClip(mypframe,0,(xviewport+borderwidth+borderwidth),(yviewport+borderheight+borderheight),0);
		
  // lines below seem to add wierd blank pixel lines to top and bottom
  // of scroll in ie5
  xdist = xoffsetwithinpic;
  ydist = yoffsetwithinpic;

  shiftover();
  quitmoving();
  xdist=1;
  ydist=0;
//  shiftover();  
  if (pOldOnResizePIV != null) {
    pOldOnResizePIV();
  }	

}	
function shiftover()
{
 if (loaded) 
 {
  quitmoving();
  if ( ((xTop(myobject) - ydist ) >= 0) && (ydist<0) ) 
  {
    ydist = 0; 
  } else
  if ( ((xTop(myobject) - ydist ) <= ( yviewport - xHeight(myimage) ) ) && (ydist>0) ) 
  {
    ydist = 0; 
  }
 
  if ( ((xLeft(myobject) - xdist ) >= 0) && (xdist<0) ) 
  {
    xdist = 0; 
  } else
  if ( ((xLeft(myobject) - xdist ) <= ( xviewport - xWidth(myimage) ) ) && (xdist>0) ) 
  {
    xdist = 0; 
  }

  xMoveTo(myobject, xLeft(myobject) - xdist, xTop(myobject) - ydist);

  if (document.layers)
  {
  	xClip(myobject,null, xviewport - xLeft(myobject) ,null,null);
  }
  initialized == true;
  if ((xdist != 0) || (ydist != 0))
  {
    mytimer = setTimeout("shiftover()",defaulttimeout);
  }
 }
}
function quitmoving() 
{
  if (mytimer)
  {
    clearTimeout(mytimer);
  }
  if (quitmoving.arguments.length > 0)
  {
    var blnClearDist = quitmoving.arguments[0];
    if (blnClearDist == true)
    {
      xdist = 0;
      ydist = 0;
    }
  }
}
function move_W() {
  xdist=-defaulttravel;
  ydist=0;
  shiftover();
}
function move_E() {
  xdist=defaulttravel;
  ydist=0;
  shiftover();
}

xMoveTo(myloadingdiv, xLeft('PlaceHolderDiv'), xTop('PlaceHolderDiv'));

window.onload=initpiv;
window.onresize=positionpiv;
