// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
jQuery(document).ready(function(){
	jQuery("textarea#standard_listing_description").maxLength(250);
	jQuery("textarea#enhanced_listing_description").maxLength(1000);
	
	jQuery("input.business_checkbox").toggle_on_select(jQuery("input.individual_checkbox"));
	jQuery("input.individual_checkbox").toggle_on_select(jQuery("input.business_checkbox"));
	
	jQuery("#enhanced_listing_swappable, #standard_listing_swappable").click(function(){
		jQuery(this).set_visibility_of_will_trade_for_box()
	});
	jQuery("#enhanced_listing_swappable").set_visibility_of_will_trade_for_box();
	jQuery("#standard_listing_swappable").set_visibility_of_will_trade_for_box();

	// Initialize Facebox
  $('a[rel*=facebox]').facebox();
});

jQuery.fn.set_visibility_of_will_trade_for_box = function(){
	if (this.is(":checked")) {
		this.parent().next().show("slow")
	} else {
		this.parent().next().hide("slow")
	}
}

jQuery.fn.toggle_on_select = function(other_box){
	var this_box = this;
	other_box.attr('checked', !this_box.attr('checked'));
	this.click(function(){
		other_box.attr('checked', !this_box.attr('checked'));
	});
};

jQuery.fn.load_image_in_main_box = function(image_url){
	this.html("<img src='" + unescape(image_url) + "' />")
}

function showSpinner() {
	$('img.spinner').show();
}