/*	TITLE		: bradgate.js
	
	DECRIPTION	: Javascript library
	
	REQUIREMENTS: jQuery.js

	HISTORY		:	2008-06-08	SJW	Added email
					2010-04-05  SJW Added tech
----------------------------------------------------------------------
*/

/*
----------------------------------------------------------------------
	TITLE:		: email.js
	
	DESCRIPTION	: Convert <span class="email"> into <a href="mailto:"> links
	
	HISTORY		: 2008-06-08 SJW Initial version
----------------------------------------------------------------------
*/
$(document).ready(function(){
// Default domain name
	var domain = "bradgate.doitwright.co.uk";

// Regular expression to match all spaces
	var from = / /g;

// Loop through all <span class="email"> tags
	
	$('span.email').each(function(){
// Read the 'rel' attribute
		var title = $(this).attr('title');

// Read the name of the person between the <span> and </span> tags
		var person = $(this).html();

		if(title == null || title == ""){
// No 'title' attribute specified.
// Check to see if we recognise the person. 
// If known, then use their known email address.
			switch(person){
			case "Robert Northage":
				email = "rhnorthage" + "@super.net";
				break;
			default:
// If person is unknown then replace all spaces with a dot and append the default domain name
				email = person.replace(from, ".") + "@" + domain;
			}
		} else {
// 'title' attribute specific. Check for '#' in the email address.
			if(title.indexOf("#") == -1){
// No '#' in the email address, so append the default domain
				email = title + "@" + domain;
			} else {
// '#' in the email address, so replace it with a '@'
				email = title.replace("#","@");
			}
		};

// Create an <a> tag
		var anchor = document.createElement("a");
// Set the 'href' attrribute to the email address (prefix with mailto:)
		anchor.setAttribute("href", "mailto:" + email);
// Create a text node with the name of the person (taken from the <span> tag). Replace " [at] " with "@"
		var person = person.replace(/ \[\at\] /, "@");
		var text = document.createTextNode(person);
// Append the text node to the <a> tag
		anchor.appendChild(text);
// Append the <a> tag to the document, immediately after the <span>...</span>. Then remove the <span> tag. 
		$(this).after(anchor).remove();
	});
});

/*
----------------------------------------------------------------------
	TITLE:		: tech.js
	
	DESCRIPTION	: Allow double-click of #tech <p> to show technical details
	
	HISTORY		: 2010-04-05 SJW Initial version
----------------------------------------------------------------------
*/
$(document).ready(function(){
	$('#tech').each(function(){
		$(this).hide();
		$('#status').dblclick(function(){
			$('#tech').show();
		});
	});
});

