	refreshtopbar = function(){
		tb_remove();
		// If there is any dynamic content on the page refresh instead of reloading the topbar.
		// Makes sure everything is updated.
		if ($('.dynamic').size()){ location.reload(true); }

		$('tr.topbar').load("/resources/ajax.asp?section=TopBar");
	};
	
	inputBG = function(id,focus){
		
		if ( focus || $('#' + id).val() != '') { $('#' + id).css('background','#fff');}
		else {
			$('#' + id).css('background',"#fff url('/images/" + id + "_bg.gif') center left no-repeat");
		}
	};
	
	addFav = function(id){
		$.get("/resources/ajax.asp",
		{ section: "AddFav", listing: id},
		function(data,txtStatus){
			switch (data) {
				case "0":
					document.location="/favorites.asp";
					//$.jGrowl("You must be logged in to use favorites.");
					break;
				case "-2":
					//$.jGrowl("This listing is already in your favorites.");
				case "-1":
					$("#"+id+" img.fav").attr("src","/images/favorite_star_20_added.png");
					$("#"+id).attr("background","url('/images/favorite_star_20_added.png') top left no-repeat")
					$('tr.topbar').load("/resources/ajax.asp?section=TopBar");
					break;
				case "-3":
					alert("Your user account is disabled.");
					//$.jGrowl("Your user account is disabled.");
					break;
				case "-4":
					alert("There was an error while adding a listing to your favorites.");
					//$.jGrowl("There was an error while adding a listing to your favorites.");
					break; 
			}
		} );
	};
	
	delFav = function(id){
		$.get("/resources/ajax.asp",
			{ section: "DelFav", listing: id},
			function(resData,txtStatus){
				 $('tr.topbar').load("/resources/ajax.asp?section=TopBar");
				 $("#biz_count").text(resData);
			}
		);
		// Clear out the rows that make up a record
		$("#"+(id)).parent().parent().next().toggle();
		$("#"+(id)).parent().parent().toggle();
	};
	
	editSwap = function(){
		tb_show("","/resources/edit-submit.asp?TB_iframe=true&height=300&width=400","");
	};
	
	// Declare a variable for Autocomplete
	var auto_city;
	
	$(document).ready(function(){
		
		//$.jGrowl.defaults.closer = false;
		//$.jGrowl.defaults.position = "center"; 
		inputBG('txtSearch',false);
		inputBG('txtCityZip',false);
		
		$('.favbox img').bind("mouseover",function(e){
			if ( $(this).attr("src") == "/images/favorite_star_20.png" ) {
				$(this).attr("src","/images/favorite_star_20_add.png");
			}
		});
		$('.favbox img').bind("mouseout",function(e){
			if ( $(this).attr("src") == "/images/favorite_star_20_add.png" ) {
				$(this).attr("src","/images/favorite_star_20.png");
			}
		});
		$('.unfavbox img').bind("mouseover",function(e){
			if ( $(this).attr("src") == "/images/favorite_star_20.png" ) {
				$(this).attr("src","/images/favorite_star_20_del.png");
			}
		});
		$('.unfavbox img').bind("mouseout",function(e){
			if ( $(this).attr("src") == "/images/favorite_star_20_del.png" ) {
				$(this).attr("src","/images/favorite_star_20.png");
			}
		});
		
		if ($('#txtCityZip').size()){
			auto_city = $('#txtCityZip').autocomplete({ serviceUrl:'/resources/ajax.asp', minChars: 2, params: { section:'CityAuto' } });
		}
		
		if ($('#txtCity').size() && $('#selState').size()){
			$('#state_abbr').val($('#selState option:selected').text());
			auto_city = $('#txtCity').autocomplete({ 
				serviceUrl:'/resources/ajax.asp', 
				minChars: 2,
				params: { section:'CityAuto', state:$('#selState ').val() } });
			$('#selState').bind('change',function(){
				// Update the State Abbreviation
				$('#state_abbr').val($('#selState option:selected').text());
				// Reset the autocomplete when the state changes.
				auto_city.setOptions({ params: { section:'CityAuto', state:$('#selState ').val() } });
				auto_city.clearCache();
			});
		
		}
		
		
		// Make the calendar table cells clickable
		if ($('#calendar_mini').size()){
			$('#calendar_mini td.events').live('click',function(){
				location.href = $(this).find('a').attr('href');});
			$('#calendar_mini td.events').live('hover',function(){ $(this).toggleClass('hover');});
		}
		
		// Adjust the Thickbox window height on Google Maps to fit in the viewport if the window is short.
/*
		if($(window).height() < 700){
			var mapHeight = $(window).height() - 70;
			mapHeight = mapHeight < 300 ? 300 : mapHeight;	// Minimum height if you have a tiny viewport.
			$("a.googlemap").each(function(){
				$(this).attr('href',function(){
					return (this + "").replace("&height=600","&height=" + mapHeight);
				});
			});
		}
*/		
		
		if ($('.bottomlinks').size()){
			$('.bottomlinks').each(function(index,el){
				$this = $(el);
				var tdheight = $this.parent().parent().height();
				var myheight = $this.height();
				$this.css({'top': (tdheight - myheight) + "px"});
			});
		}
	});