//declare global variables
var thumbNumRight
var thumbNumLeft
var archiveNum = 1;
var picture = "images/magnets/small_magnet/small_magnet";
var thumb = "images/magnets/thumbnails/thumb_magnet"

var pictureLarge = "images/magnets/magnet";

function archiveBack() {
  if (archiveNum <= 1) {
	    archiveNum = 6
			thumbNumRight = archiveNum-5
			thumbNumLeft = 5
	  } else if (archiveNum == 2) {
		  archiveNum = 1
			thumbNumRight = 2
			thumbNumLeft = 6
		} else {
	  archiveNum--
		thumbNumRight = archiveNum+1
		thumbNumLeft = archiveNum-1
		}
		document.getElementById('archiveCount').childNodes[0].nodeValue=archiveNum + "/6";
		document.image.src = picture + archiveNum + ".jpg";
		document.next.src = thumb + thumbNumRight + ".jpg";
		document.back.src = thumb + thumbNumLeft + ".jpg";
		
		getImageWidth = document.image.width;
		marginSize = (440-getImageWidth)/2;
		
		imageText();
	}
									
	function archiveNext() {
	  if (archiveNum >= 6) {
			archiveNum = 1
			thumbNumRight = archiveNum+1
			thumbNumLeft = 6
			} else {
			archiveNum++
			thumbNumRight = archiveNum+1
			thumbNumLeft = archiveNum-1
			}
			document.getElementById('archiveCount').childNodes[0].nodeValue=archiveNum + "/6";
			document.image.src = picture + archiveNum + ".jpg";			
			document.next.src = thumb + thumbNumRight + ".jpg";
			document.back.src = thumb + thumbNumLeft + ".jpg";
    
		  getImageWidth = document.image.width;
			marginSize = (440-getImageWidth)/2;
			
			imageText();
		
}
	
function imageWindow() { // Function to create a new popup window.
			var imageLarge = pictureLarge + archiveNum + ".jpg";
			// Create and open new window
			var newWindow = window.open("", "Large_Image", 'width=900,height=700,left=0,top=0,scrollbars=1') 
			// Set openWindow variable and write HTML elements.
			var openWindow = newWindow.document;
			openWindow.write('<html><head><title>Large Archive Image</title>');
			openWindow.write('<style type="text/css">body{background:black;} a{color:white;text-decoration:none;font-size:1.3em;}</style>');

			openWindow.write('</head><body><p align="center">');
			openWindow.write('<img src="' + imageLarge + '" alt="Large Archive Image" title="Large Archive Image" \/></p>');
			openWindow.write('<p align="center"><a href="javascript:self.close()">Close Window</a></p>');
			openWindow.write('</body></html>');
			openWindow.close();  
			
} // End of imageWindow function.

// Picture description.

// JON READ BELOW 
// Each case number coincides with the image number in the gallery
// Just chnage the text for the variable descrip.
 
function imageText()
				 {
				 var descrip = archiveNum;
				 switch(descrip)
				 {
				 	case 1:
  				descrip = "Look - Magnetic wood!";
  				break;
					
					case 2:
  				descrip = "The front - click photo to enlarge";
  				break;
					
					case 3:
  				descrip = "The back - click photo to enlarge";
  				break;
					
					case 4:
  				descrip = "The point - click photo to enlarge";
  				break;
					
					case 5:
  				descrip = "Also available in natural wood (here cork oak)";
  				break;
					
					case 6:
  				descrip = "Limited edition 'Africa'";
  				break;
					
					case 7:
  				descrip = "click photo to enlarge";
  				break;
					
					default:
  				descrip = "Default"
				}

				document.getElementById('description').childNodes[0].nodeValue=descrip

}
