$(document).ready(function(){						   	   	clear_inputs_on_focus();	clean_get_forms();	init_print();	$('img').bind('click', function(e) {			if (e.button == 3) {				return false;			}		}).bind("contextmenu", function(e) {                e.preventDefault();            });;		if($('#frm-filters').length > 0) { 		init_filters();	}	if($('#product-view-switch').length > 0) {		init_productViewSwitch();	}	if($('#product-list').length > 0) {		init_sorters();	}			if($.fancybox) {		$(".photo-album a").fancybox({			'transitionIn'	:	'elastic',			'transitionOut'	:	'elastic',			'easingIn'      :	'easeOutBack',			'easingOut'     :	'easeInBack',			'speedIn'		:	400, 			'speedOut'		:	400, 			'overlayShow'	:	true		});	}	$('.product-button').css("cursor", "pointer").hover( function() { $(this).addClass('hover') }, function(){ $(this).removeClass('hover')  } ).click(entireDivClick);	$('.catalogus-button').css("cursor", "pointer").hover( function() { $(this).addClass('hover') }, function(){ $(this).removeClass('hover')  } ).click(entireDivClick);//	$('#product-list th.cell-quality ').click(entireDivClick).hover( function() { $(this).parent('tr').addClass('hover') }, function() { $(this).parent('tr').removeClass('hover') });	$('#news-items .news-item, .search-result, #product-list-related tr').click(entireDivClick).hover( function() { $(this).addClass('hover') }, function() { $(this).removeClass('hover') });//	$('#product-view-switch #switch_view a').click(switch_view_product_list);	init_product_hover_img();}); 	function init_product_hover_img() { 		$('.product-specs td img').hover(function() { if(!$(this).hasClass('no')){ showVisual(this)} } ).hover( function() { $(this).parents('tr').addClass('hover') }, function() { $('#nvs_product_popup').remove(); $(this).parents('tr').removeClass('hover') });		$('#product-list td img').hover(function() { if(!$(this).hasClass('no')){ showVisual(this)}  }).hover( function() { $(this).parents('tr').addClass('hover') }, function() { $('#nvs_product_popup').remove(); $(this).parents('tr').removeClass('hover') });		$('#product-visual').mouseover(function() { showLargerVisual(this) });	}	 	function do_product_sort() { 		a_link = $(this).find("a"); 		 		if (this.className == 'cell-name') { 			// sorteren op naam	 		if (a_link.hasClass("desc")) {	 			new_sort = 'ASC';	 		} else {	 			new_sort = 'DESC';	 		}			$("#frm-filters #frm_orderby").val('naam');			$("#frm-filters #frm_order").val(new_sort); 			 		} 				getFilterResults();		return false; 	}	function showVisual (obj) {		$('#nvs_product_popup').remove();		objOffset = $(obj).offset();		objOffset.top = parseInt(objOffset.top - 233 +49);		objOffset.left = objOffset.left + 300;				$('<div></div>').attr({ id: 'nvs_product_popup'	}).css({top: objOffset.top, left: objOffset.left }).appendTo('body');		source = $(obj).attr('src')		source = source.substring(0, (source.length-5)) +'l.jpg';			$('<img></img>').attr({ src: source, width: 295 , height: 225 }).appendTo('#nvs_product_popup')	}		function showLargerVisual (obj) {		$('#nvs_product_popup').remove();		objOffset = $(obj).offset();		objOffset.top = parseInt(objOffset.top) - 4;		objOffset.left = $(window).width() - objOffset.left - $(obj).width() - 5;				$('<div></div>').attr({ id: 'nvs_product_popup'	}).css({top: objOffset.top, right: objOffset.left }).appendTo('body').mouseout(function() {$('#nvs_product_popup').remove(); });		source = $(obj).attr('src')		source = source.substring(0, (source.length-5)) +'l.jpg';			$('<img></img>').attr({ src: source, width: 294 , height: 225 }).appendTo('#nvs_product_popup')	}		function init_productViewSwitch() {		$('#frm-num-products').show();		$('#product-view-switch a.list').click(function() { 			$('#frm_field_view').val('list');			getFilterResults();			return false;		});		$('#product-view-switch a.photo').click(function() { 			$('#frm_field_view').val('photo');			getFilterResults();			return false;		});		$('#frm-select-num-products').change(function() { 			$('#frm_field_resultsperpage').val($(this).val());			getFilterResults();			return false;		});	}		function init_sorters() {		// $('#product-list th.cell-name ').click(do_product_sort);	}		function init_filters() {		$('#filter-box').show();		$('#frm-filters li:not(.pop)').hide();		$('#frm-filters fieldset a.more').show().click(function() { showMore_filters(this); return false; })		$('#frm-filters fieldset a.less').hide().click(function() { showLess_filters(this); return false; })		$('#frm-filters input:checkbox').click( function() { getFilterResults();  })				$('.sliderfieldset').each( function(index) { 			// begin en eind waarde ophalen uit de hidden fields 			startValue = $(this).find('.hiddenStartVal').val();			endValue = $(this).find('.hiddenEndVal').val();						startValue_preselected = $(this).find('.hiddenStartVal_preselected').val();			endValue_preselected = $(this).find('.hiddenEndVal_preselected').val();						if (startValue_preselected > 0) {				slider_start_value = startValue_preselected;			} else {				slider_start_value = startValue;			}			if (endValue_preselected > 0) {				slider_end_value = endValue_preselected;			} else {				slider_end_value = endValue;			}						// Uniek Id creeëren voor de slide zodat deze eenvoudig terug te vinden is via scripting			sliderId = 'slider' + index;			$(this).find('.slider').attr( 'id', sliderId);						// De begin en eind waardes plaatsen onder de slider			$(this).find('.sliderstart').text(FormatNumberBy3(startValue, ",", "."));			$(this).find('.sliderend').text(FormatNumberBy3(endValue, ",", "."));									if((endValue - startValue) >= 1 && (endValue - startValue) < 10) {				step_size = 0.1;				min_val = parseFloat(startValue)				max_val = parseFloat(endValue);											} else if ((endValue - startValue) < 1) {				step_size = 0.01;				min_val = parseFloat(startValue)				max_val = parseFloat(endValue);											} else {				step_size = 1;				min_val = parseInt(startValue)				max_val = parseInt(endValue);			}																					// Slider function aanroepen (jquery UI http://jqueryui.com/demos/slider/) 			$('#'+sliderId).slider({				range: true,				min: min_val,				max: max_val,				step: step_size,				values: [slider_start_value, slider_end_value],				slide:  function(event, ui) {										// sliderId variable is niet global dus moeten we even ophalen uit de ui.handle.parentNode					mySliderId = ui.handle.parentNode.id										vals = ui.values;								// Nu we het id hebben kunnen we de nieuwe waardes als text velden boven de sliders plaatsen					$('#'+mySliderId+' .ui-slider-handle:first').html(FormatNumberBy3(vals[0], ",", "."));					$('#'+mySliderId+' .ui-slider-handle:last').html(FormatNumberBy3(vals[1], ",", "."))				},				stop: function(event, ui) {										vals = ui.values;									// gestop met schuiven nu kunnen we de hidden formfields in voeren (niet tijdens het slide-en ivm performance)					// sliderId moeten we ook hier even ophalen uit de ui.handle.parentNode					mySliderId = ui.handle.parentNode.id;					$('#'+mySliderId).parent().siblings('.hiddenStartVal').val(FormatNumberBy3(vals[0], ",", "."));					$('#'+mySliderId).parent().siblings('.hiddenEndVal').val(FormatNumberBy3(vals[1], ",", "."));										// tijd voor ajax !!					getFilterResults();				}			});			// Slider is geïnitialiseerd nu de beginwaardes van de slider even in de slide handles plaatsen			vals = $('#'+sliderId).slider( "values" );								$(this).find('.ui-slider-handle:first').html(FormatNumberBy3(vals[0], ",", "."));			$(this).find('.ui-slider-handle:last').html(FormatNumberBy3(vals[1], ",", "."));			$(this).find('.ui-slider-handle:last').addClass('ui-silder-handle-end');		})					// de selects kunnen we verwijderen		$('.pricerange').remove();				// sliders kunnen worden getoond		$('.slider-container, .sliderstart, .sliderend').show('0');			}		function getFilterResults() {		var currentTime = new Date();		var t = currentTime.getTime();    if($('#product-ajax-container').length > 0) { 		  w =	$('#product-ajax-container').width();		  h =	$('#product-ajax-container').height();    } else {                             		  w =	$('#productvariaties-ajax-container').width();		  h =	$('#productvariaties-ajax-container').height();    }		$('#product-ajax-loader').css({ position: 'absolute', background: '#fff url(/img/ajax-loader.gif) no-repeat center center', width: w, height: h });		$('#product-ajax-loader').show();		$('#product-ajax-loader').animate({'opacity': 0.7}, 250);		$.get('/ajax/producten_selectie.ajax.php?t='+t, $("#frm-filters").serialize(), function(data) {			$('#' + data.target_div).html(data.html);			$('#product-ajax-loader').animate({'opacity': 0.0}, 250);			$('#product-ajax-loader').hide();			init_productViewSwitch();			init_sorters();			init_product_hover_img();		}, "json");	}		function showLess_filters(jObj) {		$(jObj).parent().find('li:not(.pop)').stop(true, true).fadeOut(500).find(':checkbox').attr("checked",false);		$(jObj).hide();		$(jObj).siblings('.more').show();		return false;	}		function showMore_filters(jObj) {		$(jObj).parent().find('li').stop(true, true).fadeIn(500);		$(jObj).hide();		$(jObj).siblings('.less').show();		return false;		}	// make entire elm	function entireDivClick () {		if($(this).find("a").attr("target") == '_blank'){			window.open($(this).find("a").attr("href"));		}else{			window.location=$(this).find("a").attr("href");		}		return false;	}// Clear input fields on focus	function clear_inputs_on_focus () {		$("input[type=text].clear").focus(function () { 			if(!$(this).attr("startvalue")) {  				$(this).attr("startvalue", $(this).val());			} 			if($(this).val() == $(this).attr("startvalue")) {				$(this).val('');				}		}).blur(function () { 			if($(this).val() == '') {				$(this).val($(this).attr("startvalue"));			}		});	}	// Clean form GET so they don't pass x & y params in the  url.	function clean_get_forms () {		$('form[method=get] input[type=image]').click(function() {			this.form.submit();			return false;		});			}// Show the print button only when it is on the page and printing is available	function init_print () {		if (window.print && $("#print-btn").length > 0 ) {			$("#print-btn").show()			$("#print-btn").click(function () { 				window.print();				return false;			});		};		}		function submit_itemperpage(aantal) {		$("#items_per_page").val(aantal);		$("#frm-filters").submit();	}					function FormatNumberBy3(num, decpoint, sep) {			// FUNCTIE BEWUST UITGEZET! GAF NIET ALTIJD GOEDE WAARDEN TERUG (soms dubbele puntjes .. ) EN WELLICHT		// FOUT OPGEVANGEN DOOR PHP BIJ HET DOORSTUREN VAN DUIZENDTALLEN (bv 2.000)		return num;		  // check for missing parameters and use defaults if so	  if (arguments.length == 2) {	    sep = ",";	  }	  if (arguments.length == 1) {	    sep = ",";	    decpoint = ".";	  }	  	  	  // need a string for operations	  num = num.toString();	  // separate the whole number and the fraction if possible	  a = num.split(decpoint);	  x = a[0]; // decimal	  y = a[1]; // fraction	  z = "";			  if (typeof(x) != "undefined") {	    // reverse the digits. regexp works from left to right.	    for (i=x.length-1;i>=0;i--)	      z += x.charAt(i);	    // add seperators. but undo the trailing one, if there	    z = z.replace(/(\d{3})/g, "$1" + sep);	    if (z.slice(-sep.length) == sep)	      z = z.slice(0, -sep.length);	    x = "";	    // reverse again to get back the number	    for (i=z.length-1;i>=0;i--)	      x += z.charAt(i);	    // add the fraction back in, if it was there	    if (typeof(y) != "undefined" && y.length > 0)	      x += decpoint + y;	  }	  return x;	}		
