$(document).ready(function() {

	/*if($("body#latest-news").length){
		$("#newsevents").tabs({selected:1});
	}
	else{
		$("#newsevents").tabs();
	}*/
	
	//Google driving directions - take a postcode from the text field, put it into a variable, then take that to Google. Cross your fingaz.
	
	$("body#contact #getdirs_submit").click(function(){
	
		var destination = $("#getdirs_destination").val();
		var postcode = $("#getdirs_postcode").val();
	
//		window.location = 'http://maps.google.co.uk/maps?f=d&source=s_d&saddr='+postcode+'&daddr=5+Manfred+Road,+Wandsworth&hl=en&geocode=FTzCDwMdY-r8_ylff3SxEwh2SDE1V3nUc5-1nw%3BFWIwEQMdc9v8_ynF5BIjbA92SDEIAb99hKnNNA&mra=ls&sll=53.800651,-4.064941&sspn=21.27781,57.084961&ie=UTF8&ll=51.410985,-0.196724&spn=0.174739,0.445976&z=12&dirflg=d';
		window.location = 'http://maps.google.co.uk/maps?f=d&source=s_d&saddr='+postcode+'&daddr='+destination+'&hl=en&geocode=FTzCDwMdY-r8_ylff3SxEwh2SDE1V3nUc5-1nw%3BFWIwEQMdc9v8_ynF5BIjbA92SDEIAb99hKnNNA&mra=ls&sll=53.800651,-4.064941&sspn=21.27781,57.084961&ie=UTF8&ll=51.410985,-0.196724&spn=0.174739,0.445976&z=12&dirflg=d';
		return false;
	
	});
	
	//javascript:window.location%20=%20'http://validator.w3.org/check?uri='+escape(location)

	// Animooted dropdown top navigation (#primary-nav)
 	$("#primary-nav > li").mouseenter(function(){
		$(this).addClass("hover");
		$(this).children("ul").slideDown("fast");
 	});
 	$("#primary-nav > li").mouseleave(function(){
		$(this).removeClass("hover");
 		$(this).children("ul").slideUp("fast");
	});
	$("#primary-nav > li > ul > li:last-child").css("border-bottom","0px");

	// Funky forms
	// First we set up event handlers for focus and blur. Finally there are two functions for highlighting on and off.
 	
	$('input[type="text"]:not(.search-input)').focus(function(){
		highLight(this);
	});
	$('input[type="text"]:not(.search-input)').blur(function(){
		lowLight(this);
	});
	$('textarea').focus(function(){
		highLight(this);
	});
	$('textarea').blur(function(){
		lowLight(this);
	});
	
	function highLight(element){
		$(element).animate({
			borderTopColor:"#E991BD",
			borderRightColor:"#E991BD",
			borderBottomColor:"#E991BD",
			borderLeftColor:"#E991BD"},'fast');
	};
	function lowLight(element){
		$(element).animate({
			borderTopColor:"#ccc",
			borderRightColor:"#ccc",
			borderBottomColor:"#ccc",
			borderLeftColor:"#ccc"},'fast');
	};
	
	/* Additional items added for Lynda Gratton's site: */
	$("#newsevents div.story").hover(
	  function () {
		$(this).css("cursor", "pointer");
		$(this).animate({"background-color": "#eee"}, "slow");
	  },
	  function () {
		$(this).css("cursor", "auto");
		$(this).animate({"background-color": "#fff"}, "slow");
	  }
	);
	$("#homebooks div.story").hover(
	  function () {
		$(this).css("cursor", "pointer");
		$(this).animate({"background-color": "#eee"}, "slow");
	  },
	  function () {
		$(this).css("cursor", "auto");
		$(this).animate({"background-color": "#fff"}, "slow");
	  }
	);
	
	/* Make sure all story divs become links */
	$("div.story").click(function(){
		var linkURL = $(this).find("a").attr("href");
		window.location = linkURL;
		return false;
		
	});
	
	/* Book promo - Feb 2011 */
	$("#top_expander").hide();
	$("#top_expander").delay(800).slideDown("slow");
	$("div#top_expander_control div.inner p.open").delay(800).hide();
	$("div#top_expander_control div.inner p.close").delay(800).show();
	
	// expander controls
	$("div#top_expander_control div.inner p.close").hover(
	  function () {
		$(this).css("cursor", "pointer");
		$(this).animate({"color": "#fff"}, "slow");
	  },
	  function () {
		$(this).css("cursor", "auto");
		$(this).animate({"color": "#ccc"}, "slow");
	  }
	);
	
	$("div#top_expander_control div.inner p.close").click(function(){
		$("#top_expander").slideUp("slow");
		$("div#top_expander_control div.inner p.close").hide();
		$("div#top_expander_control div.inner p.open").show();
	});
	
	$("div#top_expander_control div.inner p.open").click(function(){
		$("#top_expander").slideDown("slow");
		$("div#top_expander_control div.inner p.close").show();
		$("div#top_expander_control div.inner p.open").hide();
	});
	
	// preload images first (can run before page is fully loaded)
	//$.preloadImages("images/expander/btn_amazon_uk_on.gif", "images/expander/btn_amazon_us_off.gif");
	$("div#top_expander img.rollover").hover(
		function() {
			$(this).attr("src",$(this).attr("src").replace("_off","_on"));
		}, function() {
			$(this).attr("src",$(this).attr("src").replace("_on","_off"));
		}
	);
});
