addLoadEvent(displayLag);
addLoadEvent(displaySmallLag);
addLoadEvent(displayEmne);

function addLoadEvent(func) {
  var oldonload = window.onload;
    if (typeof window.onload != 'function') {
      window.onload = func;
    } else {
      window.onload = function() {
      oldonload();
      func();
    }
  }
}


function displayLag()
{
  if($('userContent'))
  {
    var content = $('userContent').innerHTML;
    var container = $('lag').innerHTML = content;
  }
}

function displaySmallLag()
{
  if($('smallUserContent'))
  {
    var smallContent = $('smallUserContent').innerHTML;
    var smallContainer = $('lagSmall').innerHTML = smallContent;
  }
}


function showLargeImg()
{
  $$('.imgLarge').each(function(element)
  {
    element.onclick = function()
    {
      var popupDiv = Builder.node('div', {className:'popupDiv'}, [Builder.node('img', {src:''+element.href+''})]);
      $('container').appendChild(popupDiv);
      return false;
    }
  });
}


function displayEmne()
{
  $$('.emneOverview').each(function(element)
  {
    element.onclick = function()
    {
      var emneHref = element.href;
      var emneID = emneHref.split("/?");

      var ajaxUrl = '/?'+emneID[1];
      new Ajax.Request(ajaxUrl, {
        method: 'get',
        //onCreate: this.displayLoading('show'),
      
        //onLoaded: this.displayLoading('hide'),
      
          onComplete: function(resp){
          var holeText = resp.responseText;
          var contentRest = holeText.split('<div class="emneContentIndhold">');
          var contentToUse = contentRest[1].split("<!--  filler for small logo -->");
          var udateDiv = $('emneDetailsContent').innerHTML = contentToUse[0];
          manualAssignNifty('emneImgContainer');
          initLightbox();
         },
        onFailure: function(){
          alert('Fejl ved ajax kald til serveren!!');
        return false;
      }
     });
       return false;
    }
  });
}
