// JavaScript Document
// define the necessary variables below
/*var imgPath = '../gallery/';
var theList = new Array('Accomodations1.jpg','Accomodations2.jpg','Accomodations3.jpg','Accomodations4.jpg','Accomodations5.jpg','Accomodations6.jpg','Accomodations7.jpg','Accomodations8.jpg','Accomodations9.jpg','GuestServ1.jpg','GuestServ2.jpg','GuestServ3.jpg','GuestServ4.jpg','GuestServ5.jpg','GuestServ6.jpg','GuestServ7.jpg','GuestServ8.jpg','GuestServ9.jpg','Meetings1.jpg','Meetings2.jpg','Meetings3.jpg','Meetings4.jpg','Meetings5.jpg','Meetings6.jpg','Meetings7.jpg','Meetings8.jpg','Meetings9.jpg');
*/
//**********************************************************

// define the necessary variables below
var imgPath = '../../../images/gallery/colombia/cartagena/';
var theList = new Array('1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg');
var theCaptions = new Array('Royal decameron Panama, Aereal picture of our beach, swimming pool and restaurant area','cap2','cap3','cap4','cap5','cap6','cap7','cap8')

// the code below here does not need to be altered

function showPrev () {
	master('source',theList,2);
}

function showNext () {
	master('source',theList);
}

// imgName is the name specified in the img tag... should be in quotes
// imgArray is the variable that is the array of images to rotate through... should not be in quotes
// dir tells whether to move forward or back; 1=forward; 2=back; default=1
function master (imgName, imgArray, dir) {
	// set dir to default of 1 if no parameter passed
	if (dir==null)
		dir = 1;
	// figure out which image is currently being shown
	var currentImg = document[imgName].src;
	var currentImgSplit = currentImg.split('/');
	for (x=0; x<currentImgSplit.length; x++) {
		currentImg = currentImgSplit[x];
	}
	// figure out where this image is in the array
	var currentIndex;
	for (x=0; x<imgArray.length; x++) {
		if (currentImg==imgArray[x])
			currentIndex = x;
	}
	// get the appropriate index depending on direction and array length
	var newIndex;
	if (dir==1) {
		if (currentIndex<imgArray.length-1)
			newIndex = currentIndex+1;
		else
			newIndex = 0;
	} else {
		if (currentIndex==0)
			newIndex = imgArray.length-1;
		else
			newIndex = currentIndex-1;
	}
	// display the image
	document[imgName].src = imgPath+imgArray[newIndex];
	document.getElementById("captionblock").innerHTML = theCaptions[newIndex];
}

// figures out the variable being passed from thumbnail page to full size page
// slightly modified from code here: http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
var strParamName = 'photo';
var strReturn;
var strHref = window.location.href;
if (strHref.indexOf('?') > -1) {
	var strQueryString = strHref.substr(strHref.indexOf('?'));
	var aQueryString = strQueryString.split('&');
	for (var iParam=0; iParam < aQueryString.length; iParam++) {
		if (aQueryString[iParam].indexOf(strParamName + '=') > -1) {
			var aParam = aQueryString[iParam].split('=');
			strReturn = aParam[1];
		}
	}
}
// shows first image and caption in array as default if no variable is passed or image passed is not in array
var passImg = theList[0];
var passCap = theCaptions[0];
if (strReturn!=null) {
	for (x=0; x<theList.length; x++) {
		if (theList[x] == strReturn) {
			passImg = theList[x];
			passCap = theCaptions[x];
		}
	}
}
passImg = imgPath+passImg;

function go (url) {
	opener.location = url;
	window.close();
}
