(function($){
	$(function(){
		var $product_finder = $('#product_finder');
		var $make = $product_finder.find('.make select').attr('disabled', true);
		var $model = $product_finder.find('.model select').attr('disabled', true);
		var $year = $product_finder.find('.year select').attr('disabled', true);
		var url = '/inc_global/js/application_json.asp?category='+ $product_finder.find('#Category').val() +'&';
		
		var PopulateSelect = function(parSelect, parURL){
			$.getJSON(parURL, function(j){
				var options = ['<option value="">Please Choose</option>'];
				for (var i = 0; i < j.length; i++) {
        			options.push('<option value="' + j[i].value + '">' + j[i].text + '</option>');
      			}
				if(options.length > 1){
					$(parSelect).html(options.join('')).attr('disabled', false).find('option:first').attr('selected','selected').end().trigger('change');
					if ($product_finder.is(':hidden')) { 
						$product_finder.show(); 
						if ($.browser.msie) {
								$('#footer').css('marginTop', $product_finder.height() +'px');
						}
					}
				}
				else {
					$(parSelect).attr('disabled', true);
				}
			});
		};
		
		$make.change(function(){ $model.attr('disabled', true); if ($make.val()==''){ return; } PopulateSelect($model, url +'make='+ $make.val()); });
		$model.change(function(){ $year.attr('disabled', true); if ($model.val()==''){ return; } PopulateSelect($year, url +'make='+ $make.val() +'&model='+ $model.val()); });

		PopulateSelect($make, url);

	});
})(jQuery);
