// The right way to add load events. By Simon Willison
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  }
  else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

// attach an event properly

function attachEvent(element, type, event)  {
  if(element.attachEvent) {
    element.attachEvent('on' + type, event);
  }
  else  {
   element.addEventListener(type, event, false);
  }
}

// HG News
function loadNews() {
  new Ajax.Updater($('news-content'), '/static/php/news.php', {
    method: 'get',
    frequency: 120
  });
}

addLoadEvent(loadNews);

// Load sidebars
function loadSidebars() {
  new Ajax.Updater($('side-poll'), '/polls/inc_poll.php'+window.location.search, {
    method: 'get'
  });

  new Ajax.Updater($('side-gallery'), '/sidebar-gallery', {
    method: 'get'
  });

  new Ajax.Updater($('side-headlines'), '/inc/headlines.txt', {
    method: 'get',
    frequency: 120
  });

  new Ajax.Updater($('side-recent-posts'), '/static/php/new_threads.php', {
    method: 'get',
    frequency:120
  });
}

addLoadEvent(loadSidebars);
