$(function(){
	
	// Show blockquote cites
	$("blockquote").each(function(){
		var title = $(this).attr("title");
		var cite = $(this).attr("cite");
		
		if (cite == '' && title != '') {
			$(this).append("<cite class='source'>&mdash; "+title+"</cite>");
		} else if (cite != '' && title == '') {
			$(this).append("<cite class='source'>&mdash; <a href='"+cite+"' title='"+cite+"'>"+cite+"</a></cite>");
		} else if (cite != '' && title != '') {
			$(this).append("<cite class='source'>&mdash; <a href='"+cite+"' title='"+title+"'>"+title+"</a></cite>");
		} else {
		}
		
	});
	
	// Beautiful ampersands
	$("*:contains('&')", document.body).contents().each(
		function() {
		if( this.nodeType == 3 ) {
			$(this)
			.replaceWith( this
			.nodeValue
			.replace( /&/g, "<span class='amp'>&</span>" )
			);
		}
	});

	// Opacity effect on showcase
	$("#showcase article").fadeTo("fast", 0.6);
	$("#showcase article").hover(
		function () { $(this).fadeTo("normal", 1); },
		function () { $(this).fadeTo("normal", 0.6);	}
	);
	
	// Ajax for Contact form
	$("#contact #submit").click(function() { 
		$('#contact input, #contact textarea').attr('disabled', true).fadeTo("fast", 0.5);
		$('#contact-container').load('/wp-content/themes/html5/contact-form.php', {
			nombre: $("#nombre").val(), 
			email: $("#email").val(), 
			texto: $("#texto").val(), 
		});
		return false;
	});
	
});
