// JavaScript Document
// Next-Previous Image Gallery 2 :: Solomon :: http://www.sleuthz.com/
// Create an Array of Image Locations
// altered to randomly load an image and description from the arrays
var myImg= new Array()
	myImg[0]= "st-johns-wood-apartments/images/1.jpg";
	myImg[1]= "geneva-house/images/1.jpg";
	myImg[2]= "advanced-dental-clinic/images/1.jpg";
	myImg[3]= "hampstead-apartment/images/1.jpg";
	myImg[4]= "maplehouse-orthodontics/images/3.jpg";
	myImg[5]= "antibes-house/images/1.jpg";
// Create an Array of Captions
var myCap= new Array()
	myCap[0]= "<h2>RIBA Award 2004</h2><p>Advance Dental Clinic, Chelmsford</p><h2>Royal Academy Summer Exhibition 2009</h2><p>Model for new St Johns Wood apartments accepted for the summer show</p><h2>Dental Practice WOW! Awards 2008-09</h2><p>Green Room Dental, Newquay overall winner</p><h2>Private Dentistry Awards: Best New Practice</h2><p>Pentangle Clinic, Newbury 2007<br/>Advance Dental Clinic, Chelmsford 2005</p>";
	myCap[1]= "<h2>RIBA Award 2004</h2><p>Advance Dental Clinic, Chelmsford</p><h2>Royal Academy Summer Exhibition 2009</h2><p>Model for new St Johns Wood apartments accepted for the summer show</p><h2>Dental Practice WOW! Awards 2008-09</h2><p>Green Room Dental, Newquay overall winner</p><h2>Private Dentistry Awards: Best New Practice</h2><p>Pentangle Clinic, Newbury 2007<br/>Advance Dental Clinic, Chelmsford 2005</p>";
	myCap[2]= "<h2>RIBA Award 2004</h2><p>Advance Dental Clinic, Chelmsford</p><h2>Royal Academy Summer Exhibition 2009</h2><p>Model for new St Johns Wood apartments accepted for the summer show</p><h2>Dental Practice WOW! Awards 2008-09</h2><p>Green Room Dental, Newquay overall winner</p><h2>Private Dentistry Awards: Best New Practice</h2><p>Pentangle Clinic, Newbury 2007<br/>Advance Dental Clinic, Chelmsford 2005</p>";
	myCap[3]= "<h2>RIBA Award 2004</h2><p>Advance Dental Clinic, Chelmsford</p><h2>Royal Academy Summer Exhibition 2009</h2><p>Model for new St Johns Wood apartments accepted for the summer show</p><h2>Dental Practice WOW! Awards 2008-09</h2><p>Green Room Dental, Newquay overall winner</p><h2>Private Dentistry Awards: Best New Practice</h2><p>Pentangle Clinic, Newbury 2007<br/>Advance Dental Clinic, Chelmsford 2005</p>";
	myCap[4]= "<h2>RIBA Award 2004</h2><p>Advance Dental Clinic, Chelmsford</p><h2>Royal Academy Summer Exhibition 2009</h2><p>Model for new St Johns Wood apartments accepted for the summer show</p><h2>Dental Practice WOW! Awards 2008-09</h2><p>Green Room Dental, Newquay overall winner</p><h2>Private Dentistry Awards: Best New Practice</h2><p>Pentangle Clinic, Newbury 2007<br/>Advance Dental Clinic, Chelmsford 2005</p>";
	myCap[5]= "<h2>RIBA Award 2004</h2><p>Advance Dental Clinic, Chelmsford</p><h2>Royal Academy Summer Exhibition 2009</h2><p>Model for new St Johns Wood apartments accepted for the summer show</p><h2>Dental Practice WOW! Awards 2008-09</h2><p>Green Room Dental, Newquay overall winner</p><h2>Private Dentistry Awards: Best New Practice</h2><p>Pentangle Clinic, Newbury 2007<br/>Advance Dental Clinic, Chelmsford 2005</p>";
	
// Create Number of Images Variable
var n = myImg.length;

// Create Number Variable
var i = Math.round(Math.random()*(n-1));

// Create Image Number Variable
var m = 1;


// Create Function to Load Image
function loadImg(){
// Gives "imgSrc" a Source with Number Variable
	document.imgSrc.src = myImg[i];
// Gives "caption" DIV a content
	document.getElementById("caption").innerHTML = myCap[i];
// Gives "imgNum" DIV the image number
	document.getElementById("imgNum").innerHTML = "Image&nbsp;" + m + "/" + n ;
}

// Create Link Function to Switch Image Backward
function prev(){
// Create If/Else Statement to Stop at Certain Image
// If the Number Variable is Less Than 1
	if(i<1){
// Create Another Next Number Variable which Equals to Number Variable
		var l = i = n-1;
// Create Current Number Variable which Equals to Image Number Variable
		var c = m = n;
// Otherwise
	}else{
// Next Number Variable Equals to Number Variable - 1
		var l = i-=1;
// Current Number Variable Equals to Image Number Variable - 1
		var c = m-=1;
	}
// Gives "imgSrc" a Source with an Alternative "l" Variable
	document.imgSrc.src = myImg[l];
// Gives "caption" DIV a content
	document.getElementById("caption").innerHTML = myCap[i];
// Gives "imgNum" DIV the image number
	document.getElementById("imgNum").innerHTML =  "Image&nbsp;" + c + "/" + n;
}

// Create Link Function to Switch Image Forward
function next(){
// Create If/Else Statement to Stop at Certain Image
// If the Number Variable is More Than [Minus 1 of the Number of Arrays]
	if(i>n-2){
// Create Next Number Variable which Equals to Number Variable
		var l = i = 0;
// Create Current Number Variable which Equals to Image Number Variable
		var c = m = 1;
// Otherwise
	}else{
// Next Number Variable Equals to Number Variable + 1
		var l = i+=1;
// Current Number Variable Equals to Image Number Variable + 1
		var c = m+=1;
	}
// Gives "imgSrc" a Source with Next Number Variable
	document.imgSrc.src = myImg[l];
// Gives "caption" DIV a content
	document.getElementById("caption").innerHTML = myCap[i];
// Gives "imgNum" DIV the image number
	document.getElementById("imgNum").innerHTML =  "Image&nbsp;" +  m + "/" + n;
}

// Load function after page loads
window.onload = loadImg;