;(function($){
	var fixIE = document.createElement('abbr');
	


	/* plugin by Joel Birch */
	$.fn.checkEmail = function(emailField){
		return this.submit(function(){
			var email=$(this).find(emailField);
			var val=email.val();
			if (val!='' && val.match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i) ) {
				return true;
			} else {
				var msg = (val=='') ? "The email address field is empty, please enter your email address."
					: "You have entered an invalid email address - please correct it before proceeding.";
				alert(msg);
				email.focus();
				return false;
			}
		});
	};

	/* Handy functions - needed for SweetTitles */
	Array.prototype.inArray = function (value) {
		var i;
		for (i=0; i < this.length; i++) {
			if (this[i] === value) {
				return true;
			}
		}
		return false;
	};
/*
	Sweet Titles (c) Creative Commons 2005
	http://creativecommons.org/licenses/by-sa/2.5/
	Author: Dustin Diaz | http://www.dustindiaz.com
	jQuery alterations: Joel Birch
*/
	$.st = { 
		xCord : 0,				// @Number: x pixel value of current cursor position
		yCord : 0,				// @Number: y pixel value of current cursor position
		tipElements : ['a','abbr','acronym'],	// @Array: Allowable elements that can have the toolTip
		obj : Object,			// @Element: That of which you're hovering over
		$tip : Object,			// @Element: The actual toolTip itself in a jQuery object
		active : 0,				// @Number: 0: Not Active || 1: Active
		init : function() {
			if ( !document.getElementById ||
				!document.createElement ||
				!document.getElementsByTagName ) {
				return;
			}
			this.$tip = $('<div>')
				.attr('id','toolTip')
				.appendTo("body")
				.css({
					'top':'0',
					'visibility':'hidden'});
			$(document).mousemove(this.updateXY);
			$(this.tipElements).each(function(i){
				$($.st.tipElements[i]+'[title]').each(function(){
					$(this).attr('tip',this.getAttribute('title')).hover($.st.tipOver,$.st.tipOut).removeAttr('title');
				});
			});
			$(window).unload(function() {
				$($.st.tipElements.join(','))
				.unbind('mouseover',$.st.tipOver)
				.unbind('mouseout',$.st.tipOut);
			});
		},
		updateXY : function(e) {
				$.st.xCord = e.pageX;
				$.st.yCord = e.pageY;
		},
		tipOut: function() {
			if ( window.tID ) {
				clearTimeout(tID);
			}
			if ( window.opacityID ) {
				clearTimeout(opacityID);
			}
			$.st.$tip.css({'visibility':'hidden'});
		},
		checkNode : function() {
			var trueObj = this.obj;
			if ( this.tipElements.inArray(trueObj.nodeName.toLowerCase()) ) {
				return trueObj;
			} else {
				return trueObj.parentNode;
			}
		},
		tipOver : function() {
			$.st.obj = this;
			tID = window.setTimeout("$.st.tipShow()",500);
		},
		tipShow : function() {		
			var scrX = Number(this.xCord);
			var scrY = Number(this.yCord);
			var tp = parseInt(scrY+15);
			var lt = parseInt(scrX+10);
			var anch = this.checkNode();
			var addy = '';
			var access = '';
			if ( anch.nodeName.toLowerCase() == 'a' ) {
				addy = (anch.href.length > 25 ? anch.href.toString().substring(0,25)+"&#8230;" : anch.href);
				var access = ( anch.accessKey ? ' <span>['+anch.accessKey+']</span> ' : '' );
			} else {
				addy = anch.firstChild.nodeValue;
			}
			var tip = $.st.$tip[0];
			$.st.$tip.html("<p>"+anch.getAttribute('tip')+"<em>"+access+addy+"</em></p>");
			var left = ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) < parseInt(tip.offsetWidth+lt) )
				? parseInt(lt-(tip.offsetWidth+10))+'px'
				: lt+'px';
			var top = ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) < parseInt(tip.offsetHeight+tp) )
				? parseInt(tp-(tip.offsetHeight+10))+'px'
				: tp+'px';
			$.st.$tip.css({
				'left':left,
				'top':top,
				'visibility':'visible',
				'opacity':'.1'
			});
			$.st.tipFade(10);
		},
		tipFade: function(opac) {
			var passed = parseInt(opac);
			var newOpac = parseInt(passed+10);
			if ( newOpac < 80 ) {
				$.st.$tip.css({'opacity':'.'+newOpac});
				opacityID = window.setTimeout("$.st.tipFade('"+newOpac+"')",20);
			}
			else { 
				$.st.$tip.css({'opacity':'.8'});
			}
		}
	};

	/* trigger site functionality before page load */
	$(function(){
		/* email validator */
		$("form").checkEmail("input.email");
		/* email address via AHAH */
		if ($("#contact").length){
			$("#content span.emailAddress").load("/assets/php/includes/infoAtLink.php");
		}
	
		/* initialise sweet tiles */
		$.st.init();
	});
	
		$(window).load(function() {
			if ($('body').is('#home')){
				setTimeout(function(){
					$.st.init();
				},2000);
				setInterval($.st.init,10000);
			}
		});
})(jQuery);