/* Instructions:  Add another album by adding the following items to the albumList array.  The first line is the
                  most recent album.  Don't forget the comma at the end of the line!  The last line does NOT have a comma.
   1. Album name 
   2. directory name of album
   3. Picture of Album
   4. Album caption 
   5. width
   6. height
   7. description of picture
*/
var albumList = new Array (
	"LASCI2008", "gallery", "OldGlory.jpg", "LASCI 2008", "75", "100", "Officers",
	"LASCI2007", "gallery", "Officers.jpg", "LASCI 2007", "100", "75", "Officers"
);

/* Instructions:  To add a new gallery of thumbnails add them contiguously and start at position 1. 
   Instructions:  Add additional thumbnails to an album by adding the following 5 items per line to the thumbs array.
		  Put the picture with others in that same album.
                  Don't forget the comma at the end of the line!  The last line does NOT have a comma.
   1. Album name, which is the first element in albumList array
   2. Image name of thumbnail
   3. Width of thumbnail
   4. height of thumbnail
   5. description
   6. Caption
   7. Width of large image
   8. Height of large image
*/
var gallery = new Array(
	"LASCI2008", "OldGlory.jpg", "75", "100", "Old Glory", "Old Glory 08", "263", "350",
	"LASCI2008", "Coordinator.jpg", "100", "79", "Coordinator", "08 Phyllis Semple and Doris Morse, Sister Cities State Coordinator for Northern California.", "350", "280",
	"LASCI2008", "LosAltosCityHall.jpg", "100", "67", "Los Altos City Hall", "08 Los Altos City Hall", "350", "237",
	"LASCI2008", "Jazz.jpg", "100", "74", "Jazz", "08 Jazz entertainment at Annual Party", "350", "260",
	"LASCI2007", "OldGlory.jpg", "75", "100", "Old Glory", "Old Glory", "263", "350",
	"LASCI2007", "Officers.jpg", "100", "75", "Officers", "(l. to r.) Pat Farrell, Co-president, Phyllis Semple, Co-president, and Carol Scharz, City Liaison Officer.", "350", "263",
	"LASCI2007", "Board.jpg", "100", "75", "Board", "Board of Directors, at monthly meeting", "350", "231",
	"LASCI2007", "Coordinator.jpg", "100", "79", "Coordinator", "Phyllis Semple and Doris Morse, Sister Cities State Coordinator for Northern California.", "350", "280",
	"LASCI2007", "VisitorsRustington.jpg", "100", "75", "Visitors from Rustington", "Visitors from Rustington, England, Ron and Margaret Warburton.", "350", "263",
	"LASCI2007", "SocialRustington.jpg", "100", "75", "Social", "Social for the Rustington visitors at the home of Mardell and Gerry Blaufarb, Board members.", "350", "263",
	"LASCI2007", "Chefs.jpg", "100", "75", "Chefs", "Chefs at the annual picnic meeting, (l. to r.) Bob Reed. Treasurer, Pat Farrell and Jack Heidmiller, executive vice-president.", "350", "263",
	"LASCI2007", "Buffet.jpg", "100", "75", "Buffet", "Fabulous buffet at the annual picnic.", "350", "263",
	"LASCI2007", "PicnicAttendees.jpg", "100", "75", "Picnic", "Picnic attendees (l. to r.) Mike Bruno, Membership chair, Marge Bruno, member and former mayor of Los Altos, and Myra Orta, member.", "350", "263",
	"LASCI2007", "HistoryHouseMuseum.jpg", "100", "75", "History House Museum", "History House Museum", "350", "263",
	"LASCI2007", "LosAltosCityHall.jpg", "100", "67", "Los Altos City Hall", "Los Altos City Hall", "350", "237",
	"LASCI2007", "Jazz.jpg", "100", "74", "Jazz", "Jazz entertainment at Annual Party", "350", "260",
	"LASCI2007", "StudentsShihLin.jpg", "100", "75", "Students from Shih Lin", "High school exchange students from Shih Lin and Taiwan consulate official", "350", "263",
	"LASCI2007", "RussianDancers.jpg", "100", "75", "Russian Dancers", "Russian dancers at Annual Party", "350", "263",
	"LASCI2007", "RussianDancers2.jpg", "100", "75", "Russian Dancers", "Russian dancers at Annual Party", "350", "263"
);


//----------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------

var albumName = 0;
var albumDir = 1;
var albumPic = 2;
var albumCaption = 3;
var albumWidth = 4;
var albumHeight = 5;
var albumAlt = 6;

var galleryElements = 8;

var numElements = 7;

var idList = new Array(); // Div id of album
var curAlbum = 0;
var startGallery = 0;
var numPics = 0;
var photoSel = 0;

//var borderColor = "#d0dcff";
var borderColor = "#99CC66";

//---------------------------------------------------------------------------------------
// Package vars to send to different page
function packQueryDataPhoto (whatPhoto) {
  var packed = "";
  var data = new Array();
  data[0] = curAlbum;
  data[1] = startGallery;
  data[2] = numPics;
  data[3] = albumList[(curAlbum*numElements)+albumDir];
  data[4] = whatPhoto;
  
  for (i = 0; (i < data.length); i++) {
    if (i > 0) {
      packed += ",";
    }
    packed += escape(data[i]);
  }
  return packed;

}


//---------------------------------------------------------------------------------------
// From boutell.com consultants - parses out data from the query string
function unpackQueryData () {

  var query = window.location.search;

  // Skip the leading ?, which should always be there,
  // but be careful anyway
  if (query.substring(0, 1) == '?') {
    query = query.substring(1);
  }

  var data = query.split(',');
  for (i = 0; (i < data.length); i++) {
    data[i] = unescape(data[i]);
  }

  return data;
}

//---------------------------------------------------------------------------------------
// Store Album div id's
function addId (id) {
  idList[idList.length] = id;
}

//---------------------------------------------------------------------------------------
// Return index where id matches Album div id
function findAlbum (id) {
  for (i=0; i<idList.length; i++) {
    if (idList[i] == id)
      return i;
  }
  return 0;
}

//---------------------------------------------------------------------------------------
// Find the offset in the gallery array where first picture is located in album and get
// number of photos in that album
function setThumb (albumName) {

  var totPics = 0;
  var found = 0;
  
  // Find album name in gallery array then find the number of photos in that gallery    
  for (i=0; i <gallery.length/galleryElements; i++) {
  
    if (gallery[i*galleryElements] == albumName) {   
      if (totPics == 0) {
        found = 1;
        startGallery = i;
      }
      totPics++;
    }
    else if (found)
      break;
  }
  return (totPics);
}

//---------------------------------------------------------------------------------------
// Add onClick callback to each album
function addOnclickAlbum (id, album) {

  if (document.layers) 	{

  }
  //put IE DOM commands here to hide the object;
  else if (document.all) {
    obj = document.all[id];

  }
  //put W3C DOM commands here to hide the object;
  else if (document.getElementById) {
    obj = document.getElementById(id);
  }

  if (obj) obj.onclick = function () {selectAlbum (album) };

}

//---------------------------------------------------------------------------------------
// Add onClick callback to each album
function addOnclickThumb (id, whatPhoto) {

  var obj = null;
  var ifrObj = null;

  if (document.layers) 	{

  }
  //put IE DOM commands here to hide the object;
  else if (document.all) {
    obj = document.all[id];
    ifrObj = document.all.ifr;
  }
  //put W3C DOM commands here to hide the object;
  else if (document.getElementById) {
    obj = document.getElementById(id);
    ifrObj = document.getElementById("ifr");
  }

  if (obj) obj.onclick = function () {selectPhoto (whatPhoto) };

}

//---------------------------------------------------------------------------------------
function selectPhoto (whatPhoto) {

  var packed = packQueryDataPhoto (whatPhoto);
  photoSel = whatPhoto;
  window.location="bigImage.html?" + packed;
}

//---------------------------------------------------------------------------------------
// Select the first album in the list.
function selectFirstAlbum () {
  selectAlbum ('album1');
}

//---------------------------------------------------------------------------------------
// Select the album, set the border to blue to denote that it is selected.  Read in the
// gallery associated with the album.
var curObj = 0;

function selectAlbum (id){

  var obj1 = null;
  var obj2 = null;

  if (document.layers) 	{

  }
  //put IE DOM commands here to hide the object;
  else if (document.all) {
    obj1 = document.all[id];
    obj2 = document.all.ifr;

  }
  //put W3C DOM commands here to hide the object;
  else if (document.getElementById) {
    obj1 = document.getElementById(id);
    obj2 = document.getElementById("ifr");
  }

  // If the newly selected album is the current one then return, nothing to do
  if (obj1 == curObj)
    return;

  // Set border width of selected album so that it is selected one
  if (obj1) {
//    obj1.style.borderColor="#3c4b8f";
    obj1.style.borderColor= borderColor;
    obj1.style.backgroundColor= borderColor;
    curAlbum = findAlbum (id);
    numPics = setThumb (albumList[curAlbum*numElements]);
  }

  // Show the album in the iframe
  if (obj2) {
    obj2.src = "galleryThumbs.html";
  }
   // If the current album is different from the newly selected one then set it's
   // border and background to unselected
  if ((curObj) && (curObj != obj1)) {
    curObj.style.borderColor = "#fefefe";
    curObj.style.backgroundColor="#fefefe";
  }

  // Set current album to newly selected one
  curObj = obj1;

}

