(function ($) {
	jQuery.fn.extend({
		sliderBar: function (newopts) {
			this.each(function () {
				var $this = $(this);
				if ($this.data("sliderInit")) {
					return;
				}
				$this.data("sliderInit", true);

				var inputs = null;

				var opts = $.extend({
					range: true,
					min: 0,
					change: function (event, ui) {
						var lowValue = $(this).slider("values", 0);
						var highValue = $(this).slider("values", 1);
						inputs.attr('disabled', 'disabled');
						if (opts.min != lowValue | opts.max != highValue)
							for (var i = lowValue; i <= highValue; i++)
								$(inputs.get(i)).removeAttr('disabled');

						var input = $(opts.displayInputSelector),
						val = input.val();
						input.val(inputs.get(lowValue).title + ((lowValue == highValue) ? "" : " - " + inputs.get(highValue).title));
						if (val != $(opts.displayInputSelector).val()) {
							input.triggerEvent("change");
						}
					}
				}, newopts, $this.ParseClass(true));

				inputs = $('input[name="' + opts.inputSelector + '"]');
				if (!opts.max)
					opts.max = inputs.length - 1;

				if (!opts.values)
					opts.values = [0, inputs.length - 1];

				$(opts.seeAllSelector).click(function () {
					$this.slider("values", 0, opts.min);
					$this.slider("values", 1, opts.max);
					return false;
				});
                
				try{
				$(opts.displayInputSelector).val(inputs.get(opts.min).title + ((opts.min == opts.max) ? "" : " - " + inputs.get(opts.max).title));  // Initial values of inputSelector box
				}
				catch(e){}
				$this.slider(opts);
			});
			return this;
		}
	});

	$.sliderBar = {
		init: function (sel) {
			$(sel || "div.sliderRange").sliderBar();

		}
	};
	$(document).ready(function () {
		$.sliderBar.init();
	});


})(jQuery);

