$.extend(jQuery, new Toolbar());
function Toolbar() {
	$.extend($.blockUI.defaults.overlayCSS, { backgroundColor: '#E4F2F9' });
	var MAX_PRICE = 500;
	
	$(document).ready(function(){
		var tbox = $('#mtypes').get(0);
		if(tbox.options[tbox.selectedIndex].value == 'other'){
			$('div.slider, #price, #pcv').block();
			$('.blockUI').css('cursor', 'auto');
		}
		
		$('.slider').Slider({
			accept:'.indicator',
			onSlide:function(px, py, x, y){
				var cd = parseInt(MAX_PRICE * (px/100));
				if(cd == 0 && tbox.options[tbox.selectedIndex].value != 'other'){
					$('#pcv').html('Any');
				}else{
					if(tbox.options[tbox.selectedIndex].value == 'job'){
						$('#pcv').html('<span style="position:relative;top:-2px">&rsaquo;</span> $'+cd);
					}else if(tbox.options[tbox.selectedIndex].value != 'other'){
						$('#pcv').html('<span style="position:relative;top:-2px">&lsaquo;</span> $'+cd);
					}
				}
			},
			onChange:function(px, py, x, y){
				if(parseInt(MAX_PRICE * (px/100)) == 0 || tbox.options[tbox.selectedIndex].value == 'other'){
					$('#priceval').remove();
				}else{
					$('#priceval').remove();
				$('#SearchForm').append('<input id="priceval" type="hidden" name="p" value="'+parseInt(MAX_PRICE * (px/100))+'" />');
				}
			}
		});
	});
	
	this.updateCategories = function(){
		var tbox = $('#mtypes').get(0);
		var cbox = $('#ctypes').get(0);
		var val = tbox.options[tbox.selectedIndex].value;
		var opcount = 0;
		switch(val){
			case 'item':
				$('div.slider, #price, #pcv').unblock();
				while(cbox.length > 0){
					cbox.options[0] = null;
				}
				for(x in item_categories){
					if(x != 'indexOf'){
						cbox.options[opcount] = new Option(item_categories[x], x);
						opcount++;
					}
				}
				$('#price').html('Price: ');
				break;
			case 'housing':
				$('div.slider, #price, #pcv').unblock();
				while(cbox.length > 0){
					cbox.options[0] = null;
				}
				for(x in housing_categories){
					if(x != 'indexOf'){
						cbox.options[opcount] = new Option(housing_categories[x], x);
						opcount++;
					}
				}
				$('#price').html('Cost:');
				break;
			case 'job':
				$('div.slider, #price, #pcv').unblock();
				while(cbox.length > 0){
					cbox.options[0] = null;
				}
				for(x in job_categories){
					if(x != 'indexOf'){
						cbox.options[opcount] = new Option(job_categories[x], x);
						opcount++;
					}
				}
				$('#price').html('Pay:');
				break;
			case 'other':
				$('div.slider, #price, #pcv').block();
				$('.blockUI').css('cursor', 'auto');
				$('#priceval').remove();
				while(cbox.length > 0){
					cbox.options[0] = null;
				}
				for(x in other_categories){
					if(x != 'indexOf'){
						cbox.options[opcount] = new Option(other_categories[x], x);
						opcount++;
					}
				}
				break;
			case 'all':
				$('div.slider, #price, #pcv').block();
				while(cbox.length > 0){
					cbox.options[0] = null;
				}
				cbox.options[0] = new Option('Any', 'any');
				break;
		}
	}
	
	this.dropdownType = function(){
		$('#_category_dropdown').hide();
		$('#type_dropdown').toggle();
	}
	
	this.dropdownCategory = function(){
		$('#type_dropdown').hide();
		$('#_category_dropdown').toggle();
	}
}
