function changeIt(imagefolder, filename)
{
   document.images.display.src=imagefolder+filename+".jpg";
}


function displaygallery (imagefolder, currentpage, totalimages)
{
    
    if (currentpage==0)
	{
	    //contructor - write the divs to initialise gallery and displays 1.jpg
		
		document.write('<div id="box"><div id="displaydiv"> <img src="');
		document.write(imagefolder);
		document.write('1.jpg"  id="display" /> </div>');
        document.write('<div id="thumbs"></div>');
        document.write('</div>');
	    currentpage=1;
	}


	//alert("being called: " + currentpage);
	var startfromimage = (currentpage*8)-7;
	var theresmorepages = false;
	var output ="";
		
	for (i=startfromimage; ; i++)   
	{
		if(i>totalimages)
		{
			break;
		}
		if(i>(startfromimage+7))
		{
			theresmorepages = true;
			break;
		}
	   //document.write(i+".jpg</br>");
	
		var thumbnail = '<a href="javascript:changeIt(\'';
		thumbnail += imagefolder;
		thumbnail += '\',';
		thumbnail += i;
		thumbnail += ')"><img src="';
		thumbnail += imagefolder+i;
		thumbnail += '.jpg" width="70" height="70" alt="';
		thumbnail += i;
		thumbnail += '.jpg"></a> ';
		
		output += thumbnail;
	}
	
	output += "<br/><br/>";
	
	if(currentpage!=1)
	{
		//output += "previous <br/>";
						
		//var previous = '<a href="" onclick="displaygallery(\'';
		var previous = '<a href="javascript:displaygallery(\'';
		previous += imagefolder;	
		previous += '\',';
		previous += currentpage-1;
		previous += ',';
		previous += totalimages;
		previous += ' )">previous</a>';
		
		output += previous;
		
	}
	
	if(theresmorepages)
	{		
		var next = ' <a href="javascript:displaygallery(\'';
		next += imagefolder;	
		next += '\',';
		next += currentpage+1;
		next += ',';
		next += totalimages;
		next += ' )">next</a>';
				
		output += next;
		
	}
	
	//alert("output:"+output);
	document.getElementById("thumbs").innerHTML = output;
}



