// JavaScript code for frankleecattery.com Spotted Acres gallery

// Lionel Deimel, 5/15/2005

// Note that the code here is somewhat more complex than that used in the Bombay and Tonkinese galleries.

// Create global variable for new window
var popWindow;

// Define default values for width and height of popup windows. These default values assume
// photos with dimensions 300 px x 400 px. Defaults specify window width (W) and height (H)
// for portrait mode (P) and landscape mode (L). Photos of other dimensions require that window
// sizes be adjusted.
var defaultWP = 380;
var defaultHP = 585;
var defaultWL = 480;
var defaultHL = 485

// Define default location for top left corner of window created by popup
var topOfWindow = 40;
var leftOfWindow = 170;

// Define arrays that specify Web pages and window sizes for Spotted Acres gallery. Note that
// the order of the gallery pictures is not specified here.
saPicture = new Array(13);
saWidth = new Array(13);
saHeight = new Array(13);
saPicture[0]  = "road.html";           saWidth[0]  = defaultWL; saHeight[0]  = defaultHL;
saPicture[1]  = "house.html";          saWidth[1]  = defaultWL; saHeight[1]  = defaultHL+13;
saPicture[2]  = "pair.html";           saWidth[2]  = defaultWL; saHeight[2]  = defaultHL+21;
saPicture[3]  = "gazebo.html";         saWidth[3]  = defaultWL; saHeight[3]  = defaultHL;
saPicture[4]  = "winter_morning.html"; saWidth[4]  = defaultWL; saHeight[4]  = defaultHL-39;
saPicture[5]  = "welcome.html";        saWidth[5]  = defaultWP; saHeight[5]  = defaultHP;
saPicture[6]  = "tree.html";           saWidth[6]  = defaultWP; saHeight[6]  = defaultHP;
saPicture[7]  = "courtyard.html";      saWidth[7]  = defaultWL; saHeight[7]  = defaultHL-21;
saPicture[8]  = "kitchen.html";        saWidth[8]  = defaultWL; saHeight[8]  = defaultHL;
saPicture[9]  = "recroom.html";        saWidth[9]  = defaultWL; saHeight[9]  = defaultHL+39;
saPicture[10] = "steps.html";          saWidth[10] = defaultWL; saHeight[10] = defaultHL+39;
saPicture[11] = "bed.html";            saWidth[11] = defaultWL; saHeight[11] = defaultHL-71;
saPicture[12] = "easy.html";           saWidth[12] = defaultWL; saHeight[12] = defaultHL+30;

// Define gallery order. The value of saOrder[i] is the index of the saPicture element whose value is
// the page that follows the page given by saPicture[i]. This is essentially a linked list without
// a terminal sentinel.
saOrder = new Array(12);
saOrder[0]  = 3;
saOrder[1]  = 5;
saOrder[2]  = 4;
saOrder[3]  = 2;
saOrder[4]  = 1;
saOrder[5]  = 6;
saOrder[6]  = 7;
saOrder[7]  = 8;
saOrder[8]  = 9;
saOrder[9]  = 10;
saOrder[10] = 11;
saOrder[11] = 12;

// function popup
//
// Open popup window named popWindow that displays the page whose name is pageName.
// If such a window is already open, it is first closed to assure a window of the proper size is
// created. If either of the size parameters is 0, the corresponding default value (using topOfWindow
// or leftOfWindow is used instead.

function popup(pageName, w, h) {

	// Define local variables to hold dimensions of window popWindow. These variables are initially
	// set to the default dimensions.
	var windowW = defaultWP;
	var WindowH = defaultHP;
	
	// Close existing window. Actually, this line is useful only for very old browsers because of the
	// lines that follow. (See below.)
	if (typeof(popWindow) != "undefined" && !popWindow.closed) {popWindow.close()};

	// Use window dimensions from parameter list if they are not 0
	if (w!=0) {windowW = w};
	if (h!=0) {windowH = h};
	
	// Create new window. If the window is not new, its size and position may not be set by this
	// statement, depending upon the browser.
	popWindow = window.open(pageName, "popWin", "resizable=yes,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,top=topOfWindow,left=leftOfWindow,copyhistory=0,width="+windowW+",height="+windowH);

	// Assure proper size, position, and visibility. The top two statements may not work for very old
	// browsers.
	popWindow.resizeTo(windowW,windowH);
	popWindow.moveTo(leftOfWindow,topOfWindow);
	popWindow.focus();

	}

// function saPopup
//
// Call function popup with appropriate parameters for the seqNo-th page defined for the Spotted Acres
// gallery by arrays saPicture, saWidth, and saHeight. The lowest valid value of seqNo is 0.
	
function saPopup(seqNo) {

	// Call popup with proper parameters
	popup(saPicture[seqNo], saWidth[seqNo], saHeight[seqNo]);

	}

// function saNext
//
// Call function saPopup to open a window displaying the page following the page with URL url in the
// sequence of pages for the Spotted Acres gallery. There is no error handling; the parameter is assumed
// to be valid.
	
function saNext(url) {

	// Define variables to hold file name and loop index
	var fileName;
	var i;
	
	// Extract file name from URL
	fileName = url.substr(url.lastIndexOf('/')+1, url.length);
	
	// Search for file name in page sequence
	i = 0;
	while (saPicture[i] != fileName) {i = i+1};
	
	// Display next page in Spotted Acres gallery sequence. Notice that i is the index of the current
	// page in the saPicture array, so saPicture[saOrder[i]] is the next page to be displayed.
	saPopup(saOrder[i]);
	
	}
	
// function saPrevious
//
// Call function saPopup to open a window displaying the page before the page with URL url in the
// sequence of pages for the Spotted Acres gallery. There is no error handling; the parameter is assumed
// to be valid.
	
function saPrevious(url) {
	
	// Define variables to hold file name and loop indices
	var fileName;
	var i;
	var j;
	
	// Extract file name from URL
	fileName = url.substr(url.lastIndexOf('/')+1, url.length);
	
	// Search for file name in page sequence
	i = 0;
	while (saPicture[i] != fileName) {i = i+1};
	
	// Search for previous page. Notice that i is the index of the current page in the saPicture array.
	j=0;
	while (saOrder[j] != i) (j = j+1)

	// Display the previous page in Spotted Arrays gallery sequence. Notice that saOrder[j] = i, so
	//saPicture[j] is the page to be displayed. 
	saPopup(j);
	
	}

