if (document.getElementById) { window.onload = swap };

function swap() {
var numimages=10;
rndimg = new Array(
'http://www.randomtots.com/blog/bg/rtbg-21birthday.jpg', 
'http://www.randomtots.com/blog/bg/rtbg-eastcoast.jpg', 
'http://www.randomtots.com/blog/bg/rtbg-dolomites.jpg', 
'http://www.randomtots.com/blog/bg/rtbg-ophir.jpg', 
'http://www.randomtots.com/blog/bg/rtbg-florpisa.jpg', 
'http://www.randomtots.com/blog/bg/rtbg-rome.jpg',
'http://www.randomtots.com/blog/bg/rtbg-sweden.jpg',
'http://www.randomtots.com/blog/bg/rtbg-venice.jpg',
'http://www.randomtots.com/blog/bg/rtbg-taipei.jpg',
'http://www.randomtots.com/blog/bg/rtbg-hualien.jpg');
x=(Math.floor(Math.random()*numimages));
randomimage=(rndimg[x]);
document.getElementById("framecontent").style.backgroundImage = "url("+ randomimage +")"; 
}


function TAG_Pop(URL, WID, HEI) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=" + WID + ",height=" + HEI + "');");
}
		
function tagSubmit() {
	document.tagger.message.focus();
	document.tagger.comment.value = document.tagger.message.value;
	document.tagger.message.value = '';
}

	
/* start of countdown timer */
var myCountdown = new Array();
var repeat = false;

function checkPlural(noun, value) {
  noun = ((value == 1) || (value == 0)) ? noun : (noun += "s");
  return noun;
}

function updateDisplay(text, id) {
  var tag = document.getElementById(id);
  if (tag.firstChild) {
    tag.firstChild.nodeValue = text;
  }
  else {
    textNode = document.createTextNode(text);
    tag.appendChild(textNode);
  }
  return;
}

function doCountdown() {
  for (i = 0; i < myCountdown.length; i++) {
    if (!myCountdown[i].expired) {
      var currentDate = new Date();
      var eventDate = myCountdown[i].eventDate;
      var timeLeft = new Date();
      timeLeft = eventDate - currentDate;
      msPerDay = 24 * 60 * 60 * 1000;
      msPerHour = 60 * 60 * 1000;
      msPerMin = 60 * 1000;
      msPerSec = 1000;
      daysLeft = Math.floor(timeLeft / msPerDay);
      hoursLeft = Math.floor((timeLeft % msPerDay) / msPerHour);
      minsLeft = Math.floor(((timeLeft % msPerDay) % msPerHour) / msPerMin);
      secsLeft = Math.floor((((timeLeft % msPerDay) % msPerHour) % msPerMin) / msPerSec);
      day = checkPlural("day", daysLeft);
      hour = checkPlural("hour", hoursLeft);
      minute = checkPlural("min", minsLeft);
      second = checkPlural("sec", secsLeft);
      if ((daysLeft == 0) && (hoursLeft == 0) && (minsLeft == 0) && (secsLeft == 0)) {
        updateDisplay(myCountdown[i].onevent, myCountdown[i].tagID);
      }
      else {
        if (daysLeft <= -1) {
          updateDisplay(myCountdown[i].afterevent, myCountdown[i].tagID);
          myCountdown[i].expired = true;
        }
        else {
          updateDisplay(daysLeft + " " + day + " " + hoursLeft + " " + hour +
                        " " + minsLeft + " " + minute + " " +
                        secsLeft + " " + second + " " +
                        myCountdown[i].event, myCountdown[i].tagID);
          repeat = true;
        }
      }
    }
  }
  if (repeat) {
    repeat = false;
    window.setTimeout("doCountdown()", 1000);
  }
  else {
    return;
  }
}

function setEventDate(year, month, day, hour, minute, second) {
  this.eventDate = new Date(year, month - 1, day, hour, minute, second);
  return;
}

function addCountdown(countdown) {
  myCountdown[myCountdown.length] = countdown;
  return;
}

function Countdown() {
  this.tagID = "";
  this.eventDate = new Date();
  this.setEventDate = setEventDate;
  this.event = "";
  this.onevent = "";
  this.afterevent = "";
  this.expired = false;
}

var mycountdown = new Countdown();

with (mycountdown) {
  tagID = "mycountdowndiv";
  setEventDate(2009, 08, 08, 00, 00, 0);
  event = "until The Wedding! =)"; 
  onevent = "Jas and FM are getting married NOW!";
  afterevent = "Jas and FM are now officially MARRIED!!!";
}

addCountdown(mycountdown);

/* end of countdown timer */
