// JavaScript Document


function changeThumb(iTmbNumber, oLink) {

	// get the thumb enlarge link
	oTmbEnlargeLink = document.getElementById('tmbEnlargeLink');
	
	// get to the thumb image
	oTmbImage = document.getElementById('tmbImage');
	
	// work out the source
	sSource = oTmbImage.src;
	aSourceParts = sSource.split("/");
	sFullFileName = aSourceParts[aSourceParts.length-1]; // Last element
	aFileNameParts = sFullFileName.split(".");
	sFileName = aFileNameParts[0]; // First element

	// get the image number by spliting and getting the last element
	aImageNameParts = sFileName.split("_");
	sImageID = aImageNameParts[aImageNameParts.length-1]; // Last element	

	// padd the new images number to two digits	
	sNewImageID  = numberPad(iTmbNumber,2);

	// swap the image numbers in the source
	sNewFileName = sFileName.replace(sImageID, sNewImageID);
	// swap the file names in the source
	sNewSource = sSource.replace(sFileName, sNewFileName);
	// swap tmb for lge for the pop up link	
//	sNewSourceForEnlarge = sNewSource.replace('tmb', 'lge');	
	sNewSourceForEnlarge = 'Javascript:makeBoxFor(' + sNewImageID + ');';	

	// change the href of the pop up link
	oTmbEnlargeLink.href = sNewSourceForEnlarge;
	// swap the source of the thumb
	oTmbImage.src = sNewSource;
	
	// get all the navigation links	
	oTmbNavLinks = document.getElementById('tmbLinkList');	
	// turn them all to off
	aObjs = oTmbNavLinks.getElementsByTagName('a');
	for(i=0;i<aObjs.length;i++){
		aObjs[i].className = 'tmbLinkOff';			
	}
	// switch the correct one 'on'
	oLink.className = 'tmbLinkOn';
}

function numberPad(iNumber, iLength){  
	sPadded = iNumber.toString();
	while(iLength > sPadded.length) { 
	  sPadded = '0' + sPadded; 
	} 
	return sPadded; 
} 

function makeBoxFor(iImageNumber) {
	sLinkID = 'link' + iImageNumber;
	myVar = document.getElementById(sLinkID);		
	myLightbox.start(myVar);
}


