if (Drupal.jsEnabled) {
  Drupal.behaviors.test = function() {
      // price variables
   var minprice = $('input#edit-field-wd-ppc-value-min');
   var maxprice = $('input#edit-field-wd-ppc-value-max');
   // Set default values or use those passed into the form
   var init_min_price = ('' == minprice.val()) ? 500 : minprice.val();
   var init_max_price = ('' == maxprice.val()) ? 22000 : maxprice.val();
   // Set initial values of the slider
    minprice.val(init_min_price);
    maxprice.val(init_max_price);
   //weight variables
   var minweight = $('#edit-field-wd-weight-value-min');
   var maxweight = $('#edit-field-wd-weight-value-max');
   // Set default values or use those passed into the form
   var init_min_weight = ('' == minweight.val()) ? 0.1 : minweight.val();
   var init_max_weight = ('' == maxweight.val()) ? 10 : maxweight.val();
   // Set initial values of the slider
   minweight.val(init_min_weight);
   maxweight.val(init_max_weight);
 // depth variables
   var mindepth = $('#edit-field-wd-depth-value-min');
   var maxdepth = $('#edit-field-wd-depth-value-max');
   // Set default values or use those passed into the form
   var init_min_depth = ('' == mindepth.val()) ? 0 : mindepth.val();
   var init_max_depth = ('' == maxdepth.val()) ? 80 : maxdepth.val();
   // Set initial values of the slider
   mindepth.val(init_min_depth);
   maxdepth.val(init_max_depth);
    //table variables
   var mintable = $('#edit-field-wd-table-value-min');
   var maxtable = $('#edit-field-wd-table-value-max');
   // Set default values or use those passed into the form
   var init_min_table = ('' == mintable.val()) ? 0 : mintable.val();
   var init_max_table = ('' == maxtable.val()) ? 90 : maxtable.val();
   // Set initial values of the slider
   mintable.val(init_min_table);
   maxtable.val(init_max_table);
// Insert the slider before the min/max input elements
if($('#price-slider').length==0){
    $('#edit-field-wd-ppc-value-min').parents('div.fieldset-wrapper').before(
	    $('<div id="price-slider"></div>').slider({
        range: true,
        min: 500,     // Adjust slider min and max to the range
        max: 22000,    // of the exposed filter.
		step: 100,
		values: [init_min_price, init_max_price],
        slide: function(event, ui) {
          // Update the form input elements with the new values when the slider moves
          $('#edit-field-wd-ppc-value-min').val(ui.values[0]);
          $('#edit-field-wd-ppc-value-max').val(ui.values[1]);
        },
		stop: function(event, ui){
                    $(this).parents('form').submit();
                  }
      })
    );      
}
//weight
if($('#weight-slider').length==0){
 $('#edit-field-wd-weight-value-min').parents('div.fieldset-wrapper').before(
        $('<div id="weight-slider"></div>').slider({
        range: true,
        min: 0.1,     // Adjust slider min and max to the range
        max: 10,    // of the exposed filter.
		step: 0.1,
        values: [init_min_weight ,init_max_weight],
        slide: function(event, ui){
          // Update the form input elements with the new values when the slider moves
         minweight.val(ui.values[0]);
         maxweight.val(ui.values[1]);
		  },
		stop: function(event, ui){
                    $(this).parents('form').submit();
      }
      
      })
    );      // Add .hide(
}
//depth 
if($('#depth-slider').length==0){
   $('#edit-field-wd-depth-value-min').parents('div.fieldset-wrapper').before(
      $('<div id="depth-slider"></div>').slider({
        range: true,
        min: 0,     // Adjust slider min and max to the range
        max: 80,    // of the exposed filter.
		step: 1,
        values: [init_min_depth, init_max_depth],
        slide: function(event, ui){
          // Update the form input elements with the new values when the slider moves
         mindepth.val(ui.values[0]);
         maxdepth.val(ui.values[1]);
		  },
		stop: function(event, ui){
                    $(this).parents('form').submit();
                  }
       
      })
    );      // Add .hide(
}
//table	
if($('#table-slider').length==0){
   $('#edit-field-wd-table-value-min').parents('div.fieldset-wrapper').before(
      $('<div id="table-slider"></div>').slider({
        range: true,
        min: 0,     // Adjust slider min and max to the range
        max: 90,    // of the exposed filter.
		step:1,
        values: [init_min_table, init_max_table],
        slide: function(event, ui){
          // Update the form input elements with the new values when the slider moves
         mintable.val(ui.values[0]);
         maxtable.val(ui.values[1]);
        },
		stop: function(event, ui){
                    $(this).parents('form').submit();
                  }
      })
    );      // Add .hide(
}
	minprice.keyup(function() {
		  $("#price-slider").slider("values" , 0, parseInt($(this).val()));
		  $(this).parents('form').submit();
		  });
	maxprice.keyup(function() {
	   $("#price-slider").slider("values" , 1, parseInt($(this).val()));
	   $(this).parents('form').submit();
	   });
//weight slider	
	minweight.keyup(function() {
		 $("#weight-slider").slider("values" , 0, parseFloat($(this).val()));
		 $(this).parents('form').submit();
		 });
	maxweight.keyup(function() {
		$("#weight-slider").slider("values" , 1, parseFloat($(this).val()));
		$(this).parents('form').submit();
		});
	// depth slider
	mindepth.keyup(function() {
		 $("#depth-slider").slider("values" , 0, parseInt($(this).val()));
		 $(this).parents('form').submit();
	     });
	maxdepth.keyup(function() {
		 $("#depth-slider").slider("values" , 1, parseInt($(this).val()));
		 $(this).parents('form').submit();
         });
	//table slider
   mintable.keyup(function() {
	    $("#table-slider").slider("values" , 0, parseInt($(this).val()));
		$(this).parents('form').submit();
		});
   maxtable.keyup(function() {
		$("#table-slider").slider("values" , 1, parseFloat($(this).val()));
		$(this).parents('form').submit();
		});
	 };
}



