var headerNr = 1;
var headerTimer = 0;

$(document).ready(function() {
  $('.hoofdItem').hover(function() {
    $(this).find('.submenu:hidden').fadeIn('fast');
  }, function() {
    $(this).find('.submenu:visible').fadeOut('fast');
  });
  
  $('.headerNavigatie a').click(function() {
    $('.headerNavigatie .actief').removeClass('actief');
    $(this).addClass('actief');
    weergeefHeader($(this).attr('title'));
  });
  
  $('.zoekFormulier .textbox input').click(function() {
    if($(this).val() == 'Zoeken') { $(this).val(''); }
  });
  
  $('.zoekFormulier .textbox input').blur(function() {
    if($(this).val() == '') { $(this).val('Zoeken'); }
  });
  
  $('.vorigeSponsors').click(function() {
    if ($('#sponsors .actieveBox').length == 0) {      
      var links = $('#sponsors .box').css('left').replace('px', '');
  
      if (links + 850 < 0) {
        $('#sponsors .box').addClass('actieveBox');
        
        $('#sponsors .box').animate( { left: '+=850' }, 500, function() {
          $(this).removeClass('actieveBox');
        } );
      }
    }
  });  
  
  $('.volgendeSponsors').click(function() {
    if ($('#sponsors .actieveBox').length == 0) {      
      var links = $('#sponsors .box').css('left').replace('px', '');
      var breed = 0 - $('#sponsors .box').css('width').replace('px', '');
  
      if (links - 850 > breed) {
        $('#sponsors .box').addClass('actieveBox');
      
        $('#sponsors .box').animate( { left: '-=850' }, 500, function() {
          $(this).removeClass('actieveBox');
        } );
      }
    }
  });
  
  $('.vorigeOpleidingen').click(function() {
    if ($('.opleidingenNavigatie .actieveBox').length == 0) {      
      var links = $('.opleidingenNavigatie .box').css('left').replace('px', '');
  
      if (links + 600 < 0) {
        $('.opleidingenNavigatie .box').addClass('actieveBox');
        
        $('.opleidingenNavigatie .box').animate( { left: '+=600' }, 500, function() {
          $(this).removeClass('actieveBox');
        } );
      }
    }
  });  
  
  $('.opleidingenNavigatie .box a img').click(function(e) {
    e.preventDefault();
    document.location.href = $(this).parent().parent().attr('href');
  });
  
  $('.volgendeOpleidingen').click(function() {
    if ($('.opleidingenNavigatie .actieveBox').length == 0) {      
      var links = $('.opleidingenNavigatie .box').css('left').replace('px', '');
      var breed = 0 - $('.opleidingenNavigatie .box').css('width').replace('px', '');
  
      if (links - 600 > breed) {
        $('.opleidingenNavigatie .box').addClass('actieveBox');
      
        $('.opleidingenNavigatie .box').animate( { left: '-=600' }, 500, function() {
          $(this).removeClass('actieveBox');
        } );
      }
    }
  });  
  
  
  $('.paginaFotos a').lightBox();
  
  $('.opleidingFotos a').lightBox();
  
  /*
  $('.zoomicon').click(function(e) {
    $(this).parent().lightBox();
  });
  */
  
  var opleiding = $('#opleiding');
  
  if (opleiding.length > 0) {
    var waarde = $('#opleiding').val();
    $('#opleiding').parent().html('<div style="width: 400px">' + waarde + '</div><input type="hidden" name="opleiding" value="' + waarde + '">');
  }
  
  headerTimer = setTimeout('volgendeHeader()', 4000);
});

function weergeefHeader(nr) {
  headerNr = nr;
  var url = $('.headersLijst img:visible').attr('src');
  $('.headersLijst').css('backgroundImage', 'url(' + url + ')');
  $('.headersLijst img:visible').hide();
  $('.headersLijst img:nth-child(' + nr + ')').fadeIn('fast', function() {
  
  });
  
  clearTimeout(headerTimer);
  headerTimer = setTimeout('volgendeHeader()', 4000);
}

function volgendeHeader() {
  var aantal = $('.headersLijst img').length;
  
  var nr = headerNr + 1;
  
  if (nr > aantal) {
    nr = 1;
  }
  
  $('.headerNavigatie .actief').removeClass('actief');
  $('.headerNavigatie li:nth-child(' + nr + ') a').addClass('actief');

  weergeefHeader(nr);
}
