/*
 * My js Functions
 *
 */
  
$(document).ready(function() {$.backstretch("http://www.wilbursmithbooks.com/userfiles/images/backgrounds/diver-trim.jpg", {
		speed: 150
	});
	
	// social media tabs
	// setup ul.tabs to work as tabs for each div directly under div.panes
	$("ul.tabs").tabs("div.panes > div");
	
	
	$("a[rel*=lightbox]").lightBox(); // Select all links that contains lightbox in the attribute rel
	// open external links in new window (without classes)
	$("a[href*='http://']:not([href*='http://www.wilbursmithbooks.com/']),[href*='https://']:not([href*='http://www.wilbursmithbooks.com/'])").click(function() {
		window.open(this.href);
		return false;
	});
	
	
	// initialize scrollable - homepage covers 
	$(".scrollable").scrollable();
	
	
	// bind enquiry form using ajaxForm 
	$('#freeform').ajaxForm({ 
        // target identifies the element(s) to update with the server response 
        beforeSubmit: validate_enquiry_form,
        target: '#response', 
 
        // success identifies the function to invoke when the server response 
        // has been received; here we apply a fade-in effect to the new content 
        success: function() {
        	$('#contact-form').hide();
            $('#response').fadeIn('slow');  
        } 
	});
	function validate_enquiry_form(formData, jqForm, options) { 
	    // fieldValue is a Form Plugin method that can be invoked to find the 
	    // current value of a field 
	    // 
	    // To validate, we can capture the values of both the username and password 
	    // fields and return true only if both evaluate to true 
	 
	    var firstnameValue = $('input[name=firstname]').fieldValue();
	    var lastnameValue = $('input[name=lastname]').fieldValue();
	    var emailValue = $('input[name=email]').fieldValue();
	 
	    // usernameValue and passwordValue are arrays but we can do simple 
	    // "not" tests to see if the arrays are empty 
	    if (!firstnameValue[0] || !lastnameValue[0] || !emailValue[0]) { 
	        alert('Please ensure you have supplied your First Name, Last Name, and Email address.'); 
	        return false; 
	    } 
	 };
	
	
});

