$(document).ready(function() {
	

	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}


	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 500, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("#top-navigation li .sub").css({'opacity':'0'});
	$("#top-navigation li").hoverIntent(config);



});


/* ================================================================ 
This copyright notice must be untouched at all times.
Copyright (c) 2009 Stu Nicholls - stunicholls.com - all rights reserved.
=================================================================== */

$(document).ready(function(){

$(".hidden").hide();
$(".show b").html("Show");

$(".show").click(function() {
if (this.className.indexOf('clicked') != -1 ) {
		$(".hidden").hide();
		$(this).removeClass('clicked')
		$(this).children("b").html("Show");
		}
		else {
		$(".hidden").hide();
		$(".show").removeClass('clicked');
		$(".show").children("b").html("Show");
		current = $(this).children("b").attr("class");
		$("#"+current).show();
		$(this).addClass('clicked')
		$(this).children("b").html("Hide");
		}
});

});

/* ================================================================ 
Image carusel http://caroufredsel.frebsite.nl/
=================================================================== */


$("#foo2").carouFredSel({
	circular: true,
	infinite: true,
	auto 	: false,
	scroll	: {
		items	: "page"
	},
	prev	: {	
		button	: "#foo2_prev",
		key		: "left"
	},
	next	: { 
		button	: "#foo2_next",
		key		: "right"
	},
	pagination	: "#foo2_pag"
});


Cufon.replace('#content-wrapper h1', {textShadow:'0px 1px 1px #000'}); 
Cufon.replace('#content-wrapper h2', {textShadow:'0px 1px 1px #000'});
Cufon.replace('#content-wrapper h3', {textShadow:'0px 1px 1px #000'});
Cufon.replace('#content-wrapper h4', {textShadow:'0px 1px 1px #000'}); 
Cufon.replace('p.tel-number');
Cufon.replace('#foo2 div h3', {textShadow:'0px 1px 1px #000'}); 
Cufon.replace('.iform label', {textShadow:'0px 1px 1px #000'}); 

Galleria.loadTheme('galleria/themes/miniml/galleria.miniml.min.js');
	$("#gallery").galleria({
			width: 948,
			height: 635,
			autoplay: 7000,
			transition: 'fadeslide',
			transitionSpeed: '600',
			imageCrop: 'width',
			debug: true, 
			carousel: false,
			imagePan: true,
			clicknext: true,
			thumbnails: true,
			showCounter: true
	});	

function validateenquiry(formNode){
  var formValidatorInstance = new FormValidator(formNode);
  formValidatorInstance.addRule('yourname','Please enter your YOUR NAME','required');
	formValidatorInstance.addRule('emailaddress','Please enter your EMAIL ADDRESS','required');
	formValidatorInstance.addRule('emailaddress','Please enter a valid EMAIL ADDRESS e.g. yourname@domain.com','email');
	formValidatorInstance.addRule('phonenumber','Please enter NUMBERS (with no spaces) for your CONTACT TELEPHONE NUMBER e.g. 0800123456','numeric');	
	formValidatorInstance.addRule('phonenumber','Please enter your CONTACT TELEPHONE NUMBER including area code (and country code if outside of the UK)','required');	
  return formValidatorInstance.validate();
}

