
jQuery(InitSite);

function InitSite()
{					 //  #myID li a:not("li li a")
    Cufon.now();
    Cufon.replace("ul#topnav li.main>a, ul#topnav li.first>a", {fontFamily: 'Bebas'});
	Cufon.replace("h1, h2, h3, .thedate", {fontFamily: 'Bebas Neue'});
    Cufon.replace(".tabitha", {fontFamily: 'Tabitha'});
	//faq
	$(".faq").colorbox();	 
 
    $('#slider').nivoSlider({ 
	 	effect:'random', //Specify sets like: 'fold,fade,sliceDown'
        slices:10,
        animSpeed:1000, //Slide transition speed
        pauseTime:5000,
		controlNav: false,
        pauseOnHover: true,
		directionNav:false,
        manualAdvance: false   
		

    });
   
   //On Hover Over
function megaHoverOver(){
    $(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
    (function($) {
        //Function to calculate total width of all ul's
        jQuery.fn.calcSubWidth = function() {
            rowWidth = 0;
            //Calculate row
            $(this).find("ul").each(function() { //for each ul...
                rowWidth += $(this).width(); //Add each ul's width together
            });
        };
    })(jQuery); 

    if ( $(this).find(".row").length > 0 ) { //If row exists...

        var biggestRow = 0;	

        $(this).find(".row").each(function() {	//for each row...
            $(this).calcSubWidth(); //Call function to calculate width of all ul's
            //Find biggest row
            if(rowWidth > biggestRow) {
                biggestRow = rowWidth;
            }
        });

        $(this).find(".sub").css({'width' :biggestRow}); //Set width
        $(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin

    } else { //If row does not exist...

        $(this).calcSubWidth();  //Call function to calculate width of all ul's
        $(this).find(".sub").css({'width' : rowWidth}); //Set Width

    }
}
//On Hover Out
function megaHoverOut(){
  $(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
      $(this).hide();  //after fading, hide it
  });
}
//Set custom configurations
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)
};

$("ul#topnav li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
$("ul#topnav li").hoverIntent(config); //Trigger Hover intent with custom configurations
}
 

function validate_bookingform ( ) { 
		var reason = "";
	  	reason += validateFirstName();
		reason += validateSurname();
	  	reason += validateaddr1();
	  	reason += validateEmail();
		if (reason != "") {
	    alert("Some fields need correction:\n" + reason);
	    return false;
	  	}
	else
		{ 
		document.booking.action='booking-request-send.php'; 
		document.booking.submit();
	   
	   
	   }
}	  

function validateFirstName() {
    var error = "";
 
    if (document.booking.fldFirstName.value  == "") 
	{	
		document.getElementById("fldFirstName").style.backgroundColor = '#FFDFE3';
        error = "Please specify your first name.\n";
    } 
    return error;  
}
function validateSurname() {
    var error = "";
 
    if (document.booking.fldSurname.value == "") 
	{  
		document.getElementById("fldSurname").style.backgroundColor = '#FFDFE3';
        error = "You havent sepcified your Surname.\n";
    } 
    return error;  
}
function validateaddr1() {
    var error = "";
 
    if ( document.booking.fldAddr1.value=="")
	{  
		document.getElementById("fldAddr1").style.backgroundColor = '#FFDFE3';
        error = "The first line of your address is missing.\n";
    } 
    return error;  	
}	
function validateEmail() {
    var error = "";
 
    if ( document.booking.fldEmailAddr.value=="")
	{  
		document.getElementById("fldEmailAddr").style.backgroundColor = '#FFDFE3';
        error = "Your email address is missing.\n";
    } 
    return error;  
} 
 
 
 function validate_news ( )
{
    var errors=0;

    if ( document.news.fname.value == "" )
    {
        alert ( "Please specify your First name." );
        errors ++;
    }
	
   
var emailID=document.news.email
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		valid = false;
	}
	

     if(!errors)
   {

   document.booking.submit();
   }
}  
 function echeck(str) {

  var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail")
		  return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail")
		   return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail")
		   return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail")
		   return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail")
		   return false
		 }
		   return true	
}	

function validate_contactform ( )
{
    var errors=0;

    if ( document.contact.fldName.value == "" )
    {
        alert ( "Please specify your contact name." );
        errors ++;
    }
	
var emailID=document.contact.fldEmail
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		errors ++;
	}
	

   if(!errors)
   {

   document.contact.submit();
   document.contact.action='contactsend.php';
   }
}  

                                                function CheckMultiple41(frm, name) {
                                                                for (var i=0; i < frm.length; i++)
                                                                {
                                                                                fldObj = frm.elements[i];
                                                                                fldId = fldObj.id;
                                                                                if (fldId) {
                                                                                                var fieldnamecheck=fldObj.id.indexOf(name);
                                                                                                if (fieldnamecheck != -1) {
                                                                                                                if (fldObj.checked) {
                                                                                                                                return true;
                                                                                                                }
                                                                                                }
                                                                                }
                                                                }
                                                                return false;
                                                }
                                function CheckForm41(f) {
                                                var email_re = /[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i;
                                                if (!email_re.test(f.email.value)) {
                                                                alert("Please enter your email address.");
                                                                f.email.focus();
                                                                return false;
                                                }
                                
                                                                                                if (f.format.selectedIndex == -1) {
                                                                                                                alert("Please choose a format to receive your email campaigns in");
                                                                                                                f.format.focus();
                                                                                                                return false;
                                                                                                }
                                                                                
                                                                if (f.captcha.value == "") {
                                                                                alert("Please enter the security code shown");
                                                                                f.captcha.focus();
                                                                                return false;
                                                                }
                                                
                                                var fname = "CustomFields_159_41";
                                                var fld = document.getElementById(fname);
                                                if (fld.value == "") {
                                                                alert("Please enter a value for field Forename");
                                                                fld.focus();
                                                                return false;
                                                }
                                
                                                                return true;
                                                }
