// JavaScript Document
/* ================================================================ 
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.
=================================================================== */

run = function(mygallery, mygallery2)
	{
		clickMenu(mygallery);
		clickMenu2(mygallery2);
	}

clickMenu = function(gallery) 
	{
	var getImg = document.getElementById(gallery).getElementsByTagName("IMG");
	var getLi = document.getElementById(gallery).getElementsByTagName("LI");

	for (var i=0; i<getImg.length; i++) {
			getImg[i].onclick=function() {
			if ((this.className.indexOf('left'))!=-1) {
				for (var x=getLi.length-1; x>0; x--) {
					if ((getLi[x].className.indexOf('chosen'))!=-1)	{
						getLi[x].className=getLi[x].className.replace("chosen", "");
						x--;
						if (x>-1) {
							getLi[x].className+=" chosen";
								if (x>-1 && x<getLi.length-5){
								getLi[x].className=getLi[x].className.replace("hide", "");
									if ((getLi[x+5].className.indexOf('hide'))==-1)
									{
										getLi[x+5].className+=" hide";
									}
								}
							}
						}
					}
				}

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


		for (var i=0; i<getLi.length; i++) {
			getLi[i].onclick=function() {
				for (var x=0; x<getLi.length; x++) {
					if ((getLi[x].className.indexOf('chosen'))!=-1)	{
						getLi[x].className=getLi[x].className.replace("chosen", "");
					}
				}
			this.className+=" chosen";		
			}
		}
	}
	
	clickMenu2 = function(gallery2) 
	{
	var getImg2 = document.getElementById(gallery2).getElementsByTagName("IMG");
	var getLi2 = document.getElementById(gallery2).getElementsByTagName("LI");

	for (var i=0; i<getImg2.length; i++) {
			getImg2[i].onclick=function() {
			if ((this.className.indexOf('left'))!=-1) {
				for (var x=getLi2.length-1; x>0; x--) {
					if ((getLi2[x].className.indexOf('chosen'))!=-1)	{
						getLi2[x].className=getLi2[x].className.replace("chosen", "");
						x--;
						if (x>-1) {
							getLi2[x].className+=" chosen";
								if (x>-1 && x<getLi2.length-5){
								getLi2[x].className=getLi2[x].className.replace("hide", "");
									if ((getLi2[x+5].className.indexOf('hide'))==-1)
									{
										getLi2[x+5].className+=" hide";
									}
								}
							}
						}
					}
				}

			if ((this.className.indexOf('right'))!=-1) {
				for (var x=0; x<getLi2.length-1; x++) {
					if ((getLi2[x].className.indexOf('chosen'))!=-1)	{
						getLi2[x].className=getLi2[x].className.replace("chosen", "");
						x++;
						if (x<getLi2.length) {
							getLi2[x].className+=" chosen";
								if (x>4 && x<getLi2.length) {
								getLi2[x].className=getLi2[x].className.replace("hide", "");
									if ((getLi2[x-5].className.indexOf('hide'))==-1)
									{
										getLi2[x-5].className+=" hide";
									}
								}
							}
						}
					}
				}
			}
		}


		for (var i=0; i<getLi2.length; i++) {
			getLi2[i].onclick=function() {
				for (var x=0; x<getLi2.length; x++) {
					if ((getLi2[x].className.indexOf('chosen'))!=-1)	{
						getLi2[x].className=getLi2[x].className.replace("chosen", "");
					}
				}
			this.className+=" chosen";		
			}
		}
	}