$(document).ready(function() {
    //Bio read more/less	
	$('#read-more').click(function(e) {
	   e.preventDefault();
	   $('#ellipsis').html('.');
	   $('#read-more').hide();
	   $('#read-less').show();
	   $('#second-choice').show();
	   $('#choice').hide();
	   $('#full-bio').show();
	   
	      $('#read-less').click(function(e) {
	      e.preventDefault();
	      $('#ellipsis').html('.');
	      $('#read-more').show();
	      $('#choice').show();
	      $('#second-choice').hide();
	      $('#full-bio').hide();
	      $('#read-less').hide();
	      $('#ellipsis').html('...');
	   });
	});
	
	//Reviews 1-3, read more/less	
	$('#more-one').click(function(e) {
	   e.preventDefault();
	   $('#teaser-one').hide();
	   $('#full-one').show();
	   
	   $('#less-one').click(function(e) {
	       e.preventDefault();
	       $('#teaser-one').show();
	       $('#full-one').hide();
	   })
	});
	
	$('#more-two').click(function(e) {
	   e.preventDefault();
	   $('#teaser-two').hide();
	   $('#full-two').show();
	   
	   $('#less-two').click(function(e) {
	       e.preventDefault();
	       $('#teaser-two').show();
	       $('#full-two').hide();
	   })
	});
	
	$('#more-three').click(function(e) {
	   e.preventDefault();
	   $('#teaser-three').hide();
	   $('#full-three').show();
	   
	   $('#less-three').click(function(e) {
	       e.preventDefault();
	       $('#teaser-three').show();
	       $('#full-three').hide();
	   })
	});

// email address bot-safe swap
if ($("span.emailaddress").length) {
		$("span.emailaddress").each(function(){
			var mailtag = $(this);
			var at = / at /;
			var addr = $(mailtag).text().replace(at,"&#64;");
			$(mailtag).after('<a href="mailto:'+addr+'">'+ addr +'</a>');
			$(mailtag).remove();
		});
	}


});

function customizeCaption(caption) {
	if ($(caption).length) {
		var link = $(caption).children("#lightbox-caption-title");
		var lowres = $(caption).children("#lightbox-caption-title").attr("href");
		var highres = lowres.replace(/low([-_])/g,"hi$1");
		var newlinks = '<br/>(download this photo as <a class="downloadphoto" href="'+lowres+'">low-res</a> or <a class="downloadphoto" href="'+highres+'">high-res</a>)';
		if ($(caption).children("#download-caption").length) {// modify first time only
			$(caption).children("#download-caption").html(newlinks);
		} else {
			$(caption).append('<span id="download-caption">'+newlinks+'</span>');
		}
		if ($(link).css('display') != 'none') {// modify first time only
			$(link).after('<strong>'+$(link).text()+'</strong>');
			$(link).css('display','none');
		}
		$('.downloadphoto').click(function(){window.open($(this).attr('href')); return false;});
	}
}
