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

	
	/**
	* menutje
	**/
	$('.hoofdcat').mouseover(function(){
		$('#menu ul li ul').hide(100);
		$(this).parent().find('ul').show(100);
	});

});


/**
* 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 .imgDiv').click(function(){
		var sLinkDetail = $(this).parent().parent().find('.btnMoreInfo').attr('href');
		//alert(sElement);
		window.location.replace(sLinkDetail);
	});
	
	$('.article [name=add2cartImg]').click(function(){
		$(this).parent().parent().find('[name=add2cart]').trigger('click');
	});
	
	/**
	* 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);
		}
	});
	

	/**
	* ATTRIBUUT kleur - weergave kleurkaart en selectie
	.att_1 = kleurattribuut
	**/
	$('.att_1').click(function(){
		$(this).blur();
		var sName = $(this).attr('name');
		var iArtikelID = $(this).parent().parent().attr('id');
		$('#popupBoxCanvas').html('');
		$('option',this).each(function(){
			var sKleur = $(this).html();
			var iKleur = $(this).attr('value');
			var sKleurDiv = '<div class="kleurDiv">'; 
					sKleurDiv += '<img src="/images/attributen/'+jQuery.trim(sKleur)+'.jpg" title="'+jQuery.trim(sKleur)+'" alt="'+ sKleur +'" />';
					sKleurDiv += '<span id="id_kleur" style="display: none;">'+iKleur+'</span>';
					sKleurDiv += '<span id="id_artikel" style="display: none;">'+iArtikelID+'</span>';
				sKleurDiv += '</div>';
			$(sKleurDiv).appendTo($('#popupBoxCanvas')).get(0);
		});
		$('#container').fadeTo(300,0.2);
		$('#popupBox').fadeIn(300);
		
	});
	$('.kleurDiv').live('click',function(){
		var iKleurID = $('#id_kleur',this).html();
		var iArtikelID = $('#id_artikel',this).html();
		$('#'+iArtikelID+' .att_1').val(iKleurID);
		$('#container').fadeTo(300,1);
		$('#popupBox').fadeOut(300);
	});
});