/**
* Standaard functies/acties	
**/
$(document).ready(function(){
	$('#contact').validate();
	
	
	/**
	* menu functionaliteiten
	**/
	$('.nav ul li').each(function(){
		if($(this).parent().attr('class')!='actief'){
			$(this).hide();
		}
	})
	$('.nav .hoofditem').click(function(){
		var aantalChildren = $(this).parent().find('ul').children().size();
		if(aantalChildren==0){
			return true;
		}
		if($(this).attr('class')=='hoofditem'){
			$(this).parent().find('ul').children().toggle(300);
			return false;
		}
		else{
			return true;				
		}	
	});
	
});

/**
* GALLERY functionaliteiten
**/
$(document).ready(function(){
	$("#thumbsHolder img").click(function(){
		var newImgSrc = $(this).attr("src");
		var newInfo = $(this).attr("id")+"info";
		var toAppend = $("#"+newInfo).html();
		$("#bigImg, #infoToAppend").fadeOut(150,function(){
			$("#infoToAppend").html(toAppend);
			$("#bigImg").attr("src",newImgSrc);
			$("#bigImg, #infoToAppend").fadeIn(100);			
		});
	});
});

/**
* WEBSHOPFUNCTIES
**/
$(document).ready(function(){
	/**
	* Forms valideren
	**/
	$('#form1').validate();
	$('#form2').validate();
	$('#form3').validate();
	
	/**
	* Via ajax een artikel verwijderen uit de winkelwagen
	**/
	$(".removeFromCart").click(
		function(){
			var id= $(this).parent().attr('id');
			var deleteRow = '#tr' + id;
			$.post('/shop/ajax_removeFromCart.php', { id: id },
				function(data){
					if(data.response == 1){
						$(deleteRow).fadeOut('fast');
						/*
						ALLEEN ALS JE BTW/SUBTOTAAL WILT WEERGEVEN IN DE WINKELWAGEN.
						$("#subtotaal").html(data.subtotaal);					
						$("#btw").html(data.btwbedrag);
						*/ 
						$("#totaal").html(data.totaal);
						if(data.aantal=='0'){
							$("#messageSpan").html("Er staan geen producten in uw winkelwagen.");
							$("#doorgaanKnop").fadeOut('fast');							
						}
					}else{
						alert("Er is een fout opgetreden.");
					}
				}, "json"
			);
		}
	);	
	
	/**
	* Loguitknop
	**/
	$('#loguitKnop').click(function() {
	  var url = $("#loguitKnop").attr('href');
	  window.location=url;
	  return false;
	})
	
	/**
	* Lightbox voor artikelfoto`s
	**/
	$('.imgDiv a').lightBox();
	
	/**
	* add review weergeven
	**/
	$('#addReview').hide(0);
	$('#addReviewBtn').click(function(){
		$('#addReviewBtn').hide(300);
		$('#addReview').show(300);
	});
	
	/**
	* Meer informatie knop. Klik op hele div, door naar de detailpagina
	**/
	$('.article img').click(function(){
		var sLinkDetail = $(this).parent().parent().find('.btnMoreInfo').attr('href');
		//alert(sElement);
		window.location.replace(sLinkDetail);
	});
	
	/**
	* Account pagina orderdetails weergeven wanneer er op de order wordt geklikt
	**/
	$('.order').click(function(){
		var orderTag = $(this).attr('id');
		var orderDetailTag = orderTag+'_details';
		var sDisplay = $('#'+orderDetailTag).css('display');
		if(sDisplay=='none'){
			$('#'+orderDetailTag).fadeIn(200);
		}
		else{
			$('#'+orderDetailTag).fadeOut(200);
		}
	});
});
