// Collection of various scripts used throughout the site

// Obfuscate email address - remove span

	$(document).ready(function(){
		$(".hide").empty();
	});

	
// Dropdown

	$(document).ready(function(){
							   
			$('li.headlink ul').hide();
							   
			function makeTall() { 
					$(this).children('ul').stop(true,true).slideDown(400);
					$(this).children('a').addClass('drop_hover');
			}
			
			function makeShort() { 
					$(this).children('ul').stop(true,true).slideUp(400);
					$(this).children('a').removeClass('drop_hover');
			}
							   
			$('li.headlink').hoverIntent({
					sensitivity: 7, 
					interval: 100, 
					over: makeTall, 
					timeout: 300, 
					out: makeShort
				});
			
			$('li.headlink a:not(li.headlink ul li a)').focus(function () {
					$(this).siblings('ul').stop(true,true).slideDown(400);
					$(this).addClass('drop_hover');
			});
			
			$('li.headlink ul li:last-child a').blur(function () {
					$('li.headlink > ul').stop(true,true).slideUp(400);
					$('li.headlink a').removeClass('drop_hover');
			});

	});
	
// Add class to last link of dropdown

	$(document).ready(function(){
		$("li.headlink ul li:last-child").addClass('last');
		$("li.headlink ul li:first-child").addClass('first');
	});

// Opens link in new window whilst retaining validity

	$(function() {
		$('a[rel*=external]').click( function() {
			window.open(this.href);
			return false;
		});
	});

// News Ticker

	$(document).ready(function () {
		createTicker();
	}); 
	
	function createTicker(){
		var tickerLIs = $("#ticker-area ul").children();
		tickerItems = new Array();
		tickerLIs.each(function(el) {
			tickerItems.push( jQuery(this).html() );
		});
		i = 0
		rotateTicker();
	}
	
	function rotateTicker(){
		if( i == tickerItems.length ){
		  i = 0;
		}
	  tickerText = tickerItems[i];
		c = 0;
		typetext();
		setTimeout( "rotateTicker()", 8000 );
		i++;
	}
	
	function typetext() {	
		var thisChar = tickerText.substr(c, 1);
		if( thisChar == '<' ){ isInTag = true; }
		if( thisChar == '>' ){ isInTag = false; }
		$('#ticker-area').html(tickerText.substr(0, c++) + '');
		if(c < tickerText.length+1)
			if( isInTag ){
				typetext();
			}else{
				setTimeout("typetext()", 28);
			}
		else {
			c = 1;
			tickerText = "";
		}	
	}
	
// Equal heights

	function equalHeight(group) {
		tallest = 0;
		group.each(function() {
			thisHeight = $(this).height();
			if(thisHeight > tallest) {
				tallest = thisHeight;
			}
		});
		group.height(tallest);
	}
	
	$(document).ready(function() {
		equalHeight($(".services_box"));
	});

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}	