﻿function setNavMargin() {
  var nav = document.getElementById('nav');
  //Totale breedte bepalen van alle items:
  var width = 0;
  for (i=0; i < nav.childNodes.length; i++) {
    if (nav.childNodes[i].tagName == "LI") {  
      width += nav.childNodes[i].offsetWidth;
    }
  }
  
  var offset = (document.getElementById('nav').offsetWidth - width ) / 2;
  if (offset > 0) {
    nav.childNodes[0].style.marginLeft = offset + 'px';
  }
}

function checkMenuItems() {
  //alert('Testing menu');
  //Menu corrigeren voor alle browsers, css is niet volledig dekkend.
  var strItems = "";
  jQuery('#nav ul').each(
    function() {
      jQuery(this).children('li :not(li.pre, li.post,li.fill)').each(
        function() {
          //alert("item");
          strItems += jQuery(this).children('span').text() + "==" + jQuery(this).children('a').height() + "==" + jQuery(this).children('span').height() + "<br/>\n";
          if (!(jQuery(this).children('a').height() == jQuery(this).children('span').height())) {
            jQuery(this).children('a').css("width",122);
            //alert("Mismatch gevonden:<br/>Hoogte Anchor: " + jQuery(this).children('a').height() + "<br/>Hoogte Span: " + jQuery(this).children('span').height());
          }
          jQuery(this).children('span').css("height",jQuery(this).children('span').height());
          jQuery(this).children('span').empty();
        }
      );
    }
  );
  //alert(strItems);
  //alert('Done testing menu');
}

function checkZoekWidth() {
  var intZoekWidth = 225; // css width.
  
  if (jQuery('#zoeken span').width() + jQuery('#zoeken a').width() > 225) {
    jQuery('#zoeken').css("width", (jQuery('#zoeken span').width() + jQuery('#zoeken a').width() + 20));
  }
}

function checkPageHeight() {
  // Controleren of de content van de rechterbalk langer is dan de content van de site.
//  var bar = document.getElementById("bar_right");
//  if (bar) {
//    var inputs = bar.getElementsByTagName("div");
//    
//    var offset = 356;
//    // Offset + 20 margin van de h2
//    var totalHeight = offset + 20;
//    for(i=0;i<inputs.length;i++)
//    {
//      if (inputs[i].parentNode == bar) 
//      {
//        // Hoogte plus margin er bij tellen.
//        totalHeight += inputs[i].offsetHeight + 20;
//      }
//    }
//    
//    var content = document.getElementById("content");
//    var contentHeight = offset + content.offsetHeight;
//    // Als de content langer is, dan een css min-height toevoegen voor de verhoging van de site.
//    if (totalHeight > contentHeight) {
//      content.style.minHeight = (totalHeight - offset) + "px";
//    }
//  }
  // Met jquery:
  var intJQHeight = 0;
  // Eerste de hoogtes verwijderen zodat er geen verkeerde hoogte berekend wordt.
  jQuery('#content').css("min-height", '');
  jQuery('#bar_right').css("min-height", '');
  jQuery('#content').css("height", '');
  jQuery('#bar_right').css("height", '');
  
  // Hoogte van de sidebar berekenen.
  jQuery('#bar_right div').each(function() {intJQHeight += jQuery(this).height();});
  // Eventueel een min-hoogte instellen.
  //alert(intJQHeight);
  var highest = intJQHeight;
  if (jQuery('#content').height() > intJQHeight) {
    highest = jQuery('#content').height();
  }
  if (highest < 342) {
    highest = 342;
  }
  jQuery('#content').css("min-height", highest - 2);
  jQuery('#bar_right').css("min-height", highest - 2);
  jQuery('#content').css("height", highest - 2);
  jQuery('#bar_right').css("height", highest+18);
//  if (jQuery('#content').height() < intJQHeight) {
//    jQuery('#content').css("min-height", intJQHeight - 20);
//  }
  
//  alert(intJQHeight);
//  alert(jQuery('#bar_right').height());
//  alert(jQuery('#content').height());
}

function showTooltip(id) {
  var tip = document.getElementById(id);
  tip.style.display = 'block';
  //IE 6 fix:
  tip.style.width = '350px';
}

function hideTooltip(id) {
  var tip = document.getElementById(id);
  tip.style.display = 'none';
}

function textFieldFocus(object,defaultValue) {
  if (object.value == defaultValue) {
    object.value = "";
  }
}

function textFieldBlur(object,defaultValue) {
  if (object.value == "") {
    object.value = defaultValue;
  }
}

// Globale window.onload functie, zorgt ervoor dat meerdere functies kunnen worden uitgevoerd tijdens de onload.
function addOnloadEvent(fnc){
  if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fnc, false );
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", fnc );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[fnc]();
      };
    }
    else 
      window.onload = fnc;
  }
}

var deinnerfade;
$(document).ready(function () {
  // Carousel op home activeren
  if ($('#carousel_inner').length > 0) {
    deinnerfade = $('#carousel_inner').innerfade({
      speed: 'slow',
      timeout: 3500,
      type: 'sequence',
      containerheight: '254px'
    });
  }
});