/* McCOLIN DOT COM
 * Javascript for Front Door
 * Sep 2010
 */

/* Generic page loader accepts an array of load-time functions to invoke */
function loadPage(fns) {
	if(fns != null && fns != undefined)
		for (var i=0; i < fns.length; i++)
			fns[i]();
}


/* Move the images in the image list around randomly */
function randomizeImages() {
  var photoList = document.getElementById("photolist");
  var photos = photoList.children;
  for (var i=0; i < photos.length-1; i++) {
    var photoA = photos[i];
    var photoB = photos[i+1];
    if (Math.floor(Math.random()*2) == 1) {
      var tmpPhoto = photoA.cloneNode(1);
      photoList.replaceChild(tmpPhoto, photoB);
      photoList.replaceChild(photoB, photoA);
      photoList.replaceChild(photoA, tmpPhoto);
      tmpPhoto = null;
    }
  }
}

/* Determine my age in years and stick it into the summary */
function setAge() {
  var today = new Date();
  var dob = new Date(1983, 0, 23);
  var years = today.getFullYear() - dob.getFullYear();
  var days = today.getDate() - dob.getDate();
  if (days < 0 && today.getMonth() <= dob.getMonth()) { years--; }
  document.getElementById("myage").innerHTML = Math.floor(years);
  
  if (today.getMonth() == dob.getMonth() && today.getDate() == dob.getDate())
    document.getElementById("birthday").innerHTML = "Today is actually my birthday, hooray!";
}


