currentTopProductChild = 0;
currentHomeSlide = 0;
volgendeHeaderNummer = 0;
headerInterval =	setInterval(volgendeHeader, 5000);
partnersTimer = 	setInterval(volgendePartners, 5000);

function volgendePartners() {
  /*
  $.ajax({
	  url: '/',
		success:function(data) {
		  var nieuweLogos = $(data).find('.partnerLogos').html();
			$('.partnerLogos').fadeOut('normal', function() {
			  $(this).html(nieuweLogos).fadeIn();
			});
		}
	});
	*/
	
	if ($('.partnerLogos .logosLijst').length > 1) {
  	var volgende = $('.partnerLogos .logosLijst:visible').next();
  	
  	if(volgende.length > 0) {
    	$('.partnerLogos .logosLijst:visible').fadeOut('fast', function() {
    	  $(volgende).fadeIn('fast');
    	});
  	} else {
    	$('.partnerLogos .logosLijst:visible').fadeOut('fast', function() {
    	  $('.partnerLogos .logosLijst:first').fadeIn('fast');
    	});
    }
	}
}

function volgendeHeader() {
  var volgendeNummer = volgendeHeaderNummer + 1;
	var aantalHeaders = $('.home-slide').length;
  var scroller = $('#home-slides');
	
	if (volgendeNummer >= aantalHeaders) { volgendeNummer = 0; }

	volgendeHeaderNummer = volgendeNummer;
	
			$('.active', scroller).fadeOut('fast', function() {
				$('.home-slide:eq('+ volgendeHeaderNummer +')', scroller).fadeIn('fast');
				$('.active', scroller).removeClass('active');
				$('.home-slide:eq('+ volgendeHeaderNummer +')', scroller).addClass('active');
  			$('.block-selected').removeClass('block-selected');
				$('#home-slides-menu .block:eq(' + volgendeHeaderNummer + ')').addClass('block-selected');
			});
}

jQuery(document).ready(function($) {

  $('.fancy').fancybox();

	$('#home-slides .home-slide:eq(0)').addClass('active');

	//Create circles
	var aantal = $('#home-slides').children('.home-slide').length;
	for( i=0; i < aantal; i++) {
		$('#home-slides-menu').append('<a href="javascript:" class="block"></a>');
	}

  // Newslettesr
    $('.aanmeldenNieuwsbrief').submit(function(e) {
      e.preventDefault();
      
      $.fancybox({
        'href' : '/php/verwerk/nieuwsbrief.php',
        'type' : 'ajax',
        'title' : 'Aanmelden nieuwsbrief',
        'ajax' : {
          data: $(this).serializeArray()
        }
      });
    });
  
    
    $('#menu li').hover(function() {
      $(this).find('.submenu:hidden').slideDown('fast');
    }, function() {
      $(this).find('.submenu:visible').slideUp('fast');
    });
  
  
  // Videos
    $('.videoThumb').click(function(e) {
		  e.preventDefault();
		  var url = $(this).attr('href');
			$.fancybox({
			  href: url,
				scrolling: 'no',
				centerOnScroll: true,
				type: 'ajax'
			});
		});
  
	//Make first blue
	$('#home-slides-menu .block:eq(0)').addClass('block-selected');

	//Clickable blocks 
	$('.block').live('click', function() {
		var scroller = $('#home-slides');

		if( !$('.active', scroller).is(':animated') ) {
			$('.block-selected').removeClass('block-selected');
  		$(this).addClass('block-selected');
			
			currentHomeSlide = $(this).index();
			
			clearInterval(headerInterval);
			
			$('.active', scroller).fadeOut('fast', function() {
				$('.home-slide:eq('+ currentHomeSlide +')', scroller).fadeIn('fast');
				$('.active', scroller).removeClass('active');
				$('.home-slide:eq('+ currentHomeSlide +')', scroller).addClass('active');
			});
		}
	});



	$('#home-topproducts .topproducts-holder:eq(0)').addClass('active');

	//Create circles
	var aantal = $('#home-topproducts').children('.topproducts-holder').length;
	for( i=0; i < aantal; i++) {
		$('#home-topproducts-menu').append('<a href="javascript:" class="circle"></a>');
	}

	//Make first blue
	$('#home-topproducts-menu .circle:eq(0)').addClass('circle-selected');

	//Clickable circles 
	$('.circle').live('click', function() {
		var scroller = $('#home-topproducts');

		if( !$('.active', scroller).is(':animated') ) {
			$('.circle-selected').removeClass('circle-selected');
			$(this).addClass('circle-selected');
			
			currentTopProductChild = $(this).index() -2;
			weergeefScroller(scroller, currentTopProductChild);
		}
	});

	$('#home-topproducts-previous').click(function() {
		var scroller = $('#home-topproducts');
		var aantal = $(scroller).children('.topproducts-holder').length;

		if( 0 < currentTopProductChild && !$('.active', scroller).is(':animated') ) {
			currentTopProductChild--;
			weergeefScroller(scroller, currentTopProductChild);

			$('.circle-selected').removeClass('circle-selected');
			$('.circle:eq('+ currentTopProductChild +')').addClass('circle-selected');
		}
	});

	$('#home-topproducts-next').click(function() {
		var scroller = $('#home-topproducts');
		var aantal = $(scroller).children('.topproducts-holder').length - 1;

		if( aantal > currentTopProductChild && !$('.active', scroller).is(':animated') ) {
			currentTopProductChild++;
			weergeefScroller(scroller, currentTopProductChild);

			$('.circle-selected').removeClass('circle-selected');
			$('.circle:eq('+ currentTopProductChild +')').addClass('circle-selected');
		}

	});

	function weergeefScroller(scroller, nr) {
		$('.active', scroller).fadeOut('fast', function() {
			$('.topproducts-holder:eq('+ nr +')', scroller).fadeIn('fast');
			$('.active', scroller).removeClass('active');
			$('.topproducts-holder:eq('+ nr +')', scroller).addClass('active');
		});
	}



	// Nice hover
	$(".topproduct-item").hover(
		function () {
			$(this).find('.topproduct-more').fadeIn('fast');
		},
		function () {
			$(this).find('.topproduct-more').fadeOut('fast', function() {
//				$(this).css('display', 'block');
			});
		}
	);
	
	// Input placeholder
	  $('input').each(function() {
		  var placeholder = $(this).attr('placeholder');
			
			if($(this).val() == '') {
			  $(this).val(placeholder);
			}
			
			$(this).focus(function() {
			  if ($(this).val() == $(this).attr('placeholder')) {
				  $(this).val('');
				}
			});
			
			$(this).blur(function() {
			  if ($(this).val() == '') {
				  $(this).val($(this).attr('placeholder'));
				}
			});
		});

		$('.secretTokenField').each(function() {
		  $(this).val('dagSpamBot');
		});
});
