/* ================================================================ 
This copyright notice must be untouched at all times.

The original version of this script and the associated (x)html
is available at http://www.stunicholls/gallery/left_right_click.html
Copyright (c) 2005-2007 Stu Nicholls. All rights reserved.
This script and the associated (x)html may be modified in any 
way to fit your requirements.
=================================================================== */

/* ====
Adapted LH 10/02/08
===*/

chooseimage = function(filename) {
	newImg=document.createElement('img');	
	newImg.setAttribute('src',filename);
	disp_img = document.getElementById('display_image');
	disp_img.replaceChild(newImg,disp_img.firstChild);
}


hideimage = function(hideme, showme) {
	showme.className=showme.className.replace("hide", "");
	if ((hideme.className.indexOf('hide'))==-1) {
		hideme.className+=" hide";
	}
}		
		

clickMenu = function(image_scroll, number_images) 
	{
	var getImg = document.getElementById(image_scroll).getElementsByTagName("IMG");
	var getLi = document.getElementById(image_scroll).getElementsByTagName("LI");
			
	chooseimage(getImg[1].src);
	
	for (var i=0; i<getImg.length; i++) {
			getImg[i].onclick=function() {
			if ((this.className.indexOf('left'))!=-1) {
				for (var x=(getImg.length-2); x>1; x--) {
					if ((getLi[x-1].className.indexOf('chosen'))!=-1)	{
						getLi[x-1].className=getLi[x-1].className.replace("chosen", "");
						x--;
						if (x>0) {
							getLi[x-1].className+=" chosen";

							chooseimage(getImg[x].src);
							
								if (x>0 && (x-1)<(getImg.length-number_images)){
								getLi[x-1].className=getLi[x-1].className.replace("hide", "");
									if ((getLi[x-1+number_images].className.indexOf('hide'))==-1)
									{
										getLi[x-1+number_images].className+=" hide";
									}
								}
							}
						}
					}
				}

			if ((this.className.indexOf('right'))!=-1) {
				for (var x=1; x<getImg.length-2; x++) {
					if ((getLi[x-1].className.indexOf('chosen'))!=-1)	{
						getLi[x-1].className=getLi[x-1].className.replace("chosen", "");
						x++;
						if (x<(getImg.length-1)) {
							getLi[x-1].className+=" chosen";

							chooseimage(getImg[x].src);
							
								if (x-1>(number_images-1) && x-1<(getImg.length)) {
								getLi[x-1].className=getLi[x-1].className.replace("hide", "");
									if ((getLi[x-1-number_images].className.indexOf('hide'))==-1)
									{
										getLi[x-1-number_images].className+=" hide";
									}
								}
							}
						}
					}
				}
			
			if ((this.className.indexOf('right') == -1) && (this.className.indexOf('left') == -1)) {
				for (var x=1; x<getImg.length-1; x++) {
					if ((getLi[x-1].className.indexOf('chosen'))!=-1)	{
						getLi[x-1].className=getLi[x-1].className.replace("chosen", "");

					}
					if (getImg[x].src == this.src) {
						getLi[x-1].className+=" chosen";
					}
				}
				

				chooseimage(this.src);
						
			}
		}

	}
	}
