var aPrices = new Array();

 jQuery(document).ready(function() {

	 jQuery("#exm_ps_minprice").html(exm_ps_current_minvalue);
	 jQuery("#exm_ps_maxprice").html(exm_ps_current_maxvalue);
	 jQuery("#exm_ps_form_minprice").val(exm_ps_current_minvalue);
	 jQuery("#exm_ps_form_maxprice").val(exm_ps_current_maxvalue);
	
	 jQuery.getJSON("exm_priceslider/ajax_funcs.php?method=get_product_count&catid="+catid+
		"&minprice="+exm_ps_min+"&maxprice="+exm_ps_max, 
		function(json) {
			 jQuery.each(json.products, function(i,product)
			{
				aPrices.push(product.price);
			});
			
			exm_ps_countproducts(exm_ps_current_minvalue, exm_ps_current_maxvalue);
			 jQuery("#exm_ps_loading_panel").hide();
			 jQuery("#exm_ps_active_panel").show();
	});

});

 jQuery(function() {
	 jQuery("#exm_priceslider_range").slider({
		range: true,
		min: exm_ps_min,
		max: exm_ps_max,
		step: exm_ps_step,
		values: [exm_ps_current_minvalue, exm_ps_current_maxvalue],
		slide: function(event, ui) {
			 jQuery("#exm_ps_minprice").html(ui.values[0]);
			 jQuery("#exm_ps_maxprice").html(ui.values[1]);
			
			 jQuery("#exm_ps_form_minprice").val(ui.values[0]);
			 jQuery("#exm_ps_form_maxprice").val(ui.values[1]);
			
			exm_ps_countproducts(ui.values[0], ui.values[1]);
		}
	});
});

function exm_ps_countproducts(pricemin, pricemax)
{
	var productcount = 0;
	
	for (var i = 0; i < aPrices.length; i++)
	{
		if ((aPrices[i] >= pricemin) && (aPrices[i] <= pricemax))
			productcount++;
	}
	
	 jQuery("#exm_ps_productcount_label").html(productcount);
	if (productcount > 0)
	{
		 jQuery("#exm_ps_products_available").show();
		 jQuery("#exm_ps_no_products_available").hide();
	}
	else
	{
		 jQuery("#exm_ps_products_available").hide();
		 jQuery("#exm_ps_no_products_available").show();
	}
}

