$(document).ready(function() {
	$('#Inventory-Content').html('<p id="Inventory-Loading">Loading Inventory...</p>');
	$('#Inventory-Content').load('utils/curl.php .click, .normal', {}, function() {
		// This is the first column
		$('span.normal').not('span.normal:first').before('<hr />');
		$('span.normal').each(function(e) {
			$(this).css({
				"clear":		"left",
				"float":		"left",
				"margin":		"10px 10px 30px 60px"
			});
		});
		// This is the second column
		$('div.left').each(function(e) {
			if($(this).text().indexOf('per page') > 1) {
				$(this).remove();
			}
			$(this).css({
				"margin":		"10px 0px 30px 0px",
				"width":		"300px"
			});
		});
		// This is the third column
		$('div.normal').each(function(e) {
			$(this).css({
				"margin":		"40px 0px 30px 0px",
				"width":		"420px"
			});
		});
		// This is for the Year and Make & Model
		$('span.normal > b, div.left > div > b').each(function(e) {
			$(this).replaceWith('<h3>' + $(this).text() + '</h3>');
		});
		$('div.left > div > br').each(function(e) {
			$(this).remove();
		});
		// The is the "Features" section
		$('.little').each(function(e) {
			if($(this).text().length <= 23) {
				$(this).remove();
			}
			if($(this).width() == '300') {			// This width must match the width set for div.left (on line 20)
				$(this).prepend('<h4>Features:</h4>').before('<br />');
				$(this).css({
					"margin":		"0px",
					"width":		"420px",		// This width must match the width set for div.normal (on line 24)
					"padding":		"5px",
					"background": 	"#F4F4F4",
					"border":		"1px solid #AAAAAA"
				});
			}
		});
		// This is for "call for price"
		$('.dColumn > span[style*="-x-system-font: none;"]').each(function(e) {
			$(this).removeAttr('style').html('<a href="Contact">Ask for Price</a>');
		});
		// This adds containers for text to the Mileage, Price, and Color sections
		$('.dColumn').each(function(e) {
			$(this).html('<span style="float: left;"><b></b></span>' + $(this).html());
		});
		// This fills the text containers with the corresponding text
		$('.dColumn').each(function(e) {
			if($(this).width() == '90') {
				if($(this).html().indexOf('$') > 1 || $(this).html().indexOf('price') > 1) {	// Price
					$('span > b', this).text('Price: ');
				} else {																		//Mileage
					$('span > b', this).text('Mileage: ');
				}
			} else if($(this).width() == '100') {
				$('span > b', this).text('Color: ');
			}
		});
		// This sets the formatting of the Mileage, Price, and Color sections
		// This must be done after text is added
		$('.dColumn').each(function(e) {
			$(this).css({
				"text-align":	"right",
				"width":		"180px"
			});
		});
		// These are all things that need to be removed
		$('input, table, .column, .center').each(function(e) {
			$(this).remove();
		});
		// Everything has been processed; display the inventory
		$('#Inventory-Loading').hide();
	});
});