$.fn.wait = function(time, type) {
	time = time || 750;
	type = type || "fx";
	return this.queue(type, function() {
		var self = this;
		setTimeout(function() {
			$(self).dequeue();
		}, time);
	});
};

// pre-submit callback 
function showRequest(formData, jqForm, options) { 
	$("#error").html('<p><img src="http://www.zippylistings.com/wp-content/themes/zippy/images/1-1.gif" width="16px" height="16px" /> Processing Listing. It may take a few seconds, we need to inform dozens of sites about your listing ...</p>');
	
	// change the subbmision button also (people may miss the above)
	$("#add-listing input.btn").attr("disabled", true);
	$("#add-listing input.btn").attr("value", "Processing...");
	return true;
} 
 
// post-submit callback 
function showResponse(responseText, statusText)  { 
    if (statusText != 'success' || responseText.fail == true){
		$("#error").html(decodeURI(decodeURIComponent(responseText.message)));
		// it failed, so unlock the submit button
		$("input.btn").attr("disabled", false);
		$("input.btn").attr("value", "Try Again");
	 } else { 
		$("#error").css({'color':'green'});
		$("#error").html('<p>Congratulations! Your Listing has been added. To see comments and feedback about your listing visit your <a href="'+responseText.url+'">listing page</a>. To add another listing <a href="http://zippylistings.com/">click here</a>.</p>');
		$("#add-listing").slideUp("slow");
		$("#entry_preview:hidden:first").html('<div class="shift"><div id="preview_image"><img src="'+responseText.image_url+'" width="100px" height="80px" /></div><h3><a href="'+responseText.url+'" title="'+responseText.title+'">'+responseText.title+'</a></h3><small>'+responseText.city+'</small><p><strong>FOR '+responseText.rentorsale.toUpperCase()+' <span class="light">&bull;</span> $'+responseText.price+' <br> '+responseText.size+' sq. ft. <span class="light">&bull;</span> Beds: '+responseText.bedrooms+' <span class="light">&bull;</span> Baths: '+responseText.baths+'</p></strong></div>').wait(500).slideDown("slow");
		//alert(responseText.parent);
		//alert('<div class="preview entry"><div id="preview_image"><img src="'+responseText.image_url+'" width="100px" height="80px" /></div><h3><a href="'+responseText.url+'" title="'+responseText.title+'">'+responseText.title+'</a></h3><small>'+responseText.city+'</small><p><strong>FOR '+responseText.rentorsale.toUpperCase()+' <span class="light">&bull;</span> $'+responseText.price+' <br> '+responseText.size+' sq. ft. <span class="light">&bull;</span> Beds: '+responseText.bedrooms+' <span class="light">&bull;</span> Baths: '+responseText.baths+'</p></strong></div>');
		if(responseText.parent == 'usa'){
			//$("#sidebar .lastest_listings #content_1 ul").prepend('<li><a href="'+responseText.url+'" title="You just added this listing!">'+responseText.title+'</a> '+responseText.rentorsale+'</li>').slideDown("slow");
		} else {
			//$("#sidebar .lastest_listings #content_2 ul").prepend('<li><a href="'+responseText.url+'" title="You just added this listing!">'+responseText.title+'</a> '+responseText.rentorsale+'</li>').slideDown("slow");
		}
	 }
	 return true;
}

$("form input.dimmed, form input.dimmed, form textarea.dimmed").focus(function () {
	if($(this).val() == 'http://www.site.com/'){
		$(this).val('http://www.');
	}else{
		$(this).val('');
	}
	$(this).removeClass('dimmed').addClass('light');
});

$(".jShow").css('display', 'block');
$(".jHidden").css('display', 'none');

$(document).ready(function(){
	// When a link is clicked
	$("a.tab").click(function () {
		// switch all tabs off
		$(".active").removeClass("active");
		// switch this tab on
		$(this).addClass("active");
		// slide all content up
		$(".content").hide();
		// slide this content up
		var content_show = $(this).attr("name");
		$("#"+content_show).fadeIn();	  
	});
	$('a#suggest-realtor_button').click(function() { 
		if($("#suggest-realtor_box").hasClass("hidden")){
			$("#suggest-realtor_box").slideDown().removeClass("hidden");	
		} else {
			$("#suggest-realtor_box").slideUp().addClass("hidden");	
		}
	});
	$("#header_login a.login").attr('href','#');
	$("#header_login a.login").click(function () {
		if ($("#header_login form").is(":hidden")) {
		$("#header_login form").slideDown(500);
		}else{
			$("#header_login form").slideUp(200);
		}
	});
});
