$(document).ready(function() {
// Background //
	$.fn.supersized.options = {  
		startwidth: 640,  
		startheight: 480
	};
	$('#background').supersized(); 

// Scroll //
	$("#scrollContainer .scroll").scrollable({size: 1, clickable: false}).circular().navigator(".navi").autoscroll({ 
    	steps: 1, 
    	interval: 10000         
	});

// Overlay //
	$("a[rel]").overlay({
		expose: {
        	color: '#000',
		    loadSpeed: 200,
        	opacity: 0.6
    	}, 
		effect: 'apple'
	});

// Contact Form //
	$('input[type="text"], textarea').addClass("defaultField");   // Add and remove active classes for the form inputs
	$('input[type="text"], textarea').focus(function() { 
		$(this).removeClass("defaultField").addClass("selectedField"); 
    		if (this.value == this.defaultValue){ 
      		this.value = ''; 
    	} 
    	if(this.value != this.defaultValue){ 
      		this.select(); 
    	} 
  	}); 
  	$('input[type="text"], textarea').blur(function() { 
    	$(this).removeClass("selectedField").addClass("defaultField"); 
    		if ($.trim(this.value == '')){ 
      		this.value = (this.defaultValue ? this.defaultValue : ''); 
      	} 
    }); 
	jQuery(function() {
		// show a simple loading indicator
		var loader = jQuery('<div id="loader"><img src="images/loading.gif" alt="loading..." /></div>')
			.css({position: "relative", top: "1em", left: "25em"})
			.appendTo("body")
			.hide();
		jQuery().ajaxStart(function() {
			loader.show();
		}).ajaxStop(function() {
			loader.hide();
		}).ajaxError(function(a, b, e) {
			throw e;
		});
		var v = jQuery("#contactForm").validate({
			submitHandler: function(form) {
				jQuery(form).ajaxSubmit({

					success: function() {  
					  // $('#contactForm .submit').attr("disabled", "disabled");
					   $('#contactForm').hide();  
					   $('#output').html("<h2>Your message has been sent!</h2>")  
					   .append("<p>We will be in touch soon.</p>")  
					   .hide()  
					   .fadeIn(1500, function() {  
						 $('#output');  
					   });
					}  					
				});
			},
			rules: { 
            	name: "required",
            	email: { 
                	required: true, 
            	   	email: true 
            	},
				enquiry: {
					required: true
				}
		  	}, 
        	messages: { 
            	name: "Required", 
            	email: { 
               		required: "Required", 
					email: "Invalid"
            	},
            	enquiry: {
					required: "Required"
				}
        	}, 
        	success: function(label) { 
            	label.html(" ").addClass("checked"); 
        	}
		});
	});
});
