// execute your scripts when DOM is ready. this is a good habit
$(function() {		
		
	//scrollable items
	$("div.scrollable").scrollable();
	
	//watermark email subscription field
	$("#q").Watermark("Search site");

	//rotate offer/banner images
	$("#offer-featured-img").cycle({ 
	    fx:      'fade', 
    	speed:    1000, 
	    timeout:  3500 
	});
	$(".banner-rotate").cycle({ 
	    fx:      'fade', 
    	speed:    1000, 
	    timeout:  5000 
	});
	
	//stores logo hover
	$(".store").hover(
    	function () {
        	$(this).find(".store-logo").addClass("store-over");
		},
		function () {
        	$(this).find(".store-logo").removeClass("store-over");
		}
	);
	
	//open external links in new window
	$("a[href*='http://']:not([href*='"+location.hostname+"'])").attr("target","_blank");  
	$(".opennew").attr("target","_blank");  
	
	// when the form is submitted
	$('#vip-subscribe').submit( function(){
		
		var reg_email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/; 
	
		var inputcheck = $('#name');
		// if field has something in it, do submit actions, otherwise write out error
		if( inputcheck.val() == '' ){
			// add class to change colour
			inputcheck.addClass("required").get(0).focus();
			return false;
		}else{ inputcheck.removeClass("required"); }
		
		var inputcheck = $('#surname');
		// if field has something in it, do submit actions, otherwise write out error
		if( inputcheck.val() == '' ){
			// add class to change colour
			inputcheck.addClass("required").get(0).focus();
			return false;
		}else{ inputcheck.removeClass("required"); }
		
		var inputcheck = $('#iutdlt-iutdlt');
		// if field has something in it, do submit actions, otherwise write out error
		if( inputcheck.val() == '' || !reg_email.test( inputcheck.val() ) ){
			// add class to change colour
			inputcheck.addClass("required").get(0).focus();
			return false;
		}else{ inputcheck.removeClass("required"); }
		
		var inputcheck = $('#mobile');
		// if field has something in it, do submit actions, otherwise write out error
		if( inputcheck.val() == '' ){
			// add class to change colour
			inputcheck.addClass("required").get(0).focus();
			return false;
		}else{ inputcheck.removeClass("required"); }
		
		var inputcheck = $('#postcode');
		// if field has something in it, do submit actions, otherwise write out error
		if( inputcheck.val() == '' ){
			// add class to change colour
			inputcheck.addClass("required").get(0).focus();
			return false;
		}else{ inputcheck.removeClass("required"); }
					
	});
	
	//leasing brochure validation
	$('#leasing-brochure-contact #contact_form').submit( function(){
		
		var reg_email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/; 
	
		var inputcheck = $('#leasing_name');
		// if field has something in it, do submit actions, otherwise write out error
		if( inputcheck.val() == '' ){
			// add class to change colour
			inputcheck.addClass("required").get(0).focus();
			return false;
		}else{ inputcheck.removeClass("required"); }
		
		var inputcheck = $('#leasing_company');
		// if field has something in it, do submit actions, otherwise write out error
		if( inputcheck.val() == '' ){
			// add class to change colour
			inputcheck.addClass("required").get(0).focus();
			return false;
		}else{ inputcheck.removeClass("required"); }
		
		var inputcheck = $('#from');
		// if field has something in it, do submit actions, otherwise write out error
		if( inputcheck.val() == '' ){
			// add class to change colour
			inputcheck.addClass("required").get(0).focus();
			return false;
		}else{ inputcheck.removeClass("required"); }
		
		var inputcheck = $('#leasing_tel');
		// if field has something in it, do submit actions, otherwise write out error
		if( inputcheck.val() == '' ){
			// add class to change colour
			inputcheck.addClass("required").get(0).focus();
			return false;
		}else{ inputcheck.removeClass("required"); }
			
	});
	
});
