//$(function() {

	if ($("#contact").length > 0) {
		$("#contact-form").validate();
	}
	
	if ($(".register").length > 0) {
		$("#contact-form").validate();
	}
	
	if ($("#farmers-markets").length > 0) {
		
		$( "#accordion" ).accordion({
			collapsible: true,
			autoHeight: false,
			navigation: true
		});
		
		// secure form
		$(".warning").remove();
		$.get('http://www.redhillfarm.com/scripts/token.php',function(txt) {

			// make sure your form has a class of .secure on it
			$('.secure').append('<input type="hidden" name="ts" value="'+txt+'" />');
		});
		// make sure your form has the id of #contact_form or change appropriatly validate form
		$("#validate-me").validate();
		
	}
	
	if ($("#newsletter").length > 0) {
		$(".warning").remove();
		$.get('http://www.redhillfarm.com/scripts/token.php',function(txt) {

			// make sure your form has a class of .secure on it
			$('.secure').append('<input type="hidden" name="ts" value="'+txt+'" />');
		});
		// make sure your form has the id of #contact_form or change appropriatly validate form
		$("#validate-me").validate();
	}
	
	if ($("#join-our-food-club").length > 0) {
		$(".warning").remove();
		$.get('http://www.redhillfarm.com/scripts/token.php',function(txt) {

			// make sure your form has a class of .secure on it
			$('.secure').append('<input type="hidden" name="ts" value="'+txt+'" />');
		});
		// make sure your form has the id of #contact_form or change appropriatly validate form
		$("#validate-me").validate();
	}
	
	$('.call-modal').each(
		function(){
			page_req = $(this).attr('href');
			$(this).colorbox({ href: page_req + " #content", opacity: 0 });
		}
	);
	
	$('.submit-btn').hover(function(){
					orig_marg_top = $(this).css('margin-top');
					new_marg_top = orig_marg_top.replace('px', '');
					new_marg_top = new_marg_top -2;
					new_marg_top = new_marg_top + 'px';
					$(this).css('margin-top',new_marg_top);
					$(this).css('height','81px');
	},
	function(){
					$(this).css('margin-top',orig_marg_top);
					$(this).css('height','79px');
	});
	
	$('.react').hover(function(){
					orig_marg_top = $(this).css('margin-top');
					new_marg_top = orig_marg_top.replace('px', '');
					new_marg_top = new_marg_top -2;
					new_marg_top = new_marg_top + 'px';
					$(this).css('margin-top',new_marg_top);
					
					orig_height = $(this).css('height');
					new_height = orig_height.replace('px', '');
					new_height++; new_height++;
					new_height = new_height + 'px';
					$(this).css('height',new_height);
	},
	function(){
					$(this).css('margin-top',orig_marg_top);
					$(this).css('height',orig_height);
	});
	
	$('.btn').hover(function(){
					$(this).css('margin-top','-2px');
					$(this).css('height','81px');
	},
	function(){
					$(this).css('margin-top','0px');
					$(this).css('height','79px');
	});
	
	
	// checkout
	function isPostcode(field) {
	  var regexp = /[a-zA-Z]{1,2}\d{1,2}\s\d{1}[a-zA-Z]{2}/;
	  var userpostcode = field.value;
	  if (regexp.test(userpostcode)) {
		return true;
	  } else {
	    return false;
	  }
	}
	
	if ($("#online-shop #validateme").length > 0) {
		$("#validateme").validate({
			rules: {
				shipping_zip: {
					required: true,
					remote: {
						url: "http://www.redhillfarm.com/scripts/check_postcode.php",
					    type: "post"
					},
				}
			}, messages: {
				shipping_zip: { remote: "We are unable to deliver to this post code"}
			}
		});
		$("#same_as_billing").append('<label for="use_billing_info">Use same details as above:</label><input type="checkbox" value="1" name="use_billing_info" id="use_billing_info" class="checkbox" />');
		$("input#use_billing_info").click(
			function(){
				if($(this).is(':checked')) {
					$("#shipping_first_name").attr('value', $("#first_name").attr('value'));
					$("#shipping_last_name").attr('value', $("#last_name").attr('value'));
					$("#shipping_address").attr('value', $("#address").attr('value'));
					$("#shipping_address2").attr('value', $("#address2").attr('value'));
					$("#shipping_city").attr('value', $("#city").attr('value'));
					$("#shipping_state").attr('value', $("#state").attr('value'));
					$("#shipping_zip").attr('value', $("#zip").attr('value'));
				} else {
					$("#shipping_first_name").attr('value', '');
					$("#shipping_last_name").attr('value', '');
					$("#shipping_address").attr('value', '');
					$("#shipping_address2").attr('value', '');
					$("#shipping_city").attr('value', '');
					$("#shipping_state").attr('value', '');
					$("#shipping_zip").attr('value', '');
				}
			}
		);
	}
	
	if ($("#online-shop").length > 0) {
		$(".multiple-weights select").change(function() {
			var selected_weight = $(this).val();
			selected_weight = selected_weight.replace('_boned', '');
			selected_weight = selected_weight.replace('_smoked', '');
			selected_weight = selected_weight.replace('_plain', '');
			if($(this).parent().parent().find(".hiddenFields").find("input[name='weight']").length > 0) {
				$(this).parent().parent().find(".hiddenFields").find("input[name='weight']").val(selected_weight);
			} else {
				$(this).parent().parent().find(".hiddenFields").append('<input type="hidden" value="' + selected_weight + '" name="weight">');
			}
		});
		$('select[name="item_options[modifier]"]').change(function(){
		        var product_size_name = $(this).children('option:selected').text();
		        $(this).parent().parent().find('input[name="item_options[product_size_name]"]').val(product_size_name);
		    }).trigger('change');
	}
	
//});
