// JavaScript Document

$(document).ready(function(){
	divList=document.getElementsByTagName("div");
	for (var w=0;w<divList.length;w++)
	{
		divID = divList[w].id;
		if(divID.indexOf("_GALLERY") > 0){
			// get images, links and captions in div
			divArray = divList[w].title;
			count = 0;
			var mygallery = new Array();
			var currentArr=new Array();
			while (divArray.substring(0, divArray.length) != "") {
				if (divArray.substring(0, divArray.indexOf(";")) != "") {
					currPiece = divArray.substring(0, divArray.indexOf(";"));
					currImg = currPiece.substring(0, currPiece.indexOf("^"));
					currCaption = currPiece.substring((currPiece.indexOf("^")+1), currPiece.length);
					divArray = divArray.substring((divArray.indexOf(";")+1), divArray.length);
					currentArr[count] = new Array("../"+currImg+".gif", "../"+currImg+".jpg", "_blank", currCaption);
				}
				else {
					currPiece = divArray.substring(0, divArray.length);
					currImg = currPiece.substring(0, currPiece.indexOf("^"));
					currCaption = currPiece.substring((currPiece.indexOf("^")+1), currPiece.length);
					divArray = "";
					currentArr[count] = new Array("../"+currImg+".gif", "../"+currImg+".jpg", "_blank", currCaption);
				}
				count += 1;
			}
			//alert(currentArr);
			mygallery[w]=new simpleGallery({
				wrapperid: divID, //ID of main gallery container,
				dimensions: [250, 250], //width/height of gallery in pixels. Should reflect dimensions of the images exactly
				imagearray: currentArr,
				autoplay: [false, 2500, 2], //[auto_play_boolean, delay_btw_slide_millisec, cycles_before_stopping_int]
				persist: false, //remember last viewed slide and recall within same session?
				fadeduration: 500, //transition duration (milliseconds)
				oninit:function(){ //event that fires when gallery has initialized/ ready to run
					//Keyword "this": references current gallery instance (ie: try this.navigate("play/pause"))
				},
				onslide:function(curslide, i){ //event that fires after each slide is shown
					//Keyword "this": references current gallery instance
					//curslide: returns DOM reference to current slide's DIV (ie: try alert(curslide.innerHTML)
					//i: integer reflecting current image within collection being shown (0=1st image, 1=2nd etc)
				}
			})
		}
	} 
});