
	// jquery scripts
	$(document).ready(function () {

		// lightbox laten werken
		$('a.lightbox').lightBox();
		
		// slideshow
		$('div#slides').cycle({ 
		    fx:    	'scrollDown',
		    speed:  3000,
			timeout:  10000,
		    before: changetab,
		    pause: true 
		 });
		 
		 $('#zoekenSelect').change(function(){
			var url = $('#zoekenSelect').val();
			window.location.href = url;
		 });
		 
		 // Standaard tekst uit forms halen
		 $('input#id_naam').focus( function() {
			if($(this).val() == 'Email:'){
				$(this).val('');
				$(this).css({'color' : 'black'});
			}
		 });
		 
		 $('input#id_onderwerp').focus( function() {
			if($(this).val() == 'Onderwerp:'){
				$(this).val('');
				$(this).css({'color' : 'black'});
			}
		 });
		 
		 $('textarea#id_bericht').focus( function() {
			if($(this).html() == 'Bericht:'){
				$(this).html('');
				$(this).css({'color' : 'black'});
			}
		 });
		 
		 $('input#id_naam').blur( function() {
			if($(this).val() == ''){
				$(this).val('Email:');
				$(this).css({'color' : '#c8c8c8'});
			}
		 });
		 
		 $('input#id_onderwerp').blur( function() {
			 if($(this).val() == ''){
				$(this).val('Onderwerp:');
				$(this).css({'color' : '#c8c8c8'});
			}
		 });
		 
		 var listItems = $("#boodschappenlijst").children();
		 var aantalListItems = listItems.length;
		 var bestelKnop = '<a id="bestelKnop" style="display:none; color:black" href="offerteaanvraag/">Uw bestelling of offerte aanvragen &raquo;</a>';
		 
		 if(aantalListItems > 0) {
			$('#boodschappenlijst').after(bestelKnop);
			$('#bestelKnop').show();
		}
		
		if(aantalListItems == 0) {
			var bericht = '<div id="message"><p style="font-size:11px;">Uw bestellijst is leeg...</p><p style="font-size:11px;>U kunt producten toevoegen door een aantal in te vullen en op het winkel mandje te klikken.</p></div>';
			$('#boodschappenlijst').after(bericht);
		}
		
		// Winkel wagentje
		//toevoegen aan wagentje
		$('img[id^=add]').click(function() {
						
			var itemId = this.id.substr(4);
			var aantal = $('input#aantal_'+itemId).val();
			if(aantal > 0) {
				$.ajax({
				   type: "POST",
				   url: "includes/actions/winkelwagen.php",
				   data: "id="+itemId+"&aantal="+aantal+"&actie=add",
				   dataType: "json",
				   success: function(jsonData){
						var itemToAdd = '<li style="display:none;" id="itemId_'+jsonData.productwagenId+'"><div class="aantal">'+jsonData.aantal+' </div><div class="product">'+jsonData.titel+'</div><div class="actie"><img id="remove_'+jsonData.productwagenId+'" src="images/basket_delete.png" /></div></li>';
						var bestelKnop = '<a id="bestelKnop" style="display:none; color:black" href="offerteaanvraag/">Uw bestelling of offerte aanvragen &raquo;</a>';
						var listItems = $("#boodschappenlijst").children();
						var aantalListItems = listItems.length;
						
						$('#boodschappenlijst').append(itemToAdd);
						$('#itemId_'+jsonData.productwagenId).slideDown();
						
						if(aantalListItems == 0) {
							$('#boodschappenlijst').after(bestelKnop);
							$('#bestelKnop').slideDown();
							$('#message').slideUp('normal', function(){
								$('#message').remove();
							});
							
						}
						
						// Click functie aan het verwijder knopje binden
						$('#remove_'+jsonData.productwagenId).bind("click", function() {
							verwijderProductUitWagentje(jsonData.productwagenId);
						});
					}
				});
				$('input#aantal_'+itemId).val('0');
			}
		});
		
		$('img[id^=remove]').click(function() {
			var itemId = this.id.substr(7);
			verwijderProductUitWagentje(itemId);
		});
		
		//Item uit het wagentje verwijderen
		function verwijderProductUitWagentje(id) {
			$.ajax({
			   type: "POST",
			   url: "includes/actions/winkelwagen.php",
			   data: "id="+id+"&actie=remove",
			   success: function(){
					$('#itemId_'+id).slideUp('normal', function(){
						$(this).remove();
					});
				}
			});
			
			var listItems = $("#boodschappenlijst").children();
			var aantalListItems = listItems.length;	
			if(aantalListItems == 1) {
				$('#bestelKnop').slideUp('normal', function(){
					$('#bestelKnop').remove();
				});
								
				var bericht = '<div style="display:none;" id="message"><p style="font-size:11px;">Uw bestellijst is leeg...</p><p style="font-size:11px;>U kunt producten toevoegen door een aantal in te vullen en op het winkel mandje te klikken.</p></div>';
				$('#boodschappenlijst').after(bericht);
				$('#message').slideDown();
				}
		}
		
		
		$('img#addBuffet').click(function() {
			var aantal = $('input#aantalBuffet').val();			
			var itemId = $("input#buffetvdWeek").val();
			var Ids = itemId.split('|');
			
			for(i in Ids){
				if(aantal > 0) {
					$.ajax({
					   type: "POST",
					   url: "includes/actions/winkelwagen.php",
					   data: "id="+Ids[i]+"&aantal="+aantal+"&actie=add",
					   dataType: "json",
					   success: function(jsonData){
							var itemToAdd = '<li style="display:none;" id="itemId_'+jsonData.productwagenId+'"><div class="aantal">'+jsonData.aantal+' </div><div class="product">'+jsonData.titel+'</div><div class="actie"><img id="remove_'+jsonData.productwagenId+'" src="images/basket_delete.png" /></div></li>';
							var bestelKnop = '<a id="bestelKnop" style="display:none; color:black;" href="offerteaanvraag/">Uw bestelling of offerte aanvragen &raquo;</a>';
							var listItems = $("#boodschappenlijst").children();
							var aantalListItems = listItems.length;
							
							$('#boodschappenlijst').append(itemToAdd);
							$('#itemId_'+jsonData.productwagenId).slideDown();
							
							if(aantalListItems == 0) {
								$('#boodschappenlijst').after(bestelKnop);
								$('#bestelKnop').slideDown();
								$('#message').slideUp('normal', function(){
									$('#message').remove();
								});
								
							}
							
							// Click functie aan het verwijder knopje binden
							$('#remove_'+jsonData.productwagenId).bind("click", function() {
								verwijderProductUitWagentje(jsonData.productwagenId);
							});
						}
					});
					$('input#aantalBuffet').val('0');
				}
			}
			
			window.location = 'index.php';
		});

	});

	
	// var tabIndex = 1;
	function changetab() { 
		
		var tabs = 3;
		
		if ($('div#tabs ul li').is('.active')) { 
			
			//console.log('de class bestaat');
			var activeTabId = $('div#tabs ul li.active').attr('id');	
			var activeTabIndex = activeTabId.substr(3);
			var newActiveIndex = parseFloat(activeTabIndex) + 1;
			
			if(newActiveIndex > tabs){
				var newActiveTabId = 'tab1';
			} else {
				var newActiveTabId = 'tab'+ newActiveIndex;	
			}
			
			
			$('li#'+ activeTabId).removeClass("active");
			$('li#'+ newActiveTabId).addClass("active");
											
		} else { 

			//console.log('de class bestaat niet');
			var activeTabId = 'tab1';
			$('li#'+ activeTabId).addClass("active");						
		}				

	}
	
	
	// voor het gebruik van exotische font gebruiken we Cufon
	// Cufon('h1')('h2')('#mainmenu ul li a')('#submenu ul li a');	
