$(document).ready(function(){

	if (typeof sameAsCheckbox == 'function') { sameAsCheckbox(); }; // used in booking_page_2
	
	if (typeof closeSameAsAbove == 'function') { closeSameAsAbove(); }; // this function only runs if same as above checkbox is selected and there are form errors so the page is reloaded with errors showing - function used in booking engine and flight option page
	
	// upto 6 pax the javascript will work - Booking Form still works for more than 6 pax.
	if (typeof noAll1 == 'function') { noAll1(); };
	if (typeof noAll2 == 'function') { noAll2(); };
	if (typeof noAll3 == 'function') { noAll3(); };
	if (typeof noAll4 == 'function') { noAll4(); }; 
	if (typeof noAll5 == 'function') { noAll5(); }; 
	if (typeof noAll6 == 'function') { noAll6(); }; 
	
	if (typeof noFlights0 == 'function') { noFlights0(); };
	if (typeof noFlights1 == 'function') { noFlights1(); };
	if (typeof noFlights2 == 'function') { noFlights2(); };
	if (typeof noFlights3 == 'function') { noFlights3(); };
	if (typeof noFlights4 == 'function') { noFlights4(); };
	if (typeof noFlights5 == 'function') { noFlights5(); };

	if (typeof closeFlights0 == 'function') { closeFlights0(); }; 
	if (typeof closeFlights1 == 'function') { closeFlights1(); }; 
	if (typeof closeFlights2 == 'function') { closeFlights2(); }; 
	if (typeof closeFlights3 == 'function') { closeFlights3(); }; 
	if (typeof closeFlights4 == 'function') { closeFlights4(); }; 
	if (typeof closeFlights5 == 'function') { closeFlights5(); }; 

	if (typeof closeAll1 == 'function') { closeAll1(); }; 
	if (typeof closeAll2 == 'function') { closeAll2(); }; 
	if (typeof closeAll3 == 'function') { closeAll3(); }; 
	if (typeof closeAll4 == 'function') { closeAll4(); }; 
	if (typeof closeAll5 == 'function') { closeAll5(); }; 
	if (typeof closeAll6 == 'function') { closeAll6(); }; 

	if (typeof animateMenu == 'function') { animateMenu(); };
	if (typeof popUpBox == 'function') { popUpBox(); }; 
	if (typeof hoverShow == 'function') { hoverShow(); }; 
	if (typeof latestShows == 'function') { latestShows(); };

});


// used to click hide tour search boxes - was used on homepage for fezbus special
function latestShows() {

$("#hover-display").css("display", "none");
$(".hover-display-button").click(function(){
	  $("#hover-display").slideToggle("slow");
	  $(this).toggleClass("active");
	});
}

// used on fb to hover hide/display phone number info in left column
function hoverShow() {
$("#hover-show").css("display", "none");
$(".hover-show-button").hover(function(){
	  $("#hover-show").show("slow");
//	  $(this).toggleClass("active");
	});
}


$(function(){
		//all hover and click logic for buttons
		$(".fg-button:not(.ui-state-disabled)")
		.hover(
			function(){ 
				$(this).addClass("ui-state-hover"); 
			},
			function(){ 
				$(this).removeClass("ui-state-hover"); 
			}
		)
	});

	function popUpBox()	{
		$(".menu_jquery a.main_link").mouseover(function() {
			if ($(this).next().css("display") == "none") {  //  if not already displayed
				$("em").animate({opacity: "hide", top: "-85"}, "slow");
				$(this).next("em").animate({opacity: "show", top: "-85"}, "slow");
			};
		});
	}

	function sameAsCheckbox()	{
		 $("#input_div").css("display","block");

	     $("#same_as_checkbox").click(function(){
	      if ($("#same_as_checkbox").is(":checked"))
	      {
	          $("#input_div").hide("fast");
	      }
	      else
	      {     
	          $("#input_div").show("fast");
	      }
	    });
	}

//http://onlinetools.org/articles/unobtrusivejavascript/chapter5.html


	function checkform(of)
	{
	// Test if DOM is available and there is an element called required
		if(!document.getElementById || !document.createTextNode){return;}
		if(!document.getElementById('required')){return;}

	// Define error messages and split the required fields
		var errorID='errormsg';
		var errorClass='error'
		var errorMsg='Please enter or change the fields marked with a ';
		var errorImg='http://www.fezbus.co.uk/Travis/fh/fh_images/alert.gif';
		var errorAlt='Error';
		var errorTitle='This field has an error!';
		var reqfields=document.getElementById('required').value.split(',');

	// Cleanup old mess
		// if there is an old errormessage field, delete it
		if(document.getElementById(errorID))
		{
			var em=document.getElementById(errorID);
			em.parentNode.removeChild(em);
		}
		// remove old images and classes from the required fields
		for(var i=0;i<reqfields.length;i++)
		{
			var f=document.getElementById(reqfields[i]);
			if(!f){continue;}
			if(f.previousSibling && /img/i.test(f.previousSibling.nodeName))
			{
				f.parentNode.removeChild(f.previousSibling);
			}
			f.className='';
		}
	// loop over required fields
		for(var i=0;i<reqfields.length;i++)
		{
	// check if required field is there
			var f=document.getElementById(reqfields[i]);
			if(!f){continue;}
	// test if the required field has an error, 
	// according to its type
			switch(f.type.toLowerCase())
			{
				case 'text':
					if(f.value=='' && f.id!='email'){cf_adderr(f)}							
	// email is a special field and needs checking
					if(f.id=='email' && !cf_isEmailAddr(f.value)){cf_adderr(f)}							
				break;
				case 'textarea':
					if(f.value==''){cf_adderr(f)}							
				break;
				case 'checkbox':
					if(!f.checked){cf_adderr(f)}							
				break;
				case 'select-one':
					if(!f.selectedIndex && f.selectedIndex==0){cf_adderr(f)}							
				break;
			}
		}
		return !document.getElementById(errorID);

		/* Tool methods */
		function cf_adderr(o)
		{
			// create image, add to and colourise the error fields
			var errorIndicator=document.createElement('img');
			errorIndicator.alt=errorAlt;
			errorIndicator.src=errorImg;
			errorIndicator.title=errorTitle;
			o.className=errorClass;
			o.parentNode.insertBefore(errorIndicator,o);

		// Check if there is no error message
			if(!document.getElementById(errorID))
			{
			// create errormessage and insert before submit button
				var em=document.createElement('div');
				em.id=errorID;
				var newp=document.createElement('p');
				newp.appendChild(document.createTextNode(errorMsg))
				// clone and insert the error image
				newp.appendChild(errorIndicator.cloneNode(true));
				em.appendChild(newp);
				// find the submit button 
				for(var i=0;i<of.getElementsByTagName('input').length;i++)
				{
					if(/submit/i.test(of.getElementsByTagName('input')[i].type))
					{
						var sb=of.getElementsByTagName('input')[i];
						break;
					}
				}
				if(sb)
				{
					sb.parentNode.insertBefore(em,sb);
				}	
			} 
		}
		function cf_isEmailAddr(str) 
		{
		    return str.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);
		}
	}
		
$(document).ready(function(){
	
});

$("ul.sf-menu").supersubs({ 
    minWidth:    15,   // minimum width of sub-menus in em units 
    maxWidth:    30,   // maximum width of sub-menus in em units 
    extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                       // due to slight rounding differences and font-family 
}).superfish({
				animation:   {opacity:'show',height:'show'},
				speed: 'slow'
		});


