// Generates random number for photo and caption


//set this to the number of photos you have
var $howManyPhotos = 16;

// Generates random number for photo and caption
var random_number;
function ranGen(){
	random_number = (Math.floor((Math.random()*($howManyPhotos-1))+1));	
}

function setCookie(){
  var nextWeek = new Date();
  nextWeek.setDate(nextWeek.getDate()+7);
  var allCookies = document.cookie;
  var pos = allCookies.indexOf("ccount=");
  if(pos == -1) {
	  ranGen();	  
	  document.cookie = "ccount=" + random_number + "; max-age=" + (60*60*24*7) + "; expires:="+ nextWeek.toGMTString(); 
	  return;
  }  
  var start = pos+7;
  var end = allCookies.indexOf(";", start);
  if(end == -1) end = allCookies.length;  
  var value = allCookies.substring(start, end);    
  if(value == $howManyPhotos) value = 0;
  random_number = ++value;
  document.cookie  = "ccount=" + random_number + "; max-age=" + (60*60*24*7) + "; expires:="+ nextWeek.toGMTString();  
}
setCookie();

function setPhotoCaption(){
	var photoCapList = [];
	for(var i = 0; i <= $howManyPhotos; i++) {
	  photoCapList[i] = document.getElementById('photoCutline' + i);
	}
	photoCapList[random_number].style.display = "block";

}//end of setPhotoCaption

//window.onload = function() {
//	setPhotoAndCaption();
//	clearDefault();
//}

//this replaces 'window.onload' above
addLoadEvent(setPhotoCaption);
addLoadEvent(clearDefault);