$( function() {
	
// -------------------- Main wheel selector --------------------	
	$("#makerSelectorGallery").change( function() {
		$("#modelSelectorGallery").children().remove().end()
			.append('<option selected value="-">Select MODEL</option>')

		// target must output content-type: text/xml for IE to work
		$.post("spitxml.php", {
			maker :this.value
		}, function(xml) {
			$("model", xml).each(
				function() {
					var optn = '<option value="'
						+ $(this).find('id').text() + '">'
						+ $(this).find('name').text()
						+ '</option>\n';
					$("#modelSelectorGallery").append(optn);
				});
		});
	});
	$("#modelSelectorGallery")
	.change(
		function(i) {
			// Set the left model box to match this one
			$("#galleryForm").submit();
		});
});

function fixUrl(textToFix) {
	var regexp = /[^a-z0-9 \-]|-$/g;
	rewrite = textToFix.replace(regexp, '');
	regexp = / +|-{2,}/g;
	rewrite = rewrite.replace(regexp, "_");
	regexp = /-$/g;
	rewrite = rewrite.replace(regexp, "");
	return rewrite;
}


