$(document).ready(function() {
	
	//Set default open/close settings
	$('.acc_container').hide(); //Hide/close all containers
	$('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container
	
	//On Click
	$('.acc_trigger').click(function(){
		if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
			$('.acc_trigger').removeClass('active').next().slideUp(); //Remove all .acc_trigger classes and slide up the immediate next container
			$(this).toggleClass('active').next().slideDown(); //Add .acc_trigger class to clicked trigger and slide down the immediate next container
		}
		return false; //Prevent the browser jump to the link anchor
	});
	
	
	$('.drop_down_wrap').hide();
	$('a.drop4nav').click(function(){
		$(this).toggleClass("active");
		$('#drop4div').fadeToggle();
		});

	
});

$(document).ready(function() {
	$('.Items').selectbox();
	$('#Items1').selectbox();
	
	
	$("#scroller").simplyScroll({
			autoMode: 'loop',
			pauseOnHover: true,
			frameRate: 20,
			speed: 1
		});
		
	$('#mycarousel').jcarousel({
		horizontal: true,
		auto: 1,
		wrap: 'last',
		scroll: 1
   });
   
   $("#basicCall").formHighlighter({
		classFocus: 'demoFocus',
		classBlur: 'demoBlur', 
		clearField:true
	});
   
   $("#basicCall1").formHighlighter({
		classFocus: 'demoFocus1',
		classBlur: 'demoBlur1', 
		clearField:true
	});

});

$(document).ready(function(){ 
jQuery(function() { 
		// show a simple loading indicator
		var loader = jQuery('<div id="loader">Loading...</div>')
			.css({position: "relative", top: "0px", left: "10px"})
			.appendTo("#msg1")
			.hide();
			
		jQuery().ajaxStart(function() { 
			loader.show();
		}).ajaxStop(function() {
			loader.hide();
		}).ajaxError(function(a, b, e) { 
			throw e;
		});
		
		
	jQuery.validator.addMethod('notDefaultValue', function( value, element ) {
		var returnVal = false;
		if (element.name == 'first_name') {
			if (value != 'First Name') {
				returnVal = true;
			}
		} else if (element.name == 'last_name') {
			if (value != 'Surname') {
				returnVal = true;
			}
		} else if (element.name == 'contact_number') {
			if (value != 'Contact Number') {
				returnVal = true;
			}
		}
		return returnVal;
	}, 'This field is required');
	
	jQuery.validator.addMethod('validUkNumber', function( value, element ) {
		var returnVal = true;
		value = value.replace(' ', '');
		value = value.replace('-', '');

		if ((value.length != 10) && (value.length != 11)) {
			returnVal = false;
		} else if ((value.substr(0, 2) != '01') && (value.substr(0, 2) != '02') && (value.substr(0, 2) != '07') && (value.substr(0, 2) != '08')) {
			returnVal = false;
		}

		return returnVal;
	}, 'Phone number must be 10 or 11 digits long and must start with 01, 02, 07 or 08');
	
	jQuery.validator.messages.required = "";

	$("#contactform2").validate({
		invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
					? 'You missed 1 field.'
					: 'You missed ' + errors + ' fields.<br>Please fill all the required fields';
				$("div.error span").html(message);
				$("div.error").show();
				$('#msg').hide();
			} else {
				$("div.error").hide();
			}
		},
		onkeyup: false,
		submitHandler: function() {
			$('#ajax_request').val('true');
			$("div.error").hide();
			jQuery("#contactform2").ajaxSubmit({
					//target: "#msg",
					success: function (data) {
						alert(data);
					}
				});	
			$('#msg').show();
			$('#contactform2 input:text').val('');
			$('#contactform2 textarea').val('');
		},
		messages: {
			email: {
				required: "invalid email",
				email: "invalid email"	
			}
		},
		rules: {
			first_name: {
				minlength: 2,
				notDefaultValue: true
			},
			last_name: {
				minlength: 2,
				notDefaultValue: true
			},
			contact_number: {
				minlength: 2,
				notDefaultValue: true,
				validUkNumber: true
			}
		},		
		debug: false
	});
	
jQuery.validator.messages.required = "";
	$("#contactform").validate({
		invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
					? 'You missed 1 field.'
					: 'You missed ' + errors + ' fields.<br>Please fill all the required fields';
				$("div.error span").html(message);
				$("div.error").show();
				$('#msg').hide();
			} else {
				$("div.error").hide();
			}
		},
		onkeyup: false,
		submitHandler: function() {
			$("div.error").hide();
			jQuery("#contactform").ajaxSubmit({
					target: "#msg",
				});	
			$('#msg').show();
			$('#contactform input:text').val('');
			$('#contactform textarea').val('');
		},
		messages: {
			email: {
				required: "invalid email",
				email: "invalid email"	
			}
		},
		debug: true
	});
});
		
});
		
		
$(document).ready(function(){ 
jQuery(function() { 
		// show a simple loading indicator
		var loader = jQuery('<div id="loader">Loading...</div>')
			.css({position: "relative", top: "0px", left: "10px"})
			.appendTo("#msg2")
			.hide();
			
		jQuery().ajaxStart(function() { 
			loader.show();
		}).ajaxStop(function() {
			loader.hide();
		}).ajaxError(function(a, b, e) { 
			throw e;
		});
		

jQuery.validator.messages.required = "";
	$("#contactform1").validate({
		invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
					? 'You missed 1 field.'
					: 'You missed ' + errors + ' fields.<br>Please fill all the required fields';
				$("div.error1 span").html(message);
				$("div.error1").show();
				$('#msg1').hide();
			} else {
				$("div.error1").hide();
			}
		},
		onkeyup: false,
		submitHandler: function() {
			$("div.error1").hide();
			jQuery("#contactform1").ajaxSubmit({
					target: "#msg1"
				});	
					$('#msg1').show();
					$('#contactform1 input:text').val('');
					$('#contactform1 textarea').val('');

		},
		messages: {
			email: {
				required: "invalid email",
				email: "invalid email"	
			}
		},
		debug:true
	});
});
		
});



