/* McCOLIN DOT COM
 * Javascript for Front Door
 * Jan 2009
 */

/* 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 point of the speech bubble header to a random image in the list */
function setPoint() {
  var pointOut = document.getElementById("pointout");
  var pointIn = document.getElementById("pointin");
  var margins = [38, 127, 215, 302, 391, 480, 570, 657];
  var margin = margins[Math.floor(Math.random()*margins.length)];
  pointOut.style.marginLeft = ""+margin+"px";
  pointIn.style.marginLeft = ""+(margin+2)+"px";
  pointOut.style.visibility = pointIn.style.visibility = "visible";
}

/* 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);
}

