$(document).ready(function() {

	/* Google directions - see Contact template */
	$("body#contact #getdirs_submit").click(function(){
	
		var destination = $("#getdirs_destination").val();
		var postcode = $("#getdirs_postcode").val();
	
		window.location = 'http://maps.google.co.uk/maps?saddr='+postcode.toUpperCase()+'&daddr='+destination;
		return false;
	
	});
	
	/* Animate dropdown top navigation (ol#primary-nav) */
 	$("ol#primary-nav > li").mouseenter(function(){
		$(this).addClass("hover");
		$(this).css("cursor", "pointer");
		$(this).children("ol").slideDown("fast");
 	});
 	$("ol#primary-nav > li").mouseleave(function(){
		$(this).removeClass("hover");
		$(this).css("cursor", "auto");
 		$(this).children("ol").slideUp("fast");
	});
	$("ol#primary-nav > li > ol > li:last-child a").css("border-bottom","0px");
	$("ol#primary-nav > li").click(function(){
		var linkURL = $(this).find("a").attr("href");
		window.location = linkURL;
		return false;
	}); 
	$("ol#primary-nav > li > ol > li").click(function(){
		var linkURL = $(this).find("a").attr("href");
		window.location = linkURL;
		return false;
	}); 
		
	 
	/* Form styling controls - for focus and blur */
	function highLight(element){
		$(element).animate({
			borderTopColor:"#f90",
			borderRightColor:"#f90",
			borderBottomColor:"#f90",
			borderLeftColor:"#f90"},'fast');
	};
	function lowLight(element){
		$(element).animate({
			borderTopColor:"#ccc",
			borderRightColor:"#ccc",
			borderBottomColor:"#ccc",
			borderLeftColor:"#ccc"},'fast');
	};
	$('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);
	});
	
	/* Make widget panels into links */
	$(".homepagebox").hover(
	  function () { /* on state */
		$(this).css("cursor", "pointer");
		$(this).animate({"background-color": "#999"}, "slow");
	  },
	  function () { /* off state */
		$(this).css("cursor", "auto");
		$(this).animate({"background-color": "#ccc"}, "slow");
	  }
	);
	$(".homepagebox").click(function(){
		var linkURL = $(this).find("p a").attr("href");
		window.location = linkURL;
		return false;
	});
	
	/* Make widget panels into links */
	$("#listingpanel li.even").hover(
	  function () { /* on state */
		$(this).css("cursor", "pointer");
		$(this).animate({"background-color": "#ededed"}, "fast");
	  },
	  function () { /* off state */
		$(this).css("cursor", "auto");
		$(this).animate({"background-color": "#f6f6f6"}, "fast");
	  }
	);
	$("#listingpanel li.odd").hover(
	  function () { /* on state */
		$(this).css("cursor", "pointer");
		$(this).animate({"background-color": "#f6f6f6"}, "fast");
	  },
	  function () { /* off state */
		$(this).css("cursor", "auto");
		$(this).animate({"background-color": "#ededed"}, "fast");
	  }
	);
	$("#listingpanel li").click(function(){
		var linkURL = $(this).find("h4 a").attr("href");
		window.location = linkURL;
		return false;
	});
	$("#listingpanel.popular li").click(function(){
		var linkURL = $(this).find("p a").attr("href");
		window.location = linkURL;
		return false;
	});
	
	
	/* Make widget panels into links */
	$(".sidebarbox.donate, div#topnav a.donate").hover(
	  function () { /* on state */
		$(this).css("cursor", "pointer");
		$(this).animate({"background-color": "#f60"}, "fast");
	  },
	  function () { /* off state */
		$(this).css("cursor", "auto");
		$(this).animate({"background-color": "#f90"}, "slow");
	  }
	);
	$(".sidebarbox.donate").click(function(){
		var linkURL = $(this).find("h3 a").attr("href");
		window.location = linkURL;
		return false;
	});
	
	/* Create tab function within any div marked #tabs */
	$("#tabpanel").tabs();
	
	/* home - news panel 
	div#highlightpanel div.highlightitem img 
	div#highlightpanel div.highlightitem div#newshighlight h3
	*/
	if (($("div#one div#highlightpanel > div").size()-1) > 1) {
	
		$("div#one div#highlightpanel div.highlightitem").hide();
		$("div#one div#highlightpanel div.highlightitem.current").fadeIn("fast");
		$(this).everyTime(10000, 'div#one div#highlightpanel', function() {
			$("div#one div#highlightpanel div.highlightitem.current").fadeOut("slow", function(){
				$("div#one div#highlightpanel div.highlightitem.current").removeClass("current");
				if($(this).hasClass("last")){
					$("div#one div#highlightpanel div.highlightitem:first").addClass("current").fadeIn("slow");
				} else{
					$(this).next("div#one div#highlightpanel div.highlightitem").addClass("current").fadeIn("slow");
				}
			});
		});
	}
	
	
});
