;(function($) {
	
	var init = function() {
		
		// Homepage slides
		$('#banner').slides({
			container: 'slides',
			preload: true,
			preloadImage: '/_media/images/layout/loading.gif',
			play: 7000,
			pause: 2500,
			hoverPause: true,
			autoHeight: true
		});
		
		// Form labels over inputs
		$('form p.label-over label').labelOver('over-apply');
		
		$( banner_clickable );
		
	};
	
	// Form validation
	$('form.validate').validator({
		message: '' // Don't show any messages, using classes on the input field instead
	});
	$('form.validate').bind('onFail', function(e, errors) {
		if (e.originalEvent.type == 'submit') {
			$.each(errors, function(i,e)  {
				// This will only execute on the first element in the loop
				if( i == 0 )
				{
					$.scrollTo( this.input, 500, {offset:{top:-35}} );
				}
			});   
		}
	});
	
	// Clickable homepage banner
	var banner_clickable = function() {
		$('#home .slide').click(function(e){
			var link = $(this).find('.overlay a').attr('href');
			window.location = link;
		});
	};
	
	$( init );

})(jQuery); // !/ doc
