$(document).ready(function() {

//	http://jquery.malsup.com/cycle/
 	$('#cycle').cycle({
		fx:				'fade',
		sync:			true,
		timeout:	6000,
		pause:		1
		});

//		jQuery('figure.gallery-item a').attr('rel','gallery');
//		jQuery('figure.gallery-item a[rel="gallery"]').fancybox();

});


// Tabbed interface
$(document).ready(function(){  

	// When a link is clicked  
	$("a.tab-ui").click(function () {  

			// switch all tabs off  
			$(".active").removeClass("active");  

			// switch this tab on  
			$(this).addClass("active");  

			// slide all elements with the class 'content' up  
			$(".content-ui").animate({width: 'hide'});  

			// Now figure out what the 'title' attribute value is and find the element with that id.  Then slide that down.  
			var content_show = $(this).attr("title");  
			$("#"+content_show).animate({width: 'show'});  

	});  

});  


$(document).ready(function() {
// Expand Log-in Panel
		$("#open").click(function(){
			$("div#panel").slideDown('fast', 'swing');
		
		});	
		
		// Collapse Log-in Panel
		$("#close").click(function(){
			$("div#panel").slideUp('slow', 'swing');	
		});		
		
		// Switch buttons from "Log In | Register" to "Close Panel" on click
		$("#toggle a").click(function () {
			$("#toggle a").toggle();
		});		
		
		// Expand 'Make an Equiry' Panel
		$("#enquiry-open").click(function(){
			$("div#enquiry-panel").slideDown('fast');
		
		});	
		
		// Collapse 'Make an Enquiry' Panel
		$("#enquiry-close").click(function(){
			$("div#enquiry-panel").slideUp('slow');	
		});		
		
		// Switch buttons from "Make an Equiry" to "Close Panel" on click
		$("#toggle2 a").click(function () {
			$("#toggle2 a").toggle();
		});		
	

// Simple AJAX php contact form with validation
// http://www.devblog.co/jquery-basic-form-validation/
	
		$(function(){
			$('#contact_form').submit(function(e){
				e.preventDefault();
				var form = $(this);
				var post_url = form.attr('action');
				var post_data = form.serialize();
		
				var submit_form = false;
				var req_fields = $('input[rel=req]');
				var field, pcount = 0;
				req_fields.each(function(){
					field = $(this).val();
					if(field == '' || field == 'Required') {
						$(this).css('color', 'red').val('Required');
						pcount += 1;
					} else {
						$(this).css('color', '#000');
					}
				});
		
				if(pcount == 0) {
					submit_form = true;
				}
		
				if(submit_form) {
					$('#loader', form).html('<img src="http://eleganzaweddings.co.uk/images/loader.gif" /> Please Wait...');
					$.ajax({
						type: 'POST',
						url: post_url, 
						data: post_data,
						success: function(msg) {
							$(form).fadeOut(500, function(){
								form.html(msg).fadeIn();
							});
						}
					});
				}
			});
		});


});



