// JavaScript Document

$(document).ready( function(){
	emailPage();
	printPage();
	externalLinks();
});

/* email page function */
function emailPage() {
	$('a.email').click(function(){
	$('a.email').attr({ href: 'mailto:enter email address?subject=Trefreock&body=The sender of this email thought that you may find the following page(s) from Trefreock of interest: %0a%0a' + document.title + ': ' + window.location})
 });
}

/* print page function */
function printPage() {
	$('.print').click(function(){
		window.print();
	});
}

/* external links to open in new window */
function externalLinks() { 

	if (!document.getElementsByTagName) return; 

	var anchors = document.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		var relvalue = anchor.getAttribute("rel");
		if (anchor.getAttribute("href")) {
			var external = /external/;
			var relvalue = anchor.getAttribute("rel");
			if (external.test(relvalue)) { 
				anchor.target = "_blank";
			}
		} 
	}
} 
