var curImage = 0;
var aPos = 0;
var imageList = 0;

function swapPictureGallery() {	
	new Ajax.Request('../imageRotator_new.asp?idnum='+curImage, {
	  method:'get',
	  onSuccess: function(transport){
		 var json = transport.responseText.evalJSON();
		 aPos = aPos + 1;
		 if (aPos > imageList.size()) {
			aPos = 0;
		 }
		 curImage = imageList[aPos];
		 
		 new Effect.Fade( $('spotlightpic'), 
			 { duration: 0.5, from: 1, to: 0, afterFinish: function() {
					$('spotlightpic').style.backgroundImage="url(../uploads/" + json.spotlightImage + ")";
					
					new Effect.Appear( $('spotlightpic'), { duration: 0.5, from:0, to: 1 } );
				}
		 })	 
		 
		 new Effect.Fade( $('spotlighttext'), 
			 { duration: 0.5, from: 1, to: 0, afterFinish: function() {
					$('spotlighttext').innerHTML = "<span class=spotlightproj>" + json.spotlightproj + "</span><br><b>" + json.location + "</b><br><br>" + json.description + " <a href=\"index.asp?pageid=" + json.pageid + "\">(jump to portfolio)</a>";
					
					new Effect.Appear( $('spotlighttext'), { duration: 0.5, from:0, to: 1 } );
				}
		 })	 
		 
		 new Effect.Fade( $('spotlightlink'), 
			 { duration: 0.5, from: 1, to: 0, afterFinish: function() {
					$('spotlightlink').innerHTML = "<a href=\"index.asp?pageid=" + json.pageid + "\"><img src=\"images/spotlightclick_a.png\" alt=\"Click here to learn more.\" width=408 height=63 border=0 /></a>"
					
					new Effect.Appear( $('spotlightlink'), { duration: 0.5, from:0, to: 1 } );
				}
		 })
	   }
	});
}

function startGalleryFader(iniPhoto, intDur) {
	curImage = iniPhoto;

	new Ajax.Request('../imageList.asp', {
	  method:'get',
	  onSuccess: function(transport){
		var imageListRaw = transport.responseText.evalJSON();
		var imageListBase = imageListRaw.pagelist.split(",");
		
		imageList = imageListBase.without(curImage);
		imageList.push()
		var q = imageList.size()
		imageList[q] = curImage
		
		if (curImage == imageList[0]) {
			curImage = imageList[1];
			aPos = 1;
		} else {
			curImage = imageList[0];
			aPos = 0;
		}
		
		setInterval('swapPictureGallery()',intDur);
	   }
	});
}
