// my library 1.0
// 1.1 add image bold title and br on hyphen
// shadow around any image of class shadow

function setUpSubmit() {  // respond to online submit button
	if (validateInquiry()) {
		// proceed if accepted or return to form if cancelled
		var inqform = document.inquiryform;
		if (confirm("Thank you " + inqform.name.value + ", click OK to send?"))
			return true;
		else
			return false;
	} else
		return false;
}



// function to validate the booking form
function validateInquiry(){

	// get form
	var inqform = document.inquiryform;
	
	// test for name
	if (inqform.name.value == ""){
	alert("Please provide your name");
	inqform.name.select();
	return false;
	}
	// test for address
	if (inqform.address.value == ""){
	alert("Please provide your address");
	inqform.address.select();
	return false;
	}
	// test for dyatime phone
	if (inqform.phone_day.value == ""){
	alert("Please supply your daytime phone number");
	inqform.phone_day.select();	
	return false;
	}
	// test for evening phone
	if (inqform.phone_evening.value == ""){
	alert("Please supply your evening phone number");
	inqform.phone_evening.select();	
	return false;
	}	
	// test for email
	if (inqform.email.value == ""){
	alert("Please supply your email address");
	inqform.email.select();	
	return false;
	}		
	// test for activity
	if (inqform.activity.value == ""){
	alert("Please supply the activity you wish to book");
	inqform.activity.select();	
	return false;
	}	
	// test for cactivity date
	if (inqform.activity_date.value == ""){
	alert("Please supply the date of the activity you wish to book");
	inqform.activity_date.select();	
	return false;
	}		
	// test for participants
	if (inqform.participants.value == ""){
	alert("Please supply the number of participants");
	inqform.participants.select();	
	return false;
	}		
	// test for participants details
	if (inqform.participants_details.value == ""){
	alert("Please participant's details");
	inqform.participants_details.select();	
	return false;
	}		
	// test for deposit
	if (inqform.deposit.value == ""){
	alert("Please supply the 50% deposit");
	inqform.deposit.select();	
	return false;
	}		
	// test for ts and cs
	if (!inqform.ts_and_cs.checked){
	alert("Please confirm you have read and accept the terms and conditions");
	inqform.ts_and_cs.select();	
	return false;
	}		
	return true;

}

// post-submit callback 
function showResponse(responseText, statusText)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 
    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
        '\n\nThe output div should have already been updated with the responseText.'); 
} 


$(document).ready(function() {
						   
	var options = { 
        target:        '#resp',   // target element(s) to be updated with server response 
		beforeSubmit:  setUpSubmit,
//        success:       showResponse,  // post-submit callback 
		clearForm: true
    }; 
 
    // bind form using 'ajaxForm' 
  // $('#inquiryform').ajaxForm(options); 
	
	
						   
	// gradual display of unique selling points on Home page
	$('#homeusps').children('p:nth-child(1)').delay(500).fadeIn();	
	$('#homeusps').children('p:nth-child(2)').delay(1200).fadeIn();
	$('#homeusps').children('p:nth-child(3)').delay(1900).fadeIn();	
	$('#homeusps').children('p:nth-child(4)').delay(2600).fadeIn();	
	
//	$('#homemenu ul li').children().children('li:nth-child(1)').delay(1500).fadeIn();
	// menu control
//	$('#homemenu ul li').children().children().fadeIn();
/*	
	$('li.submenu').hover(function(){
		$('ul', this).fadeIn();
		}, function() {	
		$('ul', this).fadeOut();
	});	
	*/
/*
	$('li.submenu').hover(function(){
		$('li.submenu ul').fadeOut(0);						
		$('ul', this).fadeIn('slow');

	}, function() {
		$('li.submenu ul').fadeOut();
	});	
	
	$('li.submenu').hover(function(){
		$('ul', this).stop().css({visibility:'visible'},{queue:false,duration:500});
	}, function() {
		$('ul', this).stop().css({visibility:'hidden'},{queue:false,duration:500});
	});	
	
	*/	
	$('#homemenu a').each(function(index) {	// select this page in menu and top level item too
		loc = window.location.toString();
		nextMenuItem = $(this).eq(0).attr('href');
		if(loc.indexOf(nextMenuItem) != -1) {
			$(this).parent().children('a').addClass('selected');	
			if ($(this).parent().parent().parent().children('a').hasClass('top')) {
				$(this).parent().parent().parent().children('a').addClass('selected');	
			}
		}
		//alert(loc+'   '+nextMenuItem);							
	});
	
	$('#mainmenu a').each(function(index) {	// select this page in menu and top level item too
		loc = window.location.toString();
		nextMenuItem = $(this).eq(0).attr('href');
		if(loc.indexOf(nextMenuItem) != -1) {
			$(this).parent().children('a').addClass('selected');	
			if ($(this).parent().parent().parent().children('a').hasClass('top2')) {
				$(this).parent().parent().parent().children('a').addClass('selected');	
			}
		}
		//alert(loc+'   '+nextMenuItem);							
	});	
	
	
	
	$('li.submenu').hover(function(){
		$('ul', this).animate({height:'200px'},{duration:700});
	}, function() {
		$('li.submenu ul').stop().animate({height:'0'},{queue:false,duration:0});
	});		
		
	$('li.submenu').click(function(){
		$('li.submenu ul').css('height', '0');
	});		
	
	$('.shadow').each(function(index) {
		picwidth = parseFloat($(this).width()) + 5 + "px";	
		picheight = parseFloat($(this).height()) + 5 + "px";	
		pic = "pic" + index;
		dotpic = ".pic" + index;
		picTitle = $(this).attr('alt');
		if (picTitle.indexOf(' - ') !=-1) picTitle = "<b>" + picTitle.replace(" - ", "</b><br />");
		
		$(this).replaceWith('<div class="shadowout ' + pic + '"  ><div class="shadowin"><div class="imagecap"><img src="' + $(this).attr('src') + '" /><div class="caption"><p>' + picTitle + '</p></div></div><div class="tr"><img src="images/bg-filler.gif" /></div><div class="bl"><img src="images/bg-filler.gif" /></div><div class="br"><img src="images/bg-filler.gif" /></div></div></div>');
	
		$(dotpic).css({ // addspace for shadow
		'width': picwidth,
		'height': picheight
		});
		
		if ($(this).hasClass('rightimage')) 
			$(dotpic).addClass('rightimage');
		if ($(this).hasClass('leftimage')) 
			$(dotpic).addClass('leftimage');			
		
	});
	
	$('.justCaption').each(function(index) {
		picwidth = parseFloat($(this).width())  + "px";	
		picheight = parseFloat($(this).height())  + "px";	
		pic = "pic2" + index;
		dotpic = ".pic2" + index;
		
		$(this).replaceWith('<div class="shadowout ' + pic + '"  ><div class="shadowin"><div class="imagecap"><img src="' + $(this).attr('src') + '" /><div class="caption"><p>' + $(this).attr('alt') + '</p></div></div></div></div>');
	
		$(dotpic).css({ // addspace for shadow
		'width': picwidth,
		'height': picheight
		});
		
		if ($(this).hasClass('rightimage')) 
			$(dotpic).addClass('rightimage');
		if ($(this).hasClass('leftimage')) 
			$(dotpic).addClass('leftimage');			
		
	});

	//Full Caption Sliding (Hidden to Visible)
	$('.imagecap').hover(function(){
		$(".caption", this).stop().animate({bottom:'0px'},{queue:false,duration:500});
	}, function() {
		$(".caption", this).stop().animate({bottom:'-45px'},{queue:false,duration:500});
	});

	// toggle maps
//	$('.map:eq(1)').hide();
	$('a.toggle').click(function() {
		if($('.map:eq(0)').is(':hidden')) {
			$('.map:eq(1)').fadeOut('slow');
			$('.map:eq(0)').fadeIn('slow');			
		} else {
			$('.map:eq(0)').fadeOut('slow');
			$('.map:eq(1)').fadeIn('slow');					
		}
		
		return false;
	});		
		
	//Facebook div sliding
	$('#facebook').hover(function(){
								  //alert("fred");
		$(this).stop().animate({width:'131px'},{queue:false,duration:500});
	}, function() {
		$(this).stop().animate({width:'40px'},{queue:false,duration:500});
	});	
	
});

