// JavaScript Document


var photos = new Array();

// var windowWidth = 630, windowHeight = 460;

function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
	offset = document.cookie.indexOf(search);
	if (offset != -1)
	{ 
	  offset += search.length;
	  end = document.cookie.indexOf(";", offset);
	  if (end == -1) end = document.cookie.length;
	  cookieValue = unescape(document.cookie.substring(offset, end))
	}
  }
  return cookieValue;
}

// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
	expire = new Date((new Date()).getTime() + hours * 3600000);
	expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}

function show(item) {
	//alert("show(" + item + ")");
	if (!document.getElementById) return;
	//alert("show " + document.getElementById("hits"));
	document.getElementById(item).style.display = "block";
}

function hide(item) {
	//alert("hide(" + item + ")");
	//if (!document.getElementById()) return;
	document.getElementById(item).style.display = "none";
}

function setValue(field) {
	//alert("setValue(" + field + ")");
	var hitCount = readCookie("hitCount");
	if (hitCount == null  || hitCount == "") {
		hitCount = 0;
	} else {
		hitCount++;
	}
	writeCookie("hitCount", hitCount, 7760); // cookie to expire one year from now
	document.getElementById(field).value = hitCount;
	return hitCount;
}

function getNextImageNumber() {
	// alert("getNextImageNumber");
	var imageCount = readCookie("imageCount");
	if (imageCount == null  || imageCount == "") {
		imageCount = 0;
	} else {
		imageCount++;
	}
	// alert("getNextImageNumber: imageCount = " + imageCount + " photos.length = " + photos.length);
	if (imageCount >= photos.length) {
		// alert("getNextImageNumber: resetting imageCount to 0");
		imageCount = 0;
	}
	writeCookie("imageCount", imageCount, 8);
	// alert("getNextImageNumber: " + imageCount);
	return imageCount;
}


function MM_preloadImages() { //v3.0
	var d = document;
	if(document.images){
	if(! document.MM_p) document.MM_p = new Array();
		var i, j = document.MM_p.length, a = MM_preloadImages.arguments[0];
		for(i = 0; i <a.length; i++) {
			if (a[i].indexOf("#") != 0) {
				// alert("j = " + j + " a[" + i + "] = " + a[i]);
				document.MM_p[j] = new Image;
				document.MM_p[j++].src = a[i];
			}
		}
		photos = document.MM_p;
	}
}


function getBackgroundImage() {
	// alert("getBackgroundImage");
	// for (i = 0; i < photos.length; i++) {
		// alert("photos[" + i + "] = " + photos[i].src);
	// }
	return photos[getNextImageNumber()].src;
}

