//define vars to send to files that will do queries
var image_number;
var total_images;
var group_type;

//each of these three functions acts as a trigger to set vars and fire off ajax requests
function setTotal(passed_total, passed_group) {//choose (image_number_passed) and load up first image on page load
	total_images = passed_total;
	group_type = passed_group;
	show_hide('next', 1)
}

function loadFirst() {
	image_number = 1;
	sndReq();
}

function trgrNext() {//get next image and meta
	if (!(image_number == total_images)) {
		++image_number;
		sndReq();
	}
}

function trgrPrev() {//get previous image and meta
	if (!(image_number == 1)) { 
		--image_number;
		sndReq();
	}
}

/*the next functions are pairs of request and response objects.  if necessary multiple ajax requests can be made;
since making simultaneous requests throws errors, each response function fires off the next request when 
it is done with it's request, thus daisy-chaining the functions.*/
function sndReq() {
	//request the image and meta and handle navigation display
	//hide/show appropriate next, back buttons
	if (image_number == 1) {
		show_hide('previous', 0);		
	}
	else {
		show_hide('previous', 1);
	}
	if (image_number == total_images) {
   		show_hide('next', 0);
	}
	else {
		show_hide('next', 1);

	}
	//retrieve the image and meta
	requester.open('get', 'http://blantonmuseum.org/images/image_slideshow_process.cfm?image_number=' + image_number + '&group_type=' + group_type, true);
    requester.onreadystatechange = handleResponse;
	requester.send(null);
}

function handleResponse() {//place image and meta onto the page
	if(requester.readyState == 4){
		var response = requester.responseText;
		document.getElementById('image_slideshow').innerHTML = response;
		/*the next request function could be fired off here... this prevents http errors caused by simultaneous 
		ajax requests*/
    }
}

// example of the next trigger function pair...
/*
function sndReq2() {//request the meta
	requester.open('get', 'path to processing page');
    requester.onreadystatechange = handleResponse2;
	requester.send(null);
}

function handleResponse2() {//place meta onto the page
    if(requester.readyState == 4){
		var response = requester.responseText;
		document.getElementById('target div id').innerHTML = response;
    }
}
*/