$(document).ready(function(){
	
	$("input.populate").each( function(){
		if ( $(this).val() == "" ) {
			$(this).val( $(this).attr("title") );
		}
	});
	$("input.populate").focus(function(){ 
		if ( $(this).val() == $(this).attr("title") ) {
			$(this).val("");
		}
	});
	$("input.populate").blur(function(){ 
		if ( $(this).val() == "" ) {
			$(this).val( $(this).attr("title") );
		}
	});
	
	var location = "" + window.location;
	if ( location.indexOf('#apply') == -1 ) {
		$("#apply").hide();
	}
	$('a[href="#apply"]').click(function(){
		$("#apply").show("slide");
	});
	
	// Encrypt Email Addresses
	$(".replace").each(function(){
		var ats, dots, address, i;
		ats = [ ' at ', ' (at) ', ' [at] ' ];
		dots = [ ' dot ', ' (dot) ', ' [dot] ' ];
		address = $(this).html();
		for ( i = 0; i < ats.length; i++ ) {
			address = address.replace(ats[i], '@');
		}
		for ( i = 0; i < dots.length; i++ ) {
			address = address.replace(dots[i], '.');
		}
		$(this).html('<a href="mailto:' + address + '">' + address + '</a>');
	});

	
	// Send to Friend message
	if ( $("#sendtofriend #your-name").val() != '' ) {
		$("#friendmessage span.yourname").html( $("#sendtofriend #your-name").val() );
	}
	else {
		$("#friendmessage span.yourname").html( "[Your Name]" );
	}
	$("#sendtofriend #your-name").keyup(function(e){
		$("#friendmessage span.yourname").html( $("#sendtofriend #your-name").val() );
		if ( $("#sendtofriend #your-name").val() == '' ) {
			$("#friendmessage span.yourname").html( "[Your Name]" );
		}
	});
	
	if ( $("#sendtofriend #their-name").val() != '' ) {
		$("#friendmessage span.theirname").html( $("#sendtofriend #their-name").val() );
	}
	else {
		$("#friendmessage span.theirname").html( "[Friend's Name]" );
	}
	$("#sendtofriend #their-name").keyup(function(e){
		$("#friendmessage span.theirname").html( $("#sendtofriend #their-name").val() );
		if ( $("#sendtofriend #their-name").val() == '' ) {
			$("#friendmessage span.theirname").html( "[Friend's Name]" );
		}
	});
	
});