// JavaScript Document

	$(document).ready(function(){

	jQuery.event.add(window, "load", resizeFrame);
	jQuery.event.add(window, "resize", resizeFrame);
	function resizeFrame()
	{
		var windowsize = $(window).width();
		$("#wrapper").css('padding-left', (windowsize - 1024) / 5 );
		$("#footer").css('margin-left', (windowsize - 1024) / 5 );
	}

		$(".servicesbox").addClass("serviceshide");
		
		$("#ourservices").click(function(){
			  $(".servicesbox").slideToggle("slow");
			  $(this).toggleClass("servicesboxactive");
			  $(".ourservices").toggleClass("ourservicesopen");
		});
		
		$("#servicesbtn").hide();
		$("#locationsbtn").hide();
		
		$.fn.search = function() {
			return this.focus(function() {
				if( this.value == this.defaultValue ) {
					this.value = "";
				}
			}).blur(function() {
				if( !this.value.length ) {
					this.value = this.defaultValue;
				}
			});
		};
		$("#key").search();
		$("#name").search();
		$("#Mobile").search();
		$("#EmailAddress").search();
		$("#FirstName").search();
		$("#LastName").search();
		$("#JobTitle").search();
		$("#Organisation").search();
		$("#Telephone").search();
		$("#Password").search();
		$("#PasswordConfirm").search();
		$("#Username").search();
		$("#CoverNote").search();

        //Cycle through the Homepage Widgets - 'Latest News' and 'Portfolio'
		$(document).ready(function() {
		    $('#latestnewsbox').cycle({
		        fx: 'scrollHorz',
		        next: '#latestnewsboxnext',
		        prev: '#latestnewsboxprev',
		        timeout: 0,
		        speed: 500
		    });
		    $('#portfoliobox').cycle({
		        fx: 'scrollHorz',
		        next: '#portfolioboxnext',
		        prev: '#portfolioboxprev',
		        timeout: 0,
		        speed: 500
		    });
		});		

		//Registration Form Validation using the Bassistance jQuery Validation plugin
		$("#regForm").validate({
		    rules: {
		        Password: {
		            required: true,
		            rangelength: [6, 10]
		        },
		        EmailAddress: {// compound rule 
		            required: true,
		            email: true
		        },
		        PasswordConfirm: {
		            required: true,
		            equalTo: Password
		        },
		        Telephone: {
		            digits: true
		        },
		        Mobile: {
		            digits: true
		        },
		        FirstName: {
		            required: true
		        },
		        LastName: {
		            required: true
		        }
		    },
		    messages: {
		        Password: "Password length must be between 6 and 10 characters",
		        EmailAddress: "Please enter a valid email address",
		        FirstName: "Please enter your first name.",
		        LastName: "Please enter your last name",
		        Telephone: "Please enter only digits without spaces",
		        Mobile: "Please enter only digits without spaces",
		        PasswordConfirm: "Please reconfirm the password"
		    }
		});


		//Login Form Validation using the Bassistance jQuery Validation plugin
		$("#loginForm").validate({
		    rules: {
		        Password: {
		            required: true
		        },
		        Username: {// compound rule 
		            email: true,
		            required: true
		        }
		    },
		    messages: {
		        Password: "Please enter your password",
		        Username: "Please enter a valid email address"
		    }
		});

		//Lost Password Form Validation using the Bassistance jQuery Validation plugin
		$("#getpasswordForm").validate({
		    rules: {
		        EmailAddress: {
		            required: true,
		            email: true
		        }
		    },
		    messages: {
		        EmailAddress: "Please enter your email address"
		    }
		});    		

		//Job Application Form Validation using the Bassistance jQuery Validation plugin
		$("#applyJobForm").validate({
		    rules: {
		        FirstName: {
		            required: true
		        },
		        LastName: {// compound rule 
		            required: true
		        }
		    },
		    messages: {
		        FirstName: "Please enter your first name",
		        LastName: "Please enter your last name"
		    }
		});    	
	
});
