$(document).ready(function(){
	// Stripe our tables and lists whenever we need to
	$(".striped li:even, .striped tr:even").addClass("alt-row");

	// Allow for toggling of the summary text not shown by default	
	$("p#summary-lead a").click(function() {
		$("div.summary-more").toggle();
		return false;
	});

	// Allow for toggling of the author biography text not shown by default
	$("p#author-lead a").click(function() {
		$("div.author-more").toggle();
		return false;
	});
	
	// Allow for toggling of the staff review text not shown by default
	$("p#staff-review-lead a").click(function() {
		$("div.staff-review-more").toggle();
		return false;
	});
	$("h5#staff-review-head a").click(function() {
		$("div.staff-review-more").toggle();
		return false;
	});

	// Remove last slash in the category navigation
	$("#breadcrumb-nav li:last").addClass("last");

	// Trigger the radio buttons and highlighted class on the Buy It Now flow
	$("#product-cart input").click(function() {
		// Here, we click on the radio button, then select the parent to add a class to that item and remove the class from the siblings
		$(this).parent().addClass("selected").siblings().removeClass("selected");
	});

	// If no option is selected in the cart...
	if (!$("#product-cart input:checked").attr("checked")) {
		// Auto-select the first option in the cart
		$("#product-cart input:first").attr("checked", true);
	}
	// Add colored stripe to the selected option
	$("#product-cart input:checked").parent().addClass("selected");

	// Take the search form input field and if clicked on, clear the default text
	$("#search-term").focus(function() { 
		if ( $(this).val() == "Search by title, author, or ISBN...") {
			$(this).val("").removeClass("default");
		}
	});
	
	// If a visitor clicks in the search field, and clicks out without entering a new term, display the default text		
	$("#search-term").blur(function() { 
		if ( $(this).val() == "") {
			$(this).val("Search by title, author, or ISBN...").addClass("default");
		}
	});
/*	
	// Enable the selecting of the different formats
	$(".formats-toolbar ul li a").click(function() {
		$(this).parent().addClass("selected").siblings().removeClass("selected");
		return false;
	});

	// Control the four tabs that filter our browsing results. Apply the class to the clicked item and remove it from it's siblings.
	$("#ebook-filters li").click(function() {
		$(this).addClass("current").siblings().removeClass("current");
		return false;
	});
*/

	// Show or hide state controls in user profile settings 
	changeState = function() {
		$("#states_US, #states_CA, #states_ALL").hide();
		c = $("select#country").val();
		if (c != "US" && c != "CA") c = "ALL";
		$("#states_"+c).css("display","inline");
		$("input#state").val( $("#states_"+c).val());
	};
	$("form#profile select#country").change(changeState).change();
	$("form#profile input#submit").click(changeState);
	
	// Show or hide relevant input elements while selecting the payment method
	$("#payment-info [name=payment_method]").change(function() {
		if ($("#payment-info [name=payment_method] option:selected").text() == "PayPal") {
			$("#payment-info .cc-details").hide();
		} else {
			$("#payment-info .cc-details").show();
		}
	}).change();
	
});