function writeIE() {
  if (is.ie4comp!=-1 && is.ns!=1) document.write('<link rel="stylesheet" type="text/css" href="'+viewFolder+'css/ie.css" />');
}

function init() {
  onScroll(updateTopButton);
}

function openApplicationLink(url, target) {
  if(url == null || url == '') {
    return false;
  }

  if(target != 'self') {
    window.open(url, target);
  } else {
    window.location.href = url;
  }
}

function setCookie(c_name, value, expiredays) {
  var exdate = new Date();
  exdate.setDate(exdate.getDate() + expiredays);
  document.cookie = c_name + "=" +escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString() + ";path=/");
}

function setCookie_dommel(c_name, value, expiredays, alwaystrue) {
  var exdate = new Date();
  if (value==false)
  {
    expiredays = 7;
  }
  exdate.setDate(exdate.getDate() + expiredays);
  document.cookie = c_name + "=" +escape(alwaystrue) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString() + ";path=/");
}

function getCookie(c_name) {
  if (document.cookie.length > 0) {
    c_start = document.cookie.indexOf(c_name + "=");
    if (c_start != -1) {
      c_start = c_start + c_name.length+1;
      c_end = document.cookie.indexOf(";",c_start);
      if (c_end == -1) {
        c_end = document.cookie.length;
      }
      return unescape(document.cookie.substring(c_start,c_end));
    }
  }
  return "";
}

var internal_link = false;

function showEnquetePopup(id) {
  var enqCookie = getCookie('show_enquete_' + id);

  if (internal_link == true) {
    return false;
  }
  else if (enqCookie != null && enqCookie == "true") {
    return false;
  } else {
    return true;
  }
}

function internalLinks() {
  var contents = getElt('page');
  if(contents) {
    if (!document.getElementsByTagName) {
      return;
    }
    var anchors = document.getElementsByTagName('a');
    for(var i=0; i<anchors.length; i++) {
      if(anchors[i].className != 'blank' && anchors[i].className != 'popupblank' && anchors[i].className != 'extern' && anchors[i].className != 'print') {
        anchors[i].onclick = function() {
          internal_link = true;
        }
      }
    }
  }
}

function fixBottoms() {
  $('div.kolom_holder').find('div.tweekoloms:last').css("border-bottom-style","none");
  $('div.kolom_holder').find('ul.index').find('li:last').addClass("lastli");
}

var rotateAction = null;

function initRotator() {
  //Set the opacity of all images to 0
  var imgheight = $('div#rotator').find('img:first').css("height");
  $('div#rotator').css("height", imgheight);

  //Set the opacity of all images to 0
  $('div#rotator ul li').css({opacity: 0.0});

  //Get the first image and display it (gets set to full opacity)
  $('div#rotator ul li:first').css({opacity: 1.0});
}

function theRotator() {
  $('div#rotator').append('<div id="rotator_stop"><a href="' + document.URL + '">Stop animatie</a></div>');

  //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
  if ($('div#rotator ul li').length > 1) {
    rotateAction = setInterval('rotate()', 6000);
  }

  // extra: start/stop linkje
  $('#rotator_stop a').bind('click', function() {
    if(rotateAction != null) {
      clearInterval(rotateAction);
      rotateAction = null;
      $('#rotator_stop a').text('Start animatie');
    } else {
      rotateAction = setInterval('rotate()', 6000);
      $('#rotator_stop a').text('Stop animatie');
    }

    return false;
  });
}

function rotate() {
  //Get the first image
  var current = ($('div#rotator ul li.show')? $('div#rotator ul li.show') : $('div#rotator ul li:first'));

  //Get next image, when it reaches the end, rotate it back to the first image
  var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));

  //Set the fade in effect for the next image, the show class has higher z-index
  next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);

  //Hide the current image
  current.animate({opacity: 0.0}, 1000).removeClass('show');
}
