////// panoCode.js  -- Copyright 2002, Armchair Travel Co Ltd
//  -- Updated 28 June 04 - wcd
//  -- Usage Examples --
// Main Browser Window:
// Header HTML:
//   <HEAD> ...... <SCRIPT LANGUAGE="JavaScript" SRC="panoCode.js"> < /SCRIPT> </HEAD>
//   <BODY BGCOLOR="#ECFFF0" onFocus="Javascript:myOnFocus()">
//
// Calling HTML:
//     (assumes '.jpa' encrypted pano source files)
//   <A HREF="javascript:vrWindow(79, 'B', 'Big Pano Title')">Large Pano Btn</A>
//   <A HREF="javascript:vrWindow(79, 'M', 'Medium Pano Title')">Medium Pano Btn</A>
//   <A HREF="javascript:vrWindow(79, 'S', 'Small Pano Title')">Small Pano Btn</A>
//
// for unencrypted pano source files,
// add optional 4th arg = file extension, e.g '.jpg'
//   <A HREF="javascript:vrWindow(79, 'S', 'Title', '.jpg')">Small Pano Btn</A>
//

var newwindow = "";

///////////////
// Function to close the Pano window before a new one is opened

function myOnFocus() {
 if(newwindow && !newwindow.closed) setTimeout('newwindow.close();',100);
}

// Function to open a new pano window

function vrWindow(panoIDnumber, panoSize, panoTitle, panoFileExt) {

//where:
//   panoIDnumber - is the number of the pano, e.g. "79", 79, "0079", etc
//   panoSize - is the small/medium/big visitor request: "S", "M" or "B"
//   panoTitle - is the title of the pano window --
//        -->  Watch out for single quote in names: Queen's Cottage
// optional args:
//   panoFileExt - is ".jpg" etc; if missing, assume ".jpg" not encrypted
//

  // If old Pano window is open, close it
  if(newwindow && !newwindow.closed) newwindow.close();

  panoIDnumber = panoIDnumber - 0;  // convert

  // Search for pano id integer (n=NNNN) in panoArray
    for (j=3; j<panoArray.length; j+=3) {
      i = j;
      if (panoIDnumber == 0+panoArray[j].substr(0,4)) break;
      i = 0; // default is 0 - "notFound"
    }

  fileName = panoArray[i];         // stem filename NNNNXXX...
  fileID = fileName.substr(0,4);   // file ID number NNNN
  hpan = panoArray[i+1];           // initial H pan
  zoom = panoArray[i+2];           // "Best" zoom for this pano

// *** NOTE: Having different pano files in different paths doesn't work right on CD

  ext = ".jpg";  // Assume panos are encrypted
  if (arguments.length >= 4) ext = panoFileExt; // otherwise, use this extension
  
  // fileName with Size Letter
  filePath = "pvr/" + fileName + panoSize + ext;
  pt_txt = '<IMG SRC="pvr/pt_txt.gif">';       // "How-to" VR button

  // All windows have 3:2 aspect ratio, with w & h multiples of 8 pixels.
  if (panoSize == "B") {  // Big pano
    qual = 2;  // high quality when still
    w = 744;
    h = 496;

    // "allowBig" var is in "panoArray.js" code; controls display of Big panos
    if (!allowBig) {
      filePath = "pvr/SampleB.jpg";      // Force SampleB.jpg pano
      pt_txt = '<A HREF="cdinfo.htm">';  // Clickable "VR usage" instructions
      pt_txt += '<IMG SRC="pvr/pt_txtB.gif" BORDER="0"></A>';
      hpan = 45;    // View of text "More Info" in pano image
      zoom = 74;
      panoTitle = "High Resolution Pano from CD-ROM Edition";
      }

    }

  else if (panoSize == "M") {  //Medium size pano
    qual = 3;  // always high quality
    w = 528;
    h = 352;
    }

  else {   // Small size pano
    qual = 3;  // always high quality
    w = 360;
    h = 240;
    }

  contents = 
  '<HTML><HEAD><TITLE>' +panoTitle+ '</TITLE></HEAD>'+
  '<BODY BGCOLOR="#000000" LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">'+
  '<DIV ALIGN="CENTER">' +
  '<APPLET CODE="ptviewer.class" WIDTH=' +w+ ' HEIGHT=' +h+ '>'+
    '<PARAM NAME=ARCHIVE     VALUE="pvr/ptviewer.jar">'+
    '<PARAM NAME=CACHE       VALUE="FALSE">'+
    '<PARAM NAME=CURSOR      VALUE="MOVE">'+
    '<PARAM NAME=PAN         VALUE="'  +hpan+ '">'+
    '<PARAM NAME=FOV         VALUE="'  +zoom+ '">'+
    '<PARAM NAME=WAIT        VALUE="pvr/' +fileID+ 'wait.jpg">'+
    '<PARAM NAME=FILE        VALUE="' +filePath+ '">'+
    '<PARAM NAME=QUALITY     VALUE="' +qual+ '">'+
    '<PARAM NAME=BARCOLOR    VALUE="223377">'+
    '<PARAM NAME=BGCOLOR     VALUE="000000">'+
    '<PARAM NAME=BAR_HEIGHT  VALUE="15">'+
    '</APPLET>'+
	pt_txt + '<DIV></BODY></HTML>';

  th = h + 49;
  tw = w;

  // If not IE, leave extra window height
  if (navigator.appVersion.indexOf("MSIE") < 0) {
  th = th + 15;
  tw = tw + 0;
 }

  // Center pano window on screen
  if (screen.width <= 800 && panoSize == "B") wtop = -8;
  else wtop = (screen.height/2) - (th/2) + 12;

  wleft = (screen.width/2) - (tw/2);   

  options = "toolbar=0,status=0,menubar=0,scrollbars=0,resizable=0,width=" +tw+ ",height=" +th+
     ",top=" +wtop+ ",left=" +wleft;

  newwindow = window.open("", "vr"+w+h, options);
  newwindow.document.write(contents);
  newwindow.document.close();
}
