		var timer; // Global variable
		
		$(document).ready(function () {
			//vouwen();
			$('#zoekterm').click(function () {
				emptyZoeken(this);
			});

			// Functies voor initialiseren bestelknop met spinnerfunctie
			init_bestelbuttons();
			// $(".tabMenu").tabs();
			
			$(".popuplink").click(function () {
				var strProduct_rg = this.id;
				// http://www.ericmmartin.com/projects/simplemodal/
				$("#dialogcontent").load("/shop/ajax_detail.asp", {Product_rg: strProduct_rg}, function() {
					init_bestelbuttons();
					$(".tabMenu").tabs();
					});
				$("#dialog").modal({
					autoResize : true
				});
			});

			$('#checkBedragAll').click(function () {
				$('#bedragenUl').find(':checkbox').attr('checked', this.checked);
				laadproductenlijst();
			});

			$('#clearProductgroepenUl').click(function () {
				$('#productgroepenUl').find(':checkbox').attr('checked', false);
				laadproductenlijst_vertraagd();
			});

			$('.clearProduct_id').click(function () {
				$('#product_id').val('clear');
				$('#categorieImg').hide();
				laadproductenlijst_vertraagd();
			});

			$('#clearBedragenUl').click(function () {
				$('#bedragenUl').find(':checkbox').attr('checked', false);
				laadproductenlijst_vertraagd();
			});

			$('#wis_zoekterm').click(function () {
				$('#zoekterm').val('');
				laadproductenlijst();
			});

			$(".toonAlles").click(function () {
				var strSubgroep_rg = this.id.replace("toonalles_", "");
				$("." + strSubgroep_rg).toggleClass("Hidden");
				$("#aantal_" + strSubgroep_rg).html("");
			});
			
		   // Register keypress events on the whole document
		   $('#zoekterm').keypress(function(e) {
			  switch(e.keyCode) { 
				 // User pressed "enter"
				 case 13:
					laadproductenlijst_vertraagd();
					return false;
			  }
		   });
			
			$("#subgroepselect").change(function () {
				var sSubgroepURL = $(this).val();
				if (sSubgroepURL != '') {
					window.location = sSubgroepURL
				}
			});
			
			$(".addtofavorites").click(function () {
				var strProduct_rg = this.id.replace("fav_", "");
				$.ajax({
					type: "POST",
					url: "/shop/ajax_updatefavorieten.asp",
					data: "action=addProduct&product_rg="  + strProduct_rg,
					success: function() {
						alert("Product is opgeslagen in uw favorietenlijst");
					}
				})
			});
		});
		
		function init_bestelbuttons() {
			
			$(".bestelbutton").unbind('click');
			
			$(".bestelbutton").click(function () {

				var infoTekst;
				
				var strProduct_rg = this.id.replace("bestel_", "");
				strProduct_rg = strProduct_rg.replace("bestelmee_", "");
				var iAantal = document.getElementById("aantal_" + this.id).value;
				var d=new Date();
				$("#cart").load("/shop/bestellen/winkelwagen_ajax.asp", {ac: "add"
									, Product_rg: strProduct_rg
									, Aantal: iAantal
									, Tijdrandom: d.getMilliseconds()}
									, function() {
											init_winkelwagen();
											showCart();
									});
			})
			
			$(".bestelmeebutton").click(function () {
				$.modal.close();
			})
			
			$("img[src*='w=50&h=37']").unbind('thumbPopup');
			$("img[src*='w=50&h=37']").thumbPopup({
				imgSmallFlag: "w=50&h=37",
				imgLargeFlag: "w=150&h=111"
			});
			
			base_url = document.location.href.substring(0, document.location.href.indexOf('index.html'), 0);
		    
			$(".lightbox").lightbox({
			    fitToScreen: true,
			    imageClickClose: true
		    });

			$('.filterlijst li :checkbox').unbind('click');
			$('.filterlijst li :checkbox').click(function () {
				laadproductenlijst();
			});
			
			$('#zoekterm').click(function () {
				emptyDefaultText(this, 'Zoek op trefwoord');
			});
			
			$('#zoekterm').keydown(function() {
				emptyDefaultText(this, 'Zoek op trefwoord');
			});
			
			
			$('#btnzoeken').unbind('click');
			$('#btnzoeken').click(function(){
					
					laadproductenlijst();
			   });
			   
			init_winkelwagen()
		}
		
				
		function emptyDefaultText(inputbox, text){ 
			$(inputbox).css("color","black");
			if (inputbox.value.indexOf(text) > -1) {
			inputbox.value = inputbox.value.replace(text, '');
			}
		};
		// 
		
		function init_winkelwagen() {
			var options = { 
				target:        '.Quantity',   // target element(s) to be updated with server response 
				beforeSubmit:  showRequest,  // pre-submit callback 
				success:       showResponse,  // post-submit callback 
		 
				// other available options: 
				url:       '/shop/bestellen/winkelwagen_ajax.asp',         // override for form's 'action' attribute 
				type:      'post',        // 'get' or 'post', override for form's 'method' attribute 
				dataType:  'script'        // 'xml', 'script', or 'json' (expected server response type) 
				//clearForm: true        // clear all form fields after successful submit 
				//resetForm: true        // reset the form after successful submit 
		 
				// $.ajax options can be used here too, for example: 
				//timeout:   3000 
			}; 
					
			$('#opnieuwberekenenbutton').unbind('click');
			$('#opnieuwberekenenbutton').click(function() {
				$('#winkelwagenform').submit();
			});
			
			// http://www.malsup.com/jquery/form/#ajaxSubmit
			// bind to the form's submit event 
			$('#winkelwagenform').submit(function() { 
				// inside event callbacks 'this' is the DOM element so we first 
				// wrap it in a jQuery object and then invoke ajaxSubmit 
				$(this).ajaxSubmit(options); 
		 
				// !!! Important !!! 
				// always return false to prevent standard browser submit and page navigation 
				return false; 
			}); 

//			$(".infolink").click(function () {
//				var strProduct_rg = this.id;
//				$('#productenlijst').empty();
//				$("#contentLoading").show();
//				$("#productenlijst").load("/shop/ajax_detailpagina.asp", {ac: "add", Product_rg: strProduct_rg}, function() {
//					$("#contentLoading").fadeOut("fast");
//					init_bestelbuttons();
//					$(".tabMenu").tabs();
//					});
//			});


			$('.verwijderknop').unbind('click');
			$(".verwijderknop").click(function() {
				var strProduct_rg = this.id.replace("del_", "");
				strProduct_rg = strProduct_rg.replace("top_", "");
				document.getElementById("iQuantity" + strProduct_rg).value = 0;
				$('#winkelwagenform').submit();
			});
		}
		
		// pre-submit callback 
		function showRequest(formData, jqForm, options) { 
			// formData is an array; here we use $.param to convert it to a string to display it 
			// but the form plugin does this for you automatically when it submits the data 
			var queryString = $.param(formData); 
		 
			// jqForm is a jQuery object encapsulating the form element.  To access the 
			// DOM element for the form do this: 
			// var formElement = jqForm[0]; 
		 
			$('#cart').empty();
			// alert('About to submit: \n\n' + queryString); 
		 
			// here we could return false to prevent the form from being submitted; 
			// returning anything other than false will allow the form submit to continue 
			return true; 
		} 
		 
		// post-submit callback 
		function showResponse(responseText, statusText)  { 
			// for normal html responses, the first argument to the success callback 
			// is the XMLHttpRequest object's responseText property 
		 
			// if the ajaxForm method was passed an Options Object with the dataType 
			// property set to 'xml' then the first argument to the success callback 
			// is the XMLHttpRequest object's responseXML property 
			//alert(responseText);
			// if the ajaxForm method was passed an Options Object with the dataType 
			// property set to 'json' then the first argument to the success callback 
			// is the json data object returned by the server 
			
		} 

		
		function ajax_turbozoeker() {
			// turboresult.load();
			var zoekterm = $("#zoekterm").val();
			$('#turboresult').empty();
			$("#turbocontentLoading").show();
			$("#turboresult").load("/shop/ajax_turbozoeker.asp", {zoekterm: zoekterm}, function() {$("#turbocontentLoading").fadeOut("fast");});
		}
		
		function emptyZoeken(tekstwaarde){ 
			if (tekstwaarde.value == 'Zoeken...')
				{ document.getElementById('zoekterm').value = ''; }
		};
		
		function empty_turboresult(){
			$('#turboresult').empty();
		}

		function ajax_turbozoeker_toonmeer() {
			empty_turboresult;
			window.location = "/shop/productenlijst.asp?zoektype=trefwoord&zoekterm=" + $("#zoekterm").val();
		}
		
		function showCart()
		{
			document.getElementById("winkelwagentotalenTable").style.display = 'none';
			document.getElementById("winkelwagendetailsTable").style.display = '';
		}
		
		function hideCart()
		{
			document.getElementById("winkelwagentotalenTable").style.display = '';
			document.getElementById("winkelwagendetailsTable").style.display = 'none';
		}
		
		function setPageNumber(pageNumber){
		   $("#page").val(pageNumber);
		   laadproductenlijst_vertraagd();
		}
		


			$(function(){
					   
				// Tabs
				$("#tabs").tabs();
				$("#tabs-3").show();
				// Accordion
				$("#accordion").accordion({ 
					header: "h3",
					active: false,
					collapsible: true,
					autoHeight: false
					});

				// Show one of the accordion blocks.		
				// if (location.hash.toLowerCase().length > 1) {
				// 	$('#accordion').accordion('activate', 'h3#' + location.hash.toLowerCase());
				// } else {
				// 	$('#accordion').accordion('activate', 'h3:first');
				// }
				
				//hover states on the static widgets
				$('#dialog_link, ul#icons li').hover(
					function() { $(this).addClass('ui-state-hover'); }, 
					function() { $(this).removeClass('ui-state-hover'); }
				);
				
			});

	function Calclength(textlengte)
	{
		maxlengte = 254
		if (textlengte.Opmerkingen.value.length > maxlengte)
			{
			textlengte.Opmerkingen.value = textlengte.Opmerkingen.value.substring(0,maxlengte)
			}
	}