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

	HISTORY		: 2010-04-05	SJW	Initial version
	              2010-04-06	SJW	email: Fixed bug when email not specified
----------------------------------------------------------------------
*/

/*
----------------------------------------------------------------------
	TITLE:		: email
	
	DESCRIPTION	: Convert <span class="email"> into <a href="mailto:"> links
	
	HISTORY		: 2010-04-05	SJW	Initial version
				  2010-04-06	SJW Fixed bug when email not specified
----------------------------------------------------------------------
*/
$(document).ready(function(){
// Default domain name
	var domain = "leicsbridge.org.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 = "rnorthage" + "@btinternet.com";
				break;
			case "Steve Wright":
				email = "stevewrightuk" + "@gmail.com";
				break;
			case "Irene Krantz":
			    email = "iyk99" + "@yahoo.co.uk";
				break;
			case "John Wilcox":
				email = "john.bridge.wilcox" + "@gmail.com";
				break;
			case "john.bridge.wilcox@gmail.com":
				email = "john.bridge.wilcox" + "@gmail.com";
				break;			case "Pat Beasley":
				email = "patbeasley" + "@care4free.net";
				break;
			case "Neil Beasley":
				email = "neilbeasley" + "@care4free.net";
				break;
			case "John Thompson":
				email = "john.thompson.bridge" + "@googlemail.com";
				break;
			case "Mike Ayers":
				email = "mike.ayers" + "@tiscali.co.uk";
				break;
			case "Henry Cooklin":
				email = "hcooklin" + "@sky.com";
				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). Strip [at] and any following characters
		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();
		});
	});
});

