// addEvent manager - http://www.twinhelix.com/javascript/addevent/
// modified to work in IE8
if (typeof addEvent != 'function')
{
 var addEvent = function(obj, obj_event, obj_func, l)
 {
    // define vars
  var d = 'addEventListener', n = 'on' + obj_event, rO = obj, rT = obj_event, rF = obj_func, rL = l;
  
  if (obj['addEventListener'] && !l) {
    return obj['addEventListener'](obj_event, obj_func, false);
    //return obj[d](obj_event, obj_func, false);
  }
  else {
    // added this else as a hack for this function to get it to work in ie8
    if (obj['attachEvent']){
        // if this is valid, then do this and return
        return obj.attachEvent(n, obj_func);
    } 
  }
  // else continue with this script
  if (!obj._evts) obj._evts = {};
  if (!obj._evts[obj_event])
  {
   obj._evts[obj_event] = obj[n] ? { b: obj[n] } : {};
   obj[n] = new Function('e',
    'var r = true, obj = this, a = obj._evts["' + obj_event + '"], i; for (i in a) {' +
     'obj._f = a[i]; r = obj._f(e||window.event) != false && r; obj._f = null;' +
     '} return r');
   if (obj_event != 'unload') addEvent(window, 'unload', function() {
    removeEvent(rO, rT, rF, rL);
   });
  }
  if (!obj_func._i) obj_func._i = addEvent._i++;
  obj._evts[obj_event][obj_func._i] = obj_func;
 };
 addEvent._i = 1;
 var removeEvent = function(obj, obj_event, obj_func, l)
 {
  var d = 'removeEventListener';
  if (obj['removeEventListener'] && !l) {
    return obj['removeEventListener'](obj_event, obj_func, false);
  }
  else {
    if (obj['detachEvent']){
        // if this is valid, then do this and return
        //alert("in here");
        return obj.detachEvent('on'+obj_event, obj_func);
    }     
  }
  if (obj._evts && obj._evts[obj_event] && obj_func._i) delete obj._evts[obj_event][obj_func._i];
 };
}
