// JavaScript Document

$(document).ready(function(){
/*HOME*/

	var myQuotes = new Array();
	myQuotes[0] = "Aardige mensen*";
	myQuotes[1] = "Sales are up*";
	myQuotes[2] = "Puur verwennen*";
	myQuotes[3] = "Trefzeker*";
	myQuotes[4] = "Snel schakelen*";
	
	var myQuotesBar = new Array();
	myQuotesBar[0] = "Wilt u ook resultaat?";
	myQuotesBar[1] = "Wilt u ook snel schakelen?";
	myQuotesBar[2] = "Wilt u ook leads?";
	myQuotesBar[3] = "Wilt u ook recht op uw doel af?";
	myQuotesBar[4] = "Wilt u ook deadlines halen?";
	
	var myRandom = Math.floor(Math.random()*myQuotes.length);
	
	$('#sloganbar .slogan').html(myQuotes[myRandom]);
	$('#contact span').html(myQuotesBar[myRandom]);
	
/*WERK*/
	if ($(window).height() < 610){
		$('.popover').css({
			"margin-top": "-130px"
		});
	}
	
	$(window).resize(function(){
		if ($(window).height() < 610){
			$('.popover').animate({
				"margin-top": "-130px"
			});
		} else {
			$('.popover').animate({
				"margin-top": "0px"
			});
		}
	});
	
	window.werk = {};
	window.werk.total = $('#werksection .slider').children().size();
	window.werk.perPage = 12;
	window.werk.nrDivs = Math.ceil(window.werk.total / window.werk.perPage);
	window.werk.aantal = $('#werksection .slider').children().size();
	
	i = 1;

	//alert(total+" "+perPage+" "+total%perPage)

	for (var x = 0; x < ((window.werk.nrDivs * window.werk.perPage) % window.werk.total) ; x++) {
		$('#werksection .slider').append('<article class="empty"></article>');
	}
	
	for (var x = 1; x <= window.werk.nrDivs; x++) {
		$('#werksection .slider').append('<div class="slide"></div>');
	}
	
	$('.slide').each(function(index) {
		for (var x = 0; x < window.werk.perPage; x++) {
			$(this).append($('#werksection .slider article').first());
		}
	});
	
	for (var x = 1; x <= window.werk.nrDivs; x++) {
		$('#werksection .navigation .navbuttons').append('<div class="navbutton button_'+(x-1)+'" id="'+(x-1)+'"></div>');
	}
	
	$('#werksection .navigation .navbuttons .navbutton').first().addClass("active");
	width = (window.werk.nrDivs * (12+9) );
	$('#werksection .navigation .navbuttons').css({
		"width":  width+"px",
		"marginLeft": Math.round( -(width-9) /2 )
	});
	
	if (window.werk.nrDivs == 1){
		$('#werksection .navigation .slidenext').slideUp(0);
	}
	
	$('#werksection .navigation .slideback').slideUp(0);

	window.werk.thisslide = 0;
	
	$('#werksection .navigation .navbuttons .navbutton').click(function(){
		if ($(this).hasClass("active")){
		} else {
			$('#werksection .navigation .navbuttons .navbutton').removeClass("active");
			$(this).addClass("active");
			window.werk.thisid = $(this).attr("id");
			window.werk.thisslide = window.werk.thisid;
			$('#werksection .slider').animate({
				"marginLeft": -(window.werk.thisid * 784)+20 +"px"
			},350);
			$('#werksection .navigation .slideback').slideDown(350);
			$('#werksection .navigation .slidenext').slideDown(350);
			if (window.werk.thisid == 0){
				$('#werksection .navigation .slideback').slideUp(100);
			}
			if (window.werk.thisid == (window.werk.nrDivs-1)){
				$('#werksection .navigation .slidenext').slideUp(100);
			}
		}
	});
	
	$('#werksection .navigation .slidenext').click(function(){
		window.werk.thisslide++;
		$('#werksection .slider').animate({
			"marginLeft": -((window.werk.thisslide) * 784)+20 +"px"
		},350);
		$('#werksection .navigation .slideback').slideDown(350);
		$('#werksection .navigation .slidenext').slideDown(350);
		if (window.werk.thisslide == 0){
			$('#werksection .navigation .slideback').slideUp(100);
		}
		if (window.werk.thisslide == (window.werk.nrDivs-1)){
			$('#werksection .navigation .slidenext').slideUp(100);
		}
		$('#werksection .navigation .navbuttons .navbutton').removeClass("active");
		$('#werksection .navigation .navbuttons .navbutton.button_'+ window.werk.thisslide).addClass("active");
	});

	$('#werksection .navigation .slideback').click(function(){
		window.werk.thisslide--;
		$('#werksection .slider').animate({
			"marginLeft": -((window.werk.thisslide) * 784)+20 +"px"
		},350);
		$('#werksection .navigation .slideback').slideDown(350);
		$('#werksection .navigation .slidenext').slideDown(350);
		if (window.werk.thisslide == 0){
			$('#werksection .navigation .slideback').slideUp(100);
		}
		if (window.werk.thisslide == (window.werk.nrDivs-1)){
			$('#werksection .navigation .slidenext').slideUp(100);
		}
		$('#werksection .navigation .navbuttons .navbutton').removeClass("active");
		$('#werksection .navigation .navbuttons .navbutton.button_'+ window.werk.thisslide).addClass("active");
	});
	
	$('#werksection .slider .slide article .popover').slideUp(0);
	
	$('#werksection .slider .slide article img, #werksection .slider .slide article h2').click(function(){
		$(this).parent().find("img.lazyload").each(function() {
			$(this).attr("src", $(this).attr("original"));
			$(this).removeAttr("original");
		});
		$(this).parent().find('div.popover').slideDown(350);
		$('#popover_overlay').animate({
			'margin-left': 0,
			'width': '100%'
		}, 350, 'swing');
	});
	
	$('#popover_overlay, .close_popover').click(function(){
		window.werk.returnname = jQuery.url.segment(2);
		if (window.werk.returnname == null){
			$('#werksection .slider .slide article .popover').slideUp(350);
			$('#popover_overlay').animate({
				'margin-left': '-1px',
				'width': '1px',
			}, 350, 'swing');
			
			$('#werksection .slider article .popover .image_nav .navbutton').removeClass("active");
			$('#werksection .slider article .popover .image_nav .child0').addClass("active");
			$('#werksection .slider article .popover .image_holder ul').animate({
				"marginLeft": "0px"
			}, 0);
			$('#werksection .slider article .popover .text_popover ul').animate({
				"marginLeft": "0px"
			}, 0);
			$('#werksection .slider article .popover .prev_case').slideUp(0);
			$('#werksection .slider article .popover .next_case').slideDown(0);
		} else {
			window.open("/"+window.werk.returnname+"/", "_self");
		}
	});
	
	$('#werksection .slider article:first .popover .nav_popover .prev_popover').hide();
	$('#werksection .slider article:eq('+(window.werk.total-1)+') .popover .nav_popover .next_popover').hide();
	
	$('#werksection .slider article .popover .nav_popover .prev_popover').click(function(){
		$(this).parent().parent().fadeOut('slow');
		$(this).parent().parent().parent().prev().find('.popover').fadeIn('slow');
	});
	
	$('#werksection .slider article .popover .nav_popover .next_popover').click(function(){
		$(this).parent().parent().fadeOut('slow');
		$(this).parent().parent().parent().next().find('.popover').fadeIn('slow');
	});
	
	$('#werksection .slider article').each(function(index){
		nrImages = $(this).find('.popover .image_holder ul li').children().size();
		for (var x = 1; x <= nrImages; x++) {
			$(this).find('.popover .image_nav').append('<div class="navbutton child'+(x-1)+'" id="'+(x-1)+'"></div>');
		}
		$(this).find('.popover .image_nav .prev_case').hide();
		if (nrImages == 1) {
			$(this).find('.popover .image_nav .next_case').hide();
		}
	});

	$('#werksection .slider article .popover .image_nav .child0').addClass("active");
			
	$('#werksection .slider article .popover .image_nav .navbutton').click(function(){
		$(this).parent().find('.navbutton').removeClass("active");
		$(this).addClass("active");
		thisid = $(this).attr("id");
		$(this).parent().parent().find('.image_holder ul').animate({
			"marginLeft": -(thisid * 533) +"px"
		},500, 'swing');
		$(this).parent().parent().find('.image_holder ul li div iframe').animate({
			"marginLeft": -(thisid * 533) +"px"
		},500, 'swing');
		$(this).parent().parent().find('.text_popover ul').animate({
			"marginLeft": -(thisid * 178) +"px"
		},500, 'swing');
		nrImages = $(this).parent().parent().parent().find('.image_holder ul li').children().size();
		if (thisid == 0) {
			$(this).parent().find('.prev_case').slideUp(350);
		}
		
		if (thisid > 0 && nrImages > 1) {
			$(this).parent().find('.prev_case').slideDown(350);
		}
		
		if (thisid >= 0 && thisid < (parseInt(nrImages)-1)) {
			$(this).parent().find('.next_case').slideDown(350);
		}
		
		if (thisid == (parseInt(nrImages)-1)) {
			$(this).parent().find('.next_case').slideUp(350);
		}
	});
	
	$('#werksection .slider article .popover .image_nav .next_case').click(function(){
		thisid = $(this).parent().find('.active').attr("id");
		nextid = parseInt(thisid) + 1;
		$(this).parent().find('.navbutton').removeClass("active");
		$(this).parent().parent().find('.image_holder ul').animate({
			"marginLeft": -(nextid * 533) +"px"
		},500, 'swing');
		$(this).parent().parent().find('.text_popover ul').animate({
			"marginLeft": -(nextid * 178) +"px"
		},500, 'swing');
		$(this).parent().find('.child'+nextid).addClass("active");
		
		nrImages = $(this).parent().parent().parent().find('.image_holder ul li').children().size();
		if (nextid == (parseInt(nrImages)-1)) {
			$(this).slideUp(350);
		}
		
		if (nextid >= 1) {
			$(this).parent().find('.prev_case').slideDown(350);
		}
	});
	
	$('#werksection .slider article .popover .image_nav .prev_case').click(function(){
		thisid = $(this).parent().find('.active').attr("id");
		nextid = parseInt(thisid) - 1;
		$(this).parent().find('.navbutton').removeClass("active");
		$(this).parent().parent().find('.image_holder ul').animate({
			"marginLeft": -(nextid * 533) +"px"
		},500, 'swing');
		$(this).parent().parent().find('.text_popover ul').animate({
			"marginLeft": -(nextid * 178) +"px"
		},500, 'swing');
		$(this).parent().find('.child'+nextid).addClass("active");
		
		nrImages = $(this).parent().parent().parent().find('.image_holder ul li').children().size();
		if (nextid < (parseInt(nrImages)-1)) {
			$(this).parent().find('.next_case').slideDown(350);
		}
		
		if (nextid == 0) {
			$(this).slideUp(350);
		}
	});
	
	window.werk.pathname = jQuery.url.segment(1);
	if (window.werk.pathname != null){
		$('div.popover.'+window.werk.pathname).find("img.lazyload").each(function() {
			$(this).attr("src", $(this).attr("original"));
			$(this).removeAttr("original");
		});
		$('div.popover.'+window.werk.pathname).slideDown(350);
		$('#popover_overlay').animate({
			'margin-left': 0,
			'width': '100%'
		}, 350, 'swing');
	}

/*KLANTEN*/
	
	window.klanten = {};
	window.klanten.total = $('#klantensection .slider').children().size();
	window.klanten.perPage = 16;
	window.klanten.nrDivs = Math.ceil(window.klanten.total / window.klanten.perPage);
	window.klanten.aantal = $('#klantensection .slider').children().size();
	
	i = 1;

	//alert(total+" "+perPage+" "+total%perPage)

	for (var x = 0; x < ((window.klanten.nrDivs * window.klanten.perPage) % window.klanten.total) ; x++) {
		$('#klantensection .slider').append('<article class="empty"></article>');
	}
	
	for (var x = 1; x <= window.klanten.nrDivs; x++) {
		$('#klantensection .slider').append('<div class="slide"></div>');
	}
	
	$('.slide').each(function(index) {
		for (var x = 0; x < window.klanten.perPage; x++) {
			$(this).append($('#klantensection .slider article').first());
		}
	});
	
	for (var x = 1; x <= window.klanten.nrDivs; x++) {
		$('#klantensection .navigation .navbuttons').append('<div class="navbutton button_'+(x-1)+'" id="'+(x-1)+'"></div>');
	}
	
	$('#klantensection .navigation .navbuttons .navbutton').first().addClass("active");
	width = (window.klanten.nrDivs * (12+9) );
	$('#klantensection .navigation .navbuttons').css({
		"width":  width+"px",
		"marginLeft": Math.round( -(width-9) /2 )
	});
	
	$('#klantensection .navigation .slideback').slideUp(0);

	if (window.klanten.nrDivs == 1){
		$('#klantensection .navigation .slidenext').slideUp(0);
	}

	window.klanten.thisslide = 0;
	
	$('#klantensection .navigation .navbuttons .navbutton').click(function(){
		if ($(this).hasClass("active")){
			
		} else {
			$('#klantensection .navigation .navbuttons .navbutton').removeClass("active");
			$(this).addClass("active");
			window.klanten.thisid = $(this).attr("id");
			window.klanten.thisslide = window.klanten.thisid;
			$('#klantensection .slider').animate({
				"marginLeft": -(window.klanten.thisid * 784)+20 +"px"
			},350);
			$('#klantensection .navigation .slideback').slideDown(350);
			$('#klantensection .navigation .slidenext').slideDown(350);
			if (window.klanten.thisid == 0){
				$('#klantensection .navigation .slideback').slideUp(100);
			}
			if (window.klanten.thisid == (window.klanten.nrDivs-1)){
				$('#klantensection .navigation .slidenext').slideUp(100);
			}
		}
	});
	
	$('#klantensection .navigation .slidenext').click(function(){
		window.klanten.thisslide++;
		$('#klantensection .slider').animate({
			"marginLeft": -((window.klanten.thisslide) * 784)+20 +"px"
		},350);
		$('#klantensection .navigation .slideback').slideDown(350);
		$('#klantensection .navigation .slidenext').slideDown(350);
		if (window.klanten.thisslide == 0){
			$('#klantensection .navigation .slideback').slideUp(100);
		}
		if (window.klanten.thisslide == (window.klanten.nrDivs-1)){
			$('#klantensection .navigation .slidenext').slideUp(100);
		}
		$('#klantensection .navigation .navbuttons .navbutton').removeClass("active");
		$('#klantensection .navigation .navbuttons .navbutton.button_'+ window.klanten.thisslide).addClass("active");
	});

	$('#klantensection .navigation .slideback').click(function(){
		window.klanten.thisslide--;
		$('#klantensection .slider').animate({
			"marginLeft": -((window.klanten.thisslide) * 784)+20 +"px"
		},350);
		$('#klantensection .navigation .slideback').slideDown(350);
		$('#klantensection .navigation .slidenext').slideDown(350);
		if (window.klanten.thisslide == 0){
			$('#klantensection .navigation .slideback').slideUp(100);
		}
		if (window.klanten.thisslide == (window.klanten.nrDivs-1)){
			$('#klantensection .navigation .slidenext').slideUp(100);
		}
		$('#klantensection .navigation .navbuttons .navbutton').removeClass("active");
		$('#klantensection .navigation .navbuttons .navbutton.button_'+ window.klanten.thisslide).addClass("active");
	});

/*WEB*/
	$('div#webpopover').slideUp(0);
	nrImages = $(this).find('#webpopover .image_holder ul li').children().size();
	for (var x = 1; x <= nrImages; x++) {
		$(this).find('#webpopover .image_nav').append('<div class="navbutton child'+(x-1)+'" id="'+(x-1)+'"></div>');
	}
	$(this).find('#webpopover .image_nav .prev_case').hide();
	if (nrImages == 1) {
		$(this).find('#webpopover .image_nav .next_case').hide();
	}
	
	$("header nav ul li a.website").click(function(){
        $(this).addClass('active');
		$('div#webpopover').slideDown(350);
		$('#popover_overlay').animate({
			'margin-left': 0,
			'width': '100%'
		}, 350, 'swing');
		$("div#webpopover .image_holder").find("img.lazyload").each(function() {
			$(this).attr("src", $(this).attr("original"));
			$(this).removeAttr("original");
		});
		$('div#webpopover .image_nav .navbutton').removeClass("active");
		$('div#webpopover .image_nav .child0').addClass("active");
		$('div#webpopover .image_holder ul').animate({
			"marginLeft": "0px"
		}, 0);
		$('div#webpopover .text_popover ul').animate({
			"marginLeft": "0px"
		}, 0);
		$('div#webpopover .prev_case').slideUp(0);
		$('div#webpopover .next_case').slideDown(0);
	});
	
	$('div#webpopover .close_popover, #popover_overlay').click(function(){
        $("nav ul li a.website").removeClass('active');
		$('div#webpopover').slideUp(350);
		$('#popover_overlay').animate({
			'margin-left': '-1px',
			'width': '1px',
		}, 350, 'swing');
	});
	
	
	$('div#webpopover .image_nav .next_case').click(function(){
		thisid = $(this).parent().find('.active').attr("id");
		nextid = parseInt(thisid) + 1;
		$(this).parent().find('.navbutton').removeClass("active");
		$(this).parent().parent().find('.image_holder ul').animate({
			"marginLeft": -(nextid * 533) +"px"
		},500, 'swing');
		$(this).parent().parent().find('.text_popover ul').animate({
			"marginLeft": -(nextid * 178) +"px"
		},500, 'swing');
		$(this).parent().find('.child'+nextid).addClass("active");
		
		nrImages = $(this).parent().parent().parent().find('.image_holder ul li').children().size();
		if (nextid == (parseInt(nrImages)-1)) {
			$(this).slideUp(350);
		}
		
		if (nextid >= 1) {
			$(this).parent().find('.prev_case').slideDown(350);
		}
	});
	
	$('div#webpopover .image_nav .prev_case').click(function(){
		thisid = $(this).parent().find('.active').attr("id");
		nextid = parseInt(thisid) - 1;
		$(this).parent().find('.navbutton').removeClass("active");
		$(this).parent().parent().find('.image_holder ul').animate({
			"marginLeft": -(nextid * 533) +"px"
		},500, 'swing');
		$(this).parent().parent().find('.text_popover ul').animate({
			"marginLeft": -(nextid * 178) +"px"
		},500, 'swing');
		$(this).parent().find('.child'+nextid).addClass("active");
		
		nrImages = $(this).parent().parent().parent().find('.image_holder ul li').children().size();
		if (nextid < (parseInt(nrImages)-1)) {
			$(this).parent().find('.next_case').slideDown(350);
		}
		
		if (nextid == 0) {
			$(this).slideUp(350);
		}
	});	
			
	$('div#webpopover .image_nav .navbutton').click(function(){
		$(this).parent().find('.navbutton').removeClass("active");
		$(this).addClass("active");
		thisid = $(this).attr("id");
		$(this).parent().parent().find('.image_holder ul').animate({
			"marginLeft": -(thisid * 533) +"px"
		},500, 'swing');
		$(this).parent().parent().find('.image_holder ul li div iframe').animate({
			"marginLeft": -(thisid * 533) +"px"
		},500, 'swing');
		$(this).parent().parent().find('.text_popover ul').animate({
			"marginLeft": -(thisid * 178) +"px"
		},500, 'swing');
		nrImages = $(this).parent().parent().parent().find('.image_holder ul li').children().size();
		if (thisid == 0) {
			$(this).parent().find('.prev_case').slideUp(350);
		}
		
		if (thisid > 0 && nrImages > 1) {
			$(this).parent().find('.prev_case').slideDown(350);
		}
		
		if (thisid >= 0 && thisid < (parseInt(nrImages)-1)) {
			$(this).parent().find('.next_case').slideDown(350);
		}
		
		if (thisid == (parseInt(nrImages)-1)) {
			$(this).parent().find('.next_case').slideUp(350);
		}
	});
});

(function() {
	var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
	po.src = 'https://apis.google.com/js/plusone.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
