$(document).ready(function () {
	photosArray = $(".lightbox-tour");
	photosCount = photosArray.size();	
	currentIndex = 0;
	
	//static variables
	firstPhotoIndex = 0;
	lastPhotoIndex  = photosCount-1;
	updateCaption();
//	previousPhotoIndex =  ((currentIndex > 0) && (currentIndex < photosCount)) ? (param-1) : 0;

	

	$("#largeImage").attr("src",photosArray[firstPhotoIndex].href); 
	
	$("#prev").click(function(){
		if(currentIndex==firstPhotoIndex)
		{
			currentIndex = lastPhotoIndex;
			$("#largeImage").attr("src",photosArray[currentIndex].href);
		}
		
		else// if(currentIndex <= (lastPhotoIndex))
		{
			currentIndex-=1;
			$("#largeImage").attr("src",photosArray[currentIndex].href);
			
		}
			updateCaption();
			refreshAds('Live Out Loud Gallery');
			return false;		
	});
	
	$("#next").click(function(){
		if(currentIndex < lastPhotoIndex)
		{
			currentIndex = currentIndex+1;
			$("#largeImage").attr("src",photosArray[currentIndex].href);
		}
		
		else //if(currentIndex == (lastPhotoIndex))
		{
			currentIndex=firstPhotoIndex;
			$("#largeImage").attr("src",photosArray[currentIndex].href);
		}
			updateCaption();
			refreshAds('Live Out Loud Gallery');	
			return false;	
	});
		function updateCaption()
		{	
			caption = $(photosArray[currentIndex]).attr("title");
			$("#photoCaption").html(caption);
			$("#photoIndex").html((currentIndex+1) + " of " + photosCount);
//			$(caption).appendTo(
//			alert(caption);
		}	
				function refreshAds(prop4Val)
					{

						var s=s_gi('nbcunbcuoxygenbu');
						s.linkTrackVars='prop4';
						s.linkTrackEvents='None';
						s.prop4=prop4Val; //this needs to be defined in source page
						s.t(this,'o','Live Out Loud Gallery');
					}		
});


/*	 qs = new QueryStringUtil();
	 param = qs.getValues("index") ? parseInt(qs.getValues("index")) : 0 ;

			a = $(".lightbox-tour");
			photosCount = a.length;
			firstPhoto = a[0].href;
			currentIndex = -1;
			firstPhotoIndex = 0;
			lastPhotoIndex  = photosCount-1; 
			previousPhotoIndex =  ((param > 0) && (param < photosCount)) ? (param-1) : 0;
			nextPhotoIndex	   = (param <= (photosCount - 2)) ? (param + 1) : 0;
			$("#prev").attr("href", "?index=" + previousPhotoIndex);
			$("#next").attr("href", "?index=" + nextPhotoIndex);


if (param > 0 && (param < (photosCount-1)))
{

    $("#largeImage").attr("src",a[param].href);
	currentIndex = param+1;
//    $("#largeImage").show();

}

else if ( param == 0)
{
	$("#largeImage").attr("src",firstPhoto);
	$("#prev").attr("href","?index=" +lastPhotoIndex);
	currentIndex = 1;
} 			
else
{
// 	alert('test');
    $("#largeImage").attr("src",firstPhoto);
	$("#prev").attr("href","?index=" +lastPhotoIndex);
	$("#next").attr("href","?index=" +(firstPhotoIndex+1));
	currentIndex = 1;
}

indexText = "Image " + currentIndex + " of " + a.length;
document.getElementById("photoIndex").innerHTML = indexText; */