
YAHOO.namespace("ksu.widget.EventViewer");

(function() {

// Shortcut YUI definitions
var Dom         = YAHOO.util.Dom;
var $           = Dom.get;
var setStyle    = Dom.setStyle;
var LOG;


/**
 * Constructor for the KSU.widget.EventViewer object.
 */
KSU.widget.EventViewer = function(url, el, attr) {
   attr = attr || {};

   this.el = $(el);
   if (!this.el) {
      LOG.log("Element '" + el + "'could not be found.", "error");
   }
   this.url = url;

   LOG = new YAHOO.widget.LogWriter("EventViewer");
   LOG.log("Created new eventViewer");
};


////////////////////////////////////////////////
// Private static properties
////////////////////////////////////////////////

var pub = KSU.widget.EventViewer.prototype;

/**
 * Display retrieved Event data.
 */
pub.displayEvents = function(response, ctx) {

   this.el.innerHTML = response.responseText;

};

var getValue = function(el, tagname) {

   var result = "";

   try {
      result = el.getElementsByTagName(tagname)[0].firstChild.nodeValue;
   } catch (e) {
      /* nothing */
   }

   return result;
};


/**
 * Add a note about data not available.
 */
pub.warnNotAvailable = function(response, ctx) {
};

pub.render = function() {

   LOG.log("Rendering");
   this.transID = YAHOO.util.Connect.asyncRequest('GET',
                                         this.url,
                                         {
                                             success: pub.displayEvents,
                                             failure: pub.warnNotAvailable,
                                             scope: this
                                         } );
};

})();

