
jQuery(document).ready(function($) {
/* ------------------------------------------------------------------------------------
-- Google Analytics event tracking
------------------------------------------------------------------------------------ */
	$("#header .cta a").click( function(){
		_gaq.push(['_trackEvent', 'CallToAction', 'UTTtop', 'Clickthrough to UTT - top']);
	});
	$("#mainContent .cta a").click( function(){
		_gaq.push(['_trackEvent', 'CallToAction', 'UTTbottom', 'Clickthrough to UTT - bottom']);
	});
	
/* ------------------------------------------------------------------------------------
-- Slideshow effect
------------------------------------------------------------------------------------ */
	fnSlideshow = function(){
		//options
		slideShowFadeSpeed="slow";
		slideShowPause=6000;
		slideShowParent = "#testimonialsInner";
		slideShowChild = "div";

		//ensure the slides are hidden
		$(slideShowParent+" "+slideShowChild).hide();
		
		//show the first slide, add on state
		$(slideShowParent+" "+slideShowChild+":eq(0)").addClass("on").fadeIn(slideShowFadeSpeed);
		
		//set time interval
		runSlideshow = setInterval( "fnSlideSwitch()", slideShowPause );
	};
	fnSlideSwitch = function(){
		$(slideShowParent+" "+slideShowChild+".on").fadeOut(slideShowFadeSpeed, function(){
			$(slideShowParent+" "+slideShowChild+".on").removeClass("on").next().addClass("on").fadeIn(slideShowFadeSpeed);
			//check if that was the last item
			if ($(slideShowParent+" "+slideShowChild+".on").length==0){
				//fnStopSlideShow();
				$(slideShowParent+" "+slideShowChild+":eq(0)").addClass("on").fadeIn(slideShowFadeSpeed);
			};
		});
	};
	fnStopSlideShow = function(){
		clearInterval(runSlideshow);
		fnSlideshow();
	};

/* ------------------------------------------------------------------------------------
-- Homepage slideshow
------------------------------------------------------------------------------------ */
	fnSlideshow();

/* ------------------------------------------------------------------------------------
-- Mark as javascript enabled 
------------------------------------------------------------------------------------ */
	$('body').addClass('js');

/* ------------------------------------------------------------------------------------
-- Lists
------------------------------------------------------------------------------------ */
	$('#mainNav li:first-child').addClass('first');
	$('#mainNav li:last-child').addClass('last');

/* ------------------------------------------------------------------------------------
-- Set up gallery
------------------------------------------------------------------------------------ */
	$('.gallery a').append('<span></span>');
	$('.gallery a, .cta a').hover(
		function () {
			$(this).addClass("on");
		}, 
		function () {
			$(this).removeClass("on");
		}

	);
	
	

/* ------------------------------------------------------------------------------------
-- CTAs
------------------------------------------------------------------------------------ */
	$('.cta a').each( function(){
		$this = $(this);
		popupText = $this.attr('title');
		$this.wrapInner('<span class="ieHack"></span>').removeAttr('title');
		$this.append('<em><span class="msg">'+popupText+'<span class="arrow"></span></span></em>');
	});


});







