
function spStopTest(){
	d = new Date();
	timeStart = $(document).data('counterStart');
	timeEnd = d.valueOf();
	$('#test').after('<input type="hidden" value="'+ (timeEnd - timeStart) +'" name="online_test_time" id="online_test_time"/>').slideUp(800);
	
}

function spTextDisplay(){
	//$('#spTimer').after('<div id="test"></div>').load('/speed_reading.html?ajax=1&test='+ $(document).data('TestId')).slideDown(1000);
	$.get('/speed_reading.html?ajax=1&test='+ $(document).data('TestId'), function(data){
		//	Remove the start button
		$('#spTimer').after('<div id="test">'+ data +'</div>').slideUp(800).remove();
		
		//	Start the timer
		d = new Date();
		$(document).data('counterStart',d.valueOf());
		
		//	Add the stop button
		$('#test').after('<div class="panel" id="spTimer"><h2>Proceed to the comprehension test</h2><p><input type="hidden" name="online_test" value="'+ $(document).data('TestId') +'" id="online_test" /><input type="submit" name="submit_test" id="spStopTest" class="button" value="Finish the test" /></p></div>');
		$('#spStopTest').click(function(){ spStopTest();  });
	});
}

function spShowTimer(){
	//	Save the id before we remove the content
	$(document).data('TestId', $('#online_test2').val());
	
	//	Show the timer
	$('#spContent').html('<div class="panel" id="spTimer"><h2>Test your speed</h2><p>Press the button to start the challange and test your reading speed.</p><p><input type="submit" name="spStartTest" id="spStartTest" class="button" value="Start the test" /></p></div>');
	$('#spContent').slideDown(1000);
	$('#spStartTest').click(function(){ spTextDisplay(); return false; });
}

function speedReadingTest(){
	$('#spContent').slideUp(800, function(){ spShowTimer(); });
}



function menuOverLinks() {
	$('#AssimilateHover').mouseover(function(){ $('#AssimilateLink').toggleClass('hover') });
	$('#AssimilateHover').mouseout(function(){ $('#AssimilateLink').toggleClass('hover') });

	$('#CommunicateHover').mouseover(function(){ $('#CommunicateLink').toggleClass('hover') });
	$('#CommunicateHover').mouseout(function(){ $('#CommunicateLink').toggleClass('hover') });

	$('#InnovateHover').mouseover(function(){ $('#InnovateLink').toggleClass('hover') });
	$('#InnovateHover').mouseout(function(){ $('#InnovateLink').toggleClass('hover') });

	$('#FacilitateHover').mouseover(function(){ $('#FacilitateLink').toggleClass('hover') });
	$('#FacilitateHover').mouseout(function(){ $('#FacilitateLink').toggleClass('hover') });

	$('#MotivateHover').mouseover(function(){ $('#MotivateLink').toggleClass('hover') });
	$('#MotivateHover').mouseout(function(){ $('#MotivateLink').toggleClass('hover') });
}


sfHover = function() {
	var sfEls = document.getElementById("coursesnav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.isMouseOver=true;
			this.className+=" hover";
		}
		sfEls[i].onmouseout=function() {
			this.isMouseOver=false;
       		if(!this.isMouseOver){
				this.className=this.className.replace(new RegExp(" hover\\b"), "");
			}
 	  	}
	}
}



if (window.attachEvent) window.attachEvent("onload", sfHover);

function pausecomp(millis){
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
} 

function saveAnalyticsCheckboxes() {
	
	at = $(this).attr('alt');
	
	pageTracker._trackPageview(at + '.html');
	
}


function attachMemberProfile(){
	
	$('form input.transform').each(function(){
		//	Hide the input
		$(this)
			.addClass('noForm')
			.parent().append(' &nbsp; <a href="#" >Edit</a>');
		
		//	Both clicking on text and edit link makes form visible 
		$(this)
			.focus(function(){
				$(this).removeClass('noForm');
			})
			.siblings('a').click(function(){
				$(this).siblings('input.transform').removeClass('noForm');
				return false;
			});
	});

	$('form input.changed').focus();
	
	$('#memberUser, #fmemberUser').focus(function(){
		if($(this).val()=='E-mail') $(this).val('');
	});
	$('#memberUser').blur(function(){
		if($(this).val()=='')
			$(this).val('E-mail');
	});
	
	$('#memberPass').focus(function(){
		if($(this).val()=='password') $(this).val('');
	});
	
	$('#memberPass').blur(function(){
		if($(this).val()=='')
			$(this).val('password');
	});
	
	$('#searchTerm').focus(function(){
		if($(this).val()=='What are you searching for?') $(this).val('');
	});
	$('#searchTerm').blur(function(){
		if($(this).val()=='')
			$(this).val('What are you searching for?');
	});
		
	
}



function analyticsCheckboxes(){
	$('input.coursecheckbox').click(saveAnalyticsCheckboxes);
}

$().ready(function(){
	//	Hide anti spam-field
	$('#extrafax').hide(1);
	//	Add strapline
	$('#straptext').html("Training to <strong>enhance practical thinking</strong> skills to improve the performance of individuals and organisations");
	//	Attach externals
	$('.external').attr('target', '_blank');
	
	menuOverLinks();
	analyticsCheckboxes();
	
	attachMemberProfile();

});