var bigPic = new Array();
var slideNum = new Array();
var waiting = new Array();
var slideCount = new Array();

function init(slidename,grpvalue) {
	SlideShowName = slidename;
	SlideShowGroup = grpvalue;
}
// Checks browser for document.images functionality

// Load Images
function loadPics(images) {
	if (document.images) {
		// checks for Netscape on Macs. If showNav is untrue (-1) it doesn't display the link navigation.
		// Changing the default value to -1 will remove the number navigation from all browsers.
		showNav = "on";
		
		if (navigator.appVersion.indexOf("Macintosh") != -1) { 
			if (navigator.appName.indexOf("Netscape") != -1) {
				showNav = "off";
			}
		}
		
		// if you're not using a Mac with Netscape then display the PREVIOUS link
		if (showNav == "on") {
			document.write("<A HREF='#" + SlideShowName + "' onClick=\"slideIt('" + SlideShowName + "'," + SlideShowGroup + ",2)\"><B>&lt;&lt;</B></a>&nbsp;&nbsp;&nbsp;&nbsp;");
		}

  for (i=0; i<arguments.length; i++){
			// the i+1 offsets the first zero value to the image array
			bigPic[i+1+SlideShowGroup] = new Image();
			bigPic[i+1+SlideShowGroup].src = "photos/proximite/" + arguments[i];
			
			// if you're not using a Mac with Netscape then display the number links
			if (showNav == "on") {
				document.write("<A HREF='#" + SlideShowName + "' onClick=\"changeIt('" + SlideShowName + "'," + SlideShowGroup + "," + (i+1) + ")\">" + (i+1) + "</a>&nbsp;&nbsp;");
			}
		}
		// if you're not using a Mac with Netscape then display the Next link
		if (showNav == "on") {	
			document.write("&nbsp;&nbsp;&nbsp;<A HREF='#" + SlideShowName + "' onClick=\"slideIt('" + SlideShowName + "'," + SlideShowGroup + ",1)\"><B>&gt;&gt;</B></a>&nbsp;");
		}
		
	slideCount[SlideShowGroup] = (bigPic.length - 1 - SlideShowGroup);
	slideNum[SlideShowGroup] = 0;
	// Start the slideshow

	slideIt(SlideShowName,SlideShowGroup,1);
	} else {
		document.write("Sorry! your browser will not enable you to view the slideshow");
	}
}

// Slideshow sequence function
function slideIt(slideShowDestination,slideShowGrp,direction) {
	// direction 1 or 2. 2 is previous and 1 is next.
	if (direction == 1) {
		slideNum[slideShowGrp] = slideNum[slideShowGrp] + 1
	} else {
		slideNum[slideShowGrp] = slideNum[slideShowGrp] - 1
	}
	
	// if you've come to the end of the list, loop from begining again.
	if (slideNum[slideShowGrp] > slideCount[slideShowGrp]) {
		slideNum[slideShowGrp] = 1;
		changeIt(slideShowDestination,slideShowGrp,slideNum[slideShowGrp]);
	}
	// if you're clicking previous and come to the first, loop round to the last image.
	if (slideNum[slideShowGrp] < 1) {
		slideNum[slideShowGrp] =  slideCount[slideShowGrp];
		changeIt(slideShowDestination,slideShowGrp,slideNum[slideShowGrp]);
	}
	changeIt(slideShowDestination,slideShowGrp,slideNum[slideShowGrp]);
}
	
// Change the image

function changeIt(slideShowDestination,slideShowGrp,imgnum) {
	// the "waiting" Timout is the pause between pictures. When the image changes the previous Timeout must be cancelled
	clearTimeout(waiting[slideShowGrp]);
	slideNum[slideShowGrp] = imgnum;
	//alert(slideNum[slideShowGrp]);
	// change the image and re-set the Timout
	document[slideShowDestination].src = bigPic[imgnum+slideShowGrp].src;
	waiting[slideShowGrp] = setTimeout("slideIt('" + slideShowDestination + "'," + slideShowGrp + ",1)", 5000);
}