
// Register a callback for the getPresenceInfo transaction
AIM.params.callbacks.getPresenceInfo = ["awayMessageWidget.displayAwayMessage"];
var awayMessageWidget = {
 // Our init function, called from the window's onload event.
 init: function() {
  // Our API key. Be sure to change this to your own
  AIM.params.wimKey = "we1kcqNsiCZNv8-D";
  // Call the getPresenceInfo transaction
  AIM.transactions.getPresenceInfo();
 },
 // This function is the callback for our transaction. It takes the json response from the host as its argument
 displayAwayMessage: function(json) {
  // Only do stuff if the back-end tells us everything is Ok
  if(json.response.statusCode==200) {
   // Only do stuff if the status of the user is "away"
   if(json.response.data.users[0].state == "away") {
    // grab the away message from the response and stick it in the "myAwayMessage" element.
    document.getElementById("myAwayMessage").innerHTML = "<p><strong>AIM Status</strong>: <img src=\"aim_away.png\" alt=\"Away\" border=\"0\" align=\"top\" /> " + json.response.data.users[0].awayMsg + "</p>";
   }
  }
 }
}
// attach the init function to the onload event of the window
window.addEventListener?window.addEventListener("load",awayMessageWidget.init,false):window.attachEvent("onload",awayMessageWidget.init);

