//This script is to display randomly on Photo Gallery page
//and it's written based on the script of Philip Guo
//Copyright 2007 SVA. All rights reserved.

BASE_URL = "photo_gallery/";

// To make sure that we open different windows and don't simply
// clobber the same window:
uniqueID = 0;

function OpenURLinNewWindow(url) {
  // If the screen is large enough, make it the optimal width/height for a gallery.
  // Otherwise, make it almost as large as the screen
  var maxScreenWidth = screen.width - 20;
  var maxScreenHeight = screen.height - 80;

  var optimalGalleryWidth = 1000;
  var optimalGalleryHeight = 920;

  var width = (optimalGalleryWidth < maxScreenWidth) ? optimalGalleryWidth : maxScreenWidth;
  var height = (optimalGalleryHeight < maxScreenHeight) ? optimalGalleryHeight : maxScreenHeight;

  var handle = window.open(url,'galleryWin' + uniqueID,'scrollbars=yes,menubar=no,resizable=yes,width=' + width + ',height=' + height);
  handle.moveTo(100,20);
  if (window.focus) {
    handle.focus();
  }

  uniqueID++;
}


function InitRandomImages() {
  var Img11 = document.getElementById ? 
  document.getElementById("Img11") : document.all.Img11;
  
  var Img12 = document.getElementById ? 
  document.getElementById("Img12") : document.all.Img12;
  
  var Img13 = document.getElementById ? 
  document.getElementById("Img13") : document.all.Img13;
  
  var Img21 = document.getElementById ? 
  document.getElementById("Img21") : document.all.Img21;
  
  var Img22 = document.getElementById ? 
  document.getElementById("Img22") : document.all.Img22;
  
  var Img0811 = document.getElementById ? 
  document.getElementById("Img0811") : document.all.Img0811;
  
  var Img0812 = document.getElementById ? 
  document.getElementById("Img0812") : document.all.Img0812;

  InitImagesAndLinks(Images0811, Img0811);
  InitImagesAndLinks(Images0812, Img0812);
  InitImagesAndLinks(Images11, Img11);
  InitImagesAndLinks(Images12, Img12);
  InitImagesAndLinks(Images13, Img13);
  InitImagesAndLinks(Images21, Img21);
  InitImagesAndLinks(Images22, Img22);
}


function InitImagesAndLinks(images, img1) {
  numImages = images.length;
  v1 = Math.round(Math.random() * numImages);

  // In rare cases, we hit the max, so don't go out of bounds:
  if (v1 == numImages) {v1 -= 1;}
  
  // Display image
  img1.src = BASE_URL + images[v1];
}

function OpenPicasaAlbum(url) {
  // If the screen is large enough, make it the optimal width/height for a gallery.
  // Otherwise, make it almost as large as the screen
  var maxScreenWidth = screen.width - 20;
  var maxScreenHeight = screen.height - 80;

  var optimalGalleryWidth = 1000;
  var optimalGalleryHeight = 920;

  var width = (optimalGalleryWidth < maxScreenWidth) ? optimalGalleryWidth : maxScreenWidth;
  var height = (optimalGalleryHeight < maxScreenHeight) ? optimalGalleryHeight : maxScreenHeight;

  var handle = window.open(url,'galleryWin' + uniqueID,'scrollbars=yes,menubar=no,resizable=yes,width=' + width + ',height=' + height);
  
  uniqueID++;
}
