$(document).ready(function() {

	$("ul.homepage-tabs a").click(function() {
		$(this).parent(0).parent(0)
			.removeClass("tickets")
			.removeClass("hotels")
			.removeClass("vacation-rentals");

		$(this).parent(0).parent(0).addClass($(this).parent(0).attr("class"));

		$("div#tickets-flip,div#hotels-flip,div#vacation-rentals-flip").addClass("hide");

		if ($(this).parent(0).attr("class") == "tickets")
		{
			$("div#home-left div#tickets-flip").removeClass("hide");
		}
		else if ($(this).parent(0).attr("class") == "hotels")
		{
			$("div#home-left div#hotels-flip").removeClass("hide");
		}
		else if ($(this).parent(0).attr("class") == "vacation-rentals")
		{
			$("div#home-left div#vacation-rentals-flip").removeClass("hide");
		}

		return false;
	});

	$("input#rs_city")
		.autocomplete(
			"/ajax/get-dropdown-results-city.xml",{
			delay:0,
			minChars:3,
			matchContains:true,
			matchSubset:false,
			max:100,
			scrollHeight:160,
			width:364
		});

	$("input#tickets-q")
		.autocomplete(
			"/ajax/get-dropdown-results-ticket.xml",{
			delay:0,
			minChars:3,
			matchContains:true,
			matchSubset:false,
			max:100,
			scrollHeight:225,
			width:396,
			formatItem:function(row,current_row,row_count) {
				if (row[0].substr(0,2) == "c^")
				{
					return "<span class=\"small\">&nbsp;</span> " + row[0].substr(2);
				}
				else if (row[0].substr(0,2) == "t^")
				{
					return "<span class=\"small\">Team</span> " + row[0].substr(2);
				}
				else if (row[0].substr(0,2) == "e^")
				{
					return "<span class=\"small\">Event</span> " + row[0].substr(2);
				}
				else
				{
					return row[0].substr(2);
				}
			},
			formatMatch:function(row,current_row,row_count) {
				return row[0].substr(2);
			},
			formatResult:function(row) {
				return row[0].substr(2);
			}
		})
		.result(function(event,item) {
			var type_value;

			if (item[0].substr(0,2) == "t^")
			{
				type_value = "team";
			}
			else if (item[0].substr(0,2) == "e^")
			{
				type_value = "event";
			}
			else if (item[0].substr(0,2) == "c^")
			{
				type_value = "category";
			}
			else
			{
				type_value = "unknown";
			}

			$("input#tickets-type").val(type_value);
		});

	$("input#properties-q")
		.autocomplete(
			"/ajax/get-dropdown-results-city.xml",{
			delay:0,
			minChars:3,
			matchContains:true,
			matchSubset:false,
			max:100,
			scrollHeight:160,
			width:396
		});

	$("a.hotels-go")
		.click(function() {
			$("form.hotels-search-form").submit();
			return false;
		});

	$("a.tickets-go")
		.click(function() {
			$("form.tickets-search-form").submit();
			return false;
		});

	$("a.properties-go")
		.click(function() {
			$("form.properties-search-form").submit();
			return false;
		});

});