var refresh = 3;
var seconds = refresh;

Event.onReady(function() {
  webcamRefresh();
});

function webcamRefresh() {
  var counter = document.getElementById('ant-cam-counter');
  var countdown_display = --seconds;
  if (countdown_display == 0) {
    countdown_display = refresh;
  } 
  counter.innerHTML = countdown_display;

  if (seconds <= 0) {
  	var now = new Date();
  	var imageURL = "http://rupespad.dyndns.org:65251/ant-cam.jpg" + "?" + now.getTime();
  	
  	document.webcam.src = imageURL;
  	seconds = refresh;
  }
  setTimeout("webcamRefresh()", 1000);
};

var LoadInitialAntCamImage = Behavior.create({ 
  
  initialize: function() { 
  	var imageURL = "http://rupespad.dyndns.org:65251/ant-cam.jpg"
  	this.element.src = imageURL;
  }
});

Event.addBehavior({
  'img#ant-webcam-image': LoadInitialAntCamImage
});
