$(document).ready(function () {

	//open first
	$(".subDirectory").hide();
	$(".dirMainCategory:first").addClass("hover").find(".subDirectory").show();

	//categories hover function
	$(".dirMainCategory").mouseover(function(){
	  //hide all subcategoryes and remove classes
	    $(".subDirectory").hide();
	    $(".dirMainCategory").removeClass("hover");
	
	  //activate current
	    $(this).addClass("hover").find(".subDirectory").show();
	});

	//notifications close
	$(".closeNotification").click(function () {
		$(this).fadeTo(400, 0, function () { // Links with the class "close" will close parent
			$(this).slideUp(400);
		});
		return false;
	});

	//newsletter fields validation rule
	jQuery.validator.addMethod("requiredNewsletter", function(value, element) {
		return ((value != "First Name*") && (value != "Last Name*") && (value != "Email*"));
	}, " ");


	//form validation
	jQuery.validator.messages.required = "";
	$(".validateMe").each(function(){
		$(this).validate({
			errorClass: 'error',
			errorElement: 'span',
			invalidHandler: function(e, validator) {
				var errors = validator.numberOfInvalids();
				if (errors) {
					var message = errors == 1
						? 'You missed 1 field. It has been highlighted below'
						: 'You missed ' + errors + ' fields.  They have been highlighted below';
					$("div.error span").html(message);
					$("div.error").show();
				} else {
					$("div.error").hide();
				}
			},
			onkeyup: false,
			messages: {
				TG_VR_EMAIL: {
					required: " ",
					email: "Please enter a valid email address."
				},
				TG_EMAIL: {
					required: " ",
					email: "Please enter a valid email address."
				}				
			},
			debug:false
		});		
	})
	
	//nyroModal form validation
	jQuery.validator.messages.required = "";
	$(".validateNyroModal").each(function(){
		$(this).validate({
			errorClass: 'error',
			errorElement: 'span',
			invalidHandler: function(e, validator) {
				var errors = validator.numberOfInvalids();
				if (errors) {
					var message = errors == 1
						? 'You missed 1 field. It has been highlighted below'
						: 'You missed ' + errors + ' fields.  They have been highlighted below';
					$("div.error span").html(message);
					$("div.error").show();
				} else {
					$("div.error").hide();
				}
			},
			onkeyup: false,
			messages: {
				TG_VR_EMAIL: {
					required: " ",
					email: "Please enter a valid email address."
				},
				TG_EMAIL: {
					required: " ",
					email: "Please enter a valid email address."
				}				
			},
			submitHandler: function(form) {
				$(form).nyroModalManual();
				//alert('a');
				//form.submit();
			},
			debug:false
		});		
	})

});


	//product caluclated price
	function calculatePrice(url)
	{
		$.ajax({
			type: "POST",
			url: url,
			error: function() {
				alert("An error ocurred!");
			},
			success: function(data) {
				$(".product-price").html(data);
			}
		});
	};
