		var timer; // Global variable
		
		$(document).ready(function () {
		 
			// Functies voor initialiseren de turbozoeker
			

			$('#turbosearch').click(function () {
				emptyZoeken(this);
			});

			$('#turbosearch').keypress(function (e) {
				emptyZoeken(this);
				clearTimeout(timer);
				timer = setTimeout("ajax_turbozoeker()", 4000);
			});
			
	
			// 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", {ac: "add", Product_rg: strProduct_rg}, function() {
					init_bestelbuttons();
					$(".tabMenu").tabs();
					});
				$("#dialog").modal({
					autoResize : true
				});
			});


		   // Register keypress events on the whole document
		   $('#zoekterm').keypress(function(e) {
			  switch(e.keyCode) { 
				 // User pressed "enter"
				 case 13:
					laadproductenlijst();
					return false;
			  }
		   });
			
			
			$(".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");
					}
				})
			});
		
		    $('#slideshow').cycle({
					speed:       1000,
					timeout:     7000,
					pager:      '#nav',
					pagerEvent: 'mouseover',
				pauseOnPagerHover: true
				});

			
		});
		
		
			$.fn.centerInClient = function(options) {
				/// <summary>Centers the selected items in the browser window. Takes into account scroll position.
				/// Ideally the selected set should only match a single element.
				/// </summary>    
				/// <param name="fn" type="Function">Optional function called when centering is complete. Passed DOM element as parameter</param>    
				/// <param name="forceAbsolute" type="Boolean">if true forces the element to be removed from the document flow 
				///  and attached to the body element to ensure proper absolute positioning. 
				/// Be aware that this may cause ID hierachy for CSS styles to be affected.
				/// </param>
				/// <returns type="jQuery" />
				var opt = { forceAbsolute: false,
							container: window,    // selector of element to center in
							completeHandler: null
						  };
				$.extend(opt, options);
			   
				return this.each(function(i) {
					var el = $(this);
					var jWin = $(opt.container);
					var isWin = opt.container == window;

					// force to the top of document to ENSURE that 
					// document absolute positioning is available
					if (opt.forceAbsolute) {
						if (isWin)
							el.appendTo("body");
						else
							el.appendTo(jWin.get(0));
					}

					// have to make absolute
					el.css("position", "absolute");

					// height is off a bit so fudge it
					var heightFudge = isWin ? 2.0 : 1.8;

					var x = (isWin ? jWin.width() : jWin.outerWidth()) / 2 - el.outerWidth() / 2;
					var y = (isWin ? jWin.height() : jWin.outerHeight()) / heightFudge - el.outerHeight() / 2;

					el.css("left", x + jWin.scrollLeft());
					el.css("top", y + jWin.scrollTop());

					// if specified make callback and pass element
					if (opt.completeHandler)
						opt.completeHandler(this);
				});
			}
			

		
		function init_bestelbuttons() {
			$(".spinnerinput").spinner({max:999, min: 1});
			
			$(".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() {
//											alert("hier het nieuwe sscherm");
											$("#toegevoegdBericht").show();
											$("#toegevoegdBericht").centerInClient();
											setTimeout("$(document.getElementById('toegevoegdBericht')).slideUp('fast')", 2400);
//											alert("Het artikel is toegevoegd aan de winkelwagen.");
//											$.modal.close();
											init_winkelwagen();
									});
			})
			
			$(".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();
			});
			
			$('#btnzoeken').unbind('click');
			$('#btnzoeken').click(function(){
					laadproductenlijst_vertraagd();
			   });
			   
			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 
				failure:       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 
			}; 
		
		function init_winkelwagen() {

			
			$('#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; 
			}); 

			$('.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]; 
			$("#opnieuwladen").show();
			//$('#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 
			$("#opnieuwladen").hide();
			// 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 
			// 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 
			//showCart();
		} 
		
		
		function ajax_turbozoeker() {
			// var position = $("#turbosearch").position();
			// $('#turboresult').css({top: position.top+20, left: position.left});
			
			// var turbosearch = $("#turbosearch").val();
			// $('#turboresult').empty();
			// if (turbosearch.length >= 3) {
				// $("#turbocontentLoading").show();
				// $("#turboresult").load("/shop/ajax_turbozoeker.asp", {zoekterm: turbosearch}, function() {$("#turbocontentLoading").fadeOut("fast");});
			// }
		}
		
		function emptyZoeken(tekstwaarde){ 
			if (tekstwaarde.value == 'Zoeken...')
				{ document.getElementById('turbosearch').value = ''; }
		};
		
		function empty_turboresult(){
			$('#turboresult').empty();
		}
		
		function checkTurbo() {
			
			var turbosearch = $('#turbosearch').val();
			if (turbosearch.length < 3) {
				alert('Geef een zoekterm van minimaal 3 karakters.');
				return false;
			}
			else {
				return true;
			}
		}

		function ajax_turbozoeker_toonmeer() {
			empty_turboresult;
			window.location = "/shop/productenlijst.asp?zoektype=trefwoord&turbosearch=" + $("#turbosearch").val();
		}
		
		function showCart()
		{
			document.getElementById("winkelwagentotalenTable").style.display = 'none';
			document.getElementById("winkelwagendetailsTable").style.display = 'block';
		}
		
		function hideCart()
		{
			document.getElementById("winkelwagentotalenTable").style.display = 'block';
			document.getElementById("winkelwagendetailsTable").style.display = 'none';
		}
	
	function Calclength(textlengte)
	{
		maxlengte = 254
		if (textlengte.Opmerkingen.value.length > maxlengte)
			{
			textlengte.Opmerkingen.value = textlengte.Opmerkingen.value.substring(0,maxlengte)
			}
	}
	
	