function CustomArticleList() {
}

CustomArticleList.init = function(bEditable) {
    var mainContent = document.getElementById("vacancies");
    if (mainContent) {
        var titleList = document.getElementsByTagName("h2");
        for (var i=0; i < titleList.length; i++) {
          titleList[i].firstChild.url=titleList[i].firstChild.href;
          titleList[i].firstChild.href='#';
          titleList[i].firstChild.downloadfile = (titleList[i].firstChild.target == '_blank' ? true : false);
          titleList[i].firstChild.target='';
          titleList[i].firstChild.attachEvent("onclick", CustomArticleList.showArticle);
        }
        this.detailDiv = document.createElement("div");
        this.detailDiv.id = "vacancyDetail";

        this.detailTitle = document.createElement("h3");
        this.detailDiv.appendChild(this.detailTitle);

        this.detailShortDesc = document.createElement("div");
        this.detailShortDesc.id = "vacancyShortDesc";
        this.detailDiv.appendChild(this.detailShortDesc);

        this.detailReadMore = document.createElement("span");
        this.detailReadMore.id = "vacancyReadMore";

        this.detailLink = document.createElement("a");
        this.detailLink.innerText = "Lees verder";
        this.detailDownloadLink = document.createElement("a");
        this.detailDownloadLink.innerText = "Download";
        this.detailReadMore.appendChild(this.detailLink);
        this.detailReadMore.appendChild(this.detailDownloadLink);

        this.detailDiv.appendChild(this.detailReadMore);

        mainContent.appendChild(this.detailDiv);
    }
    this.activeLink = false;
}

CustomArticleList.showArticle = function(ev) {
  if (CustomArticleList.activeLink) {
      CustomArticleList.activeLink.className = CustomArticleList.activeLink._className;
  }

    var target = window.event.srcElement.parentNode;

  CustomArticleList.activeLink = target;

  var shortDesc = target;
  do {
    shortDesc = shortDesc.nextSibling;
  } while (shortDesc && shortDesc.nodeType != 1);

  if (shortDesc) {
     CustomArticleList.detailTitle.innerText = target.innerText;
     CustomArticleList.detailShortDesc.innerHTML = shortDesc.innerHTML;
     CustomArticleList.detailDiv.style.display = 'block';
     target._className = target.className;
     target.className += " vacancy";
  }

  if (CustomArticleList.activeLink.children[0].downloadfile)
  {
    CustomArticleList.detailDownloadLink.target = "_blank";
    CustomArticleList.detailDownloadLink.href = CustomArticleList.activeLink.children[0].url;
    CustomArticleList.detailDownloadLink.style.display = "inline";
  }
  else
  {
    CustomArticleList.detailDownloadLink.target = "";
    CustomArticleList.detailDownloadLink.href = "";
    CustomArticleList.detailDownloadLink.style.display = "none";
  }

  var readMore = shortDesc;
  do {
    readMore = readMore.nextSibling;
  } while (readMore && readMore.nodeType != 1);

  if (readMore) {
     CustomArticleList.detailLink.href=readMore.firstChild.href;
     CustomArticleList.detailLink.style.display = "inline";
  } else {
    CustomArticleList.detailLink.style.display = "none";
  }

  window.event.cancleBubble = true;
  return false;
}

CustomArticle = {};

CustomArticle.openPopup = function(sURL, sWindowId) {
    var newWindow = window.open(sURL, sWindowId, "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,scrollbars=Yes,width=500,height=600,left=200,top=100");
    newWindow.focus();
}