/**
* Standaard functies/acties	
**/
$(document).ready(function(){
	$('#contact').validate();
});


/**
* 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);
		}
	});
	
	/**
	* Winkelwagen plus/min
	**/
	$('.cart .aantal').click(function(){
		var iID = $(this).attr('id');
		var sPage = window.location.pathname;
    var sArt = $(this).parent().parent().attr('id');
    
		if(iID=='aantal_plus'){
      $.post(sPage, { changeAmount:true, sArtikelcode:sArt,plus:true},
				function(data){
					location.reload();
				}
			);
		}
		if(iID=='aantal_min'){
			$.post(sPage, { changeAmount:true, sArtikelcode:sArt,minus:true},
				function(data){
					location.reload();
				}
			);
		}
		
	});
	
	/**
	* Verzendkosten bovenop de bestelling drukken
	**/
	function fixOrderOverzicht(){
		//checken of `t nodig is.
		if($('[name=verzendwijze]:checked').attr('rel')!=undefined){
			var sKosten = $('[name=verzendwijze]:checked').attr('rel');
			var sOrderSubTotaal = $('#subtotaal').html();
			var sOrderTotaal = ((sOrderSubTotaal*1)+(sKosten*1)).toFixed(2);
			$('#verzendkosten').html(sKosten);
			$('#totaal').html(sOrderTotaal);
		}
		else if($('[name=verzendwijze]').attr('rel')!=undefined){
			var sKosten = $('[name=verzendwijze]').attr('rel');
			var sOrderSubTotaal = $('#subtotaal').html();
			var sOrderTotaal = ((sOrderSubTotaal*1)+(sKosten*1)).toFixed(2);
			$('#verzendkosten').html(sKosten);
			$('#totaal').html(sOrderTotaal);
		}
	}
	//fixOrderOverzicht();
	$('[name=verzendwijze]').click(function(){
		//fixOrderOverzicht();
	});
	
	/**
	* Terug knop
	**/
	$('.btn_back').click(function(){
		history.back();
	});
	
});
