Gallery.imgPath = "/img/";
Gallery.imgSizes = ["sm", "md", "lg"];
Gallery.imgSize = Gallery.imgSizes[1];  // XXX
Gallery.imgViews = 0;
Gallery.pageImg = null;
Gallery.imgCaption = null;
Gallery.imgLink = null;
Gallery.imgCredit = null;
Gallery.loadingImg = null;
Gallery.loadTime = 0;
Gallery.curImg = 0;
Gallery.toLoad = 0;
Gallery.direction = 1;

function Gallery() {
}

Gallery.logGallery = function() {
	params.replace(ParamSet.names.imgViews, Gallery.imgViews, Param.SESSION);
}

// _include src/js/images.js
var lastImg = 61;
var numImgs = 62;
var gitems = new Array(62);
gitems[0] = ["0.jpg", "Bequia villa rental with stunning views", "The upstairs living room is filled with comfortable furniture and views of the neighboring islands", null, null, false];
gitems[1] = ["1.jpg", "Bequia villa rental with stunning views", "The open, airy living room offers dramatic views in every direction", null, null, false];
gitems[2] = ["2.jpg", "Bequia villa rental with stunning views", "The upstairs living room has lots of space for lounging and dining", null, null, false];
gitems[3] = ["3.jpg", "Bequia villa rental with stunning views", "Relax in the living room's cozy reading nook", null, null, false];
gitems[4] = ["4.jpg", "Bequia villa rental with stunning views", "The dining table seats six comfortably, with space for four more at the smaller table", null, null, false];
gitems[5] = ["5.jpg", "Bequia villa rental with stunning views", "Sleep in island-style luxury in the master bedroom's hand-carved antique bed", null, null, false];
gitems[6] = ["6.jpg", "Bequia villa rental with stunning views", "Awake every morning to stunning views of Park Bay", null, null, false];
gitems[7] = ["7.jpg", "Bequia villa rental with stunning views", "Soothing breezes lull you to sleep in the upstairs second bedroom", null, null, false];
gitems[8] = ["8.jpg", "Bequia vacation rental with stunning views", "The kitchen's pass-through counter provides casual seating and easy serving", null, null, false];
gitems[9] = ["9.jpg", "Bequia vacation rental with stunning views", "The kitchen is thoughtfully stocked with high-quality cookware and servingware", null, null, false];
gitems[10] = ["10.jpg", "Bequia vacation rental with stunning views", "The kitchen is bright and airy", null, null, false];
gitems[11] = ["11.jpg", "Bequia vacation rental with stunning views", "The downstairs living room is just steps from beautiful Park Bay", null, null, false];
gitems[12] = ["12.jpg", "Bequia vacation rental with stunning views", "Informal and comfortable, with lots of space for play and lounging", null, null, false];
gitems[13] = ["13.jpg", "Bequia vacation rental with stunning views", "The downstairs living room opens onto a shaded, breezy porch", null, null, false];
gitems[14] = ["14.jpg", "Bequia vacation rental with stunning views", "The romantic downstairs master bedroom looks directly out on Park Bay", null, null, false];
gitems[15] = ["15.jpg", "Bequia vacation rental with stunning views", "The downstairs second bedroom is serene and casual", null, null, false];
gitems[16] = ["16.jpg", "Bequia vacation rental with stunning views", "The villa is very child-friendly, with lots of kid gear available", null, null, false];
gitems[17] = ["17.jpg", "Bequia beaches right out your door", "Breathtaking views of Mustique and Park Bay from all the front rooms", null, null, false];
gitems[18] = ["18.jpg", "Bequia beaches right out your door", "Neighboring Battowia and Balliceaux light up in the afternoon sun", null, null, false];
gitems[19] = ["19.jpg", "Bequia beaches right out your door", "The porches fronting both living rooms invite you to lounge and take in the view", null, null, false];
gitems[20] = ["20.jpg", "Bequia beaches right out your door", "Sunbathe during the day and stargaze at night", null, null, false];
gitems[21] = ["21.jpg", "Bequia beaches right out your door", "Choose either sun or shade on the expansive porches", null, null, false];
gitems[22] = ["22.jpg", "Bequia beaches right out your door", "The rear courtyard is a perfect location for outdoor eating, playing, and relaxing", null, null, false];
gitems[23] = ["23.jpg", "Bequia beaches right out your door", "Perched over beautiful Park Bay, with stunning views in every direction", null, null, false];
gitems[24] = ["24.jpg", "Bequia hiking and biking trails", "Surrounded by pristine woodlands, Park Bay House is private yet accessible", null, null, false];
gitems[25] = ["25.jpg", "Bequia hiking and biking trails", "Explore the ruins of the 18th-century sugar mill inside the property's shaded entryway", null, null, false];
gitems[26] = ["26.jpg", "Bequia hiking and biking trails", "The grounds and environs of Park Bay House are steeped in history", null, null, false];
gitems[27] = ["27.jpg", "Bequia beaches right out your door", "Palm-fringed Park Beach lies at the foot of the driveway", null, null, false];
gitems[28] = ["28.jpg", "Bequia beaches right out your door", "Park Bay's large &quot;baby pool&quot; provides safe wading for all ages", null, null, false];
gitems[29] = ["29.jpg", "Bequia surfing", "There's a great surf break right in front of Park Bay House", null, null, false];
gitems[30] = ["30.jpg", "Bequia surfing", "Bequia surfing: no crowds, just nice clean breaks", null, null, false];
gitems[31] = ["31.jpg", "Bequia snorkeling and swimming right out your door", "Industry Beach, with its soft sand and swaying palms, is a few minutes' walk away", null, null, false];
gitems[32] = ["32.jpg", "Bequia snorkeling and swimming right out your door", "Dramatic Sal Bay is just beyond your back yard", null, null, false];
gitems[33] = ["33.jpg", "Bequia snorkeling and swimming right out your door", "The vibrant reef stretches from the villa (at lower left) across Park and Industry bays", null, null, false];
gitems[34] = ["34.jpg", "Bequia snorkeling and swimming right out your door", "The Old Hegg Turtle Sanctuary lies at the other end of Park Bay", null, null, false];
gitems[35] = ["35.jpg", "Bequia hiking and biking trails", "The villa (at right) is surrounded by miles of hiking and biking trails", null, null, false];
gitems[36] = ["36.jpg", "Bequia hiking and biking trails", "Discover the ruins and fantastic views on the hilltop behind the house", null, null, false];
gitems[37] = ["37.jpg", "Bequia maps", "Click on the image to go to Park Bay House using Google&trade; Maps", "&copy;2007 Google - Imagery &copy;2007 DigitalGlobe, TerraMetrics", "http://maps.google.com/maps?f=q&hl=en&q=13.0275,+-61.2117&ie=UTF8&z=18&ll=13.027502,-61.2117&spn=0.003695,0.006781&t=k&om=1&iwloc=addr", true];
gitems[38] = ["38.jpg", "Bequia maps", "Click on the image to go to Park Bay House using <a href=\"http://earth.google.com/index.html\" rel=\"external\">Google&trade; Earth</a>", "&copy;2006 Google &copy;2007 DigitalGlobe &copy;2007 Europa Technologies", "/misc/Park-Bay-House.kmz", false];
gitems[39] = ["39.jpg", "Bequia maps", "Map of northern Bequia, showing Park Bay House (just above &quot;Park Bay&quot; at bottom)", "&copy;1988 Government of Saint Vincent and the Grenadines", null, false];
gitems[40] = ["40.jpg", "Bequia information", "The lovely seaport of Port Elizabeth (&quot;the harbor&quot;) is the hub of activity on Bequia", null, null, false];
gitems[41] = ["41.jpg", "Bequia information", "The harbor's Front Street reflects the relaxed and friendly pace of life on Bequia", null, null, false];
gitems[42] = ["42.jpg", "Bequia information", "Beautiful Admiralty Bay is a magnet for sailing vessels of all kinds", "&copy; <a href=\"mailto:outhouse@caribsurf.com?subject=Photos on parkbayhouse.com\">Outhouse Graphics INC</a>", null, false];
gitems[43] = ["43.jpg", "Bequia schooner", "Locally built schooner Friendship Rose at anchor in Admiralty Bay", null, null, false];
gitems[44] = ["44.jpg", "Bequia information", "A walk along the harbor reveals Bequia's long history of boatbuilding", "&copy; <a href=\"mailto:outhouse@caribsurf.com?subject=Photos on parkbayhouse.com\">Outhouse Graphics INC</a>", null, false];
gitems[45] = ["45.jpg", "Bequia information", "The Belmont walkway leads to several fine restaurants and bars", null, null, false];
gitems[46] = ["46.jpg", "Bequia information", "The harbor's clear water can be very inviting", null, null, false];
gitems[47] = ["47.jpg", "Bequia beaches", "Secluded Spring Bay is part of a working plantation", "&copy; <a href=\"mailto:outhouse@caribsurf.com?subject=Photos on parkbayhouse.com\">Outhouse Graphics INC</a>", null, false];
gitems[48] = ["48.jpg", "Bequia beaches", "Spring Bay's powdery sand and towering palms invite exploration", "&copy; <a href=\"mailto:outhouse@caribsurf.com?subject=Photos on parkbayhouse.com\">Outhouse Graphics INC</a>", null, false];
gitems[49] = ["49.jpg", "Bequia beaches", "Pristine Industry Bay is a misnomer, with no hard work in sight", "&copy; <a href=\"mailto:outhouse@caribsurf.com?subject=Photos on parkbayhouse.com\">Outhouse Graphics INC</a>", null, false];
gitems[50] = ["50.jpg", "Bequia beaches", "Industry is a great swimming beach with lovely views", "&copy; <a href=\"mailto:outhouse@caribsurf.com?subject=Photos on parkbayhouse.com\">Outhouse Graphics INC</a>", null, false];
gitems[51] = ["51.jpg", "Bequia beaches", "Princess Margaret (foreground) and Lower Bay are set at the foot of dramatic hills", "&copy; <a href=\"mailto:outhouse@caribsurf.com?subject=Photos on parkbayhouse.com\">Outhouse Graphics INC</a>", null, false];
gitems[52] = ["52.jpg", "Bequia beaches", "The long sweep of Lower Bay makes it easy to find a spot to yourself", "&copy; <a href=\"mailto:outhouse@caribsurf.com?subject=Photos on parkbayhouse.com\">Outhouse Graphics INC</a>", null, false];
gitems[53] = ["53.jpg", "Bequia beaches", "Lower Bay's gently sloping beach is a favorite with families", null, null, false];
gitems[54] = ["54.jpg", "Bequia beaches", "Princess Margaret (aka Tony Gibbons) Beach is a perfect stretch of white sand", "&copy; <a href=\"mailto:outhouse@caribsurf.com?subject=Photos on parkbayhouse.com\">Outhouse Graphics INC</a>", null, false];
gitems[55] = ["55.jpg", "Bequia beaches", "Coves at the south end of Princess Margaret Beach make for great snorkeling", "&copy; <a href=\"mailto:outhouse@caribsurf.com?subject=Photos on parkbayhouse.com\">Outhouse Graphics INC</a>", null, false];
gitems[56] = ["56.jpg", "Bequia beaches", "Friendship Bay is a huge arc of sand at the south of the island", null, null, false];
gitems[57] = ["57.jpg", "Bequia beaches", "The bodysurfing at Ravine Bay is well worth the short hike required to reach it", null, null, false];
gitems[58] = ["58.jpg", "Bequia beaches", "Moonhole Beach is one of Bequia's finest and most secluded beaches", null, null, false];
gitems[59] = ["59.jpg", "Bequia information", "The <a href=\"http://www.begos.com/easterregatta\" rel=\"external\">Easter Regatta</a> is lots of fun for sailors and spectators alike", "&copy; <a href=\"mailto:outhouse@caribsurf.com?subject=Photos on parkbayhouse.com\">Outhouse Graphics INC</a>", null, false];
gitems[60] = ["60.jpg", "Bequia information", "Bequia Carnival is a lively celebration in late June", "&copy; <a href=\"mailto:outhouse@caribsurf.com?subject=Photos on parkbayhouse.com\">Outhouse Graphics INC</a>", null, false];
gitems[61] = ["61.jpg", "Bequia information", "The original Moonhole house, built beneath the spectacular stone arch", null, null, false];


function GalleryItem(num, fname, shortCaption, longCaption, credit, href, newWin, cached) {
	if (num != null) {
		this.num = num;
		this.shortCaption = shortCaption;
		this.longCaption = longCaption;
		this.credit = credit == null ? "" : credit;
		if (href == null) {
			this.href = "javascript:void(0);";
			this.cursor = "default";
			this.newWin = false;
		}
		else {
			this.href = href;
			this.cursor = "pointer";
			this.newWin = newWin;
		}
		this.src = Gallery.imgPath + Gallery.imgSize + "/" + fname;
		this.loaded = cached;
		if (!cached) {
			var img = new Image();
			img.onload = function(evt) { imgOnload(num, true, evt); };
			img.onerror = img.abort = function(evt) { imgOnload(num, false, evt); };
			this.img = img;
			++Gallery.toLoad;
		}
		this.loading = false;
		this.showOnLoad = false;
		this.viewed = false;
		this.startTime = 0;
		this.endTime = 0;
	}
}

new GalleryItem();

GalleryItem.prototype.load = function(show) {
	assert(this.loaded == false, "load(" + this.num + ") called when already loaded");
	this.showOnLoad = show;
	if (!this.loading) {
		--Gallery.toLoad;
		this.loading = true;
		this.startTime = new Date().getTime();
		this.img.src = this.src;
	}
}

GalleryItem.prototype.show = function() {
	Gallery.imgCaption.innerHTML = this.longCaption;
	if (this.loaded) {
		Gallery.loadingImg.style.display = "none";
		Gallery.pageImg.src = this.src;
		Gallery.pageImg.style.display = "block";
		Gallery.imgLink.style.cursor = this.cursor;
		Gallery.imgLink.href = this.href;
		Gallery.imgLink.target = this.newWin ? "_blank" : "_self";
		Gallery.imgCredit.innerHTML = this.credit;
		Gallery.curImg = this.num;
		Util.setLinks();
		++Gallery.imgViews;
	}
	else {
		Gallery.pageImg.style.display = "none";
		Gallery.loadingImg.style.display = "block";
		this.load(true);
	}
}

function imgOnload(num, success, evt) {
	evt = getEvent(evt);
	var item = gitems[parseInt(num)];
	item.loading = false;
	item.loaded = true;
	if (item.showOnLoad) {
		item.showOnLoad = false;
		item.show();
	}
	item.endTime = new Date().getTime();
	Gallery.loadTime += item.endTime - item.startTime;
	if (!success) {
		logError("imgOnload: failed to load " + item.src + ": " + (evt == null ? "null" : evt.type));
	}
	if (Gallery.toLoad > 0) {
		loadNext();
	}
	else {
		params.replace(ParamSet.names.imgLoadTime, Gallery.loadTime, Param.SESSION);
		params.replace(ParamSet.names.imgsCached, "1", Param.SESSION);
		logInfo(ParamSet.formatParam(ParamSet.names.imgLoadTime, params.get(ParamSet.names.imgLoadTime), true));
	}
	return success ? handled(evt) : true;
}

function showImg(num) {
	//assert(num >= 0 && num <= lastImg, "showImg called with num==" + num);
	var item = gitems[num];
	item.show();
}

function showNext(forward) {
	Gallery.direction = forward ? 1 : -1;
	var next = Gallery.curImg + Gallery.direction;
	if (next > lastImg) {
		next = 0;
	}
	else if (next < 0) {
		next = lastImg;
	}
	showImg(next);
	return false;
}

function loadNext() {
	//assert(Gallery.toLoad > 0, "loadNext called with toLoad==0");
	var next = Gallery.curImg;
	var i = numImgs;
	do {
		next += Gallery.direction;
		if (next > lastImg) {
			next = 0;
		}
		else if (next < 0) {
			next = lastImg;
		}
		var item = gitems[next];
		if (!item.loaded && !item.loading) {
			window.setTimeout(function() { item.load(false); }, 10);
			break;
		}
	} while (--i > 0);

	//assert(i > 0, "loadNext called with all images loaded or loading");
}

var mainInit = init;
init = initGallery;

function initGallery() {
	mainInit();

	Gallery.pageImg = document.getElementById("pageImg");
	Gallery.imgCaption = document.getElementById("imgCaption");
	Gallery.imgLink = document.getElementById("imgLink");
	Gallery.imgCredit = document.getElementById("imgCredit");
	Gallery.loadingImg = document.getElementById("loadingImg");
	assert(Gallery.pageImg != null, "initGallery: null pageImg");

	var cached = (params.get(ParamSet.names.imgsCached) != null);
	for (var i = lastImg; i >= 0; --i) {
		var a = gitems[i];
		gitems[i] = new GalleryItem(i, a[0], a[1], a[2], a[3], a[4], a[5], cached);
	}

	Gallery.imgViews = parseInt(params.get(ParamSet.names.imgViews));
	if (isNaN(Gallery.imgViews)) {
		Gallery.imgViews = 0;
	}

	var num = params.get("img");
	if (num != null && num >= 0 && num <= lastImg) {
		showImg(parseInt(num));
	}
	atunload = Gallery.logGallery;
}
