var nextAddress;
var prevAddress;
var currentAddress;

function getDiptych (numberOfDiptychs, URL) {
	
	var next;
	var prev;
	var current;
	var address;
	var diptych;
	
	var query = /\d{1,}/;					
	var result = query.exec(URL);
	
	if (result) {
		diptych = result;
	} else {
		diptych = Math.floor(Math.random() * numberOfDiptychs) + 1;
	}
	
	if (diptych < numberOfDiptychs) {
		next = diptych + 1; 
	} else {
		next = 1;
	}
	
	if (diptych > 1) {
		prev = diptych - 1; 
	} else {
		prev = numberOfDiptychs;
	}
	
	currentAddress = "portraits/" + diptych.toString() + ".html";
	nextAddress = "portraits/" + next.toString() + ".html";
	prevAddress = "portraits/" + prev.toString() + ".html";
	
	address = "portraits/diptychs/" + diptych.toString() + ".jpg";
	(img = document.getElementById('leader')).src = address;

}

function currentPage() {
	document.location.href = currentAddress;
}

function nextPage() {
	document.location.href = nextAddress;
}

function prevPage() {
	document.location.href = prevAddress;
}
