$(document).ready(function()
{
	// Toggle Grid
	$("div.grid").hide();
	var heightDoc = $(document).height();
	$("div.grid").css({height: heightDoc});
	
	$(document).keyup(function (e) { 
		if (e.which == 18) isAlt=false; 
	}).keydown(function (e) {
		if (e.which == 18) isAlt=true;
		if (e.which == 71 && isAlt == true) {
			$(".grid").toggle();
			// $(".grid").css('backgroundImage','url(images/grid-overlay.png)');
			return false;
		}
	});

	// Menu large hover stuff
 	function addDropBox(){
        $(this).find(".hoverBox").stop().animate({opacity:1}, 500).show();
    }
    function removeDropBox(){
        $(this).find(".hoverBox").stop().animate({opacity:0}, 500).hide();
    }

    var dropConfig = {
         interval: 0,
         sensitivity: 5,
         over: addDropBox,
         timeout: 0,
         out: removeDropBox
    };
    
	$("#mainMenu li").hover(
		function(){
			$(this).prev().addClass("noLine");
		},
		function(){
			$(this).prev().removeClass("noLine");
		}
	);

	// CODE FOR CLEARING FIELD	
	$.fn.clearOnFocus = function(){

	    /* No attribution required,
	       don't use excessively */

	    return this.focus(function(){
			$('input.emailBox').css("box-shadow", "inset 0 1px 0 #fff")
	        var v = $(this).val();
	        $(this).val( v === this.defaultValue ? '' : v );
	    }).blur(function(){
	        var v = $(this).val();
	        $(this).val( v.match(/^\s+$|^$/) ? this.defaultValue : v );
	    });

	};
	$('input.emailBox').clearOnFocus();
	
	// CODE FOR TESTIMONIAL REVOLVER
	// $('.testimonialsBox blockquote').quovolver();
	
	// REQUEST INFO PACK ANIMATION
	$('a.requestButton').click(function() {
		$("html, body").animate({ scrollTop: $(document).height() }, 1000);
		//$('input.emailBox').css("box-shadow", "0 0 50px #002E4F")
		$('span.thankYouMessage').hide();
		$('span.enterYourEmail').fadeIn(500)
		.fadeTo(500, 0.5)
		.fadeTo(500, 1)
		.fadeTo(500, 0.5)
		.fadeTo(500, 1)
		.fadeTo(500, 0.5)
		.fadeTo(500, 1)
		.fadeTo(2000, 1)
		.fadeOut(500);
		
		return false;
	 });
	
	
	// INFO PACK VALIDATION
		$('form#infoPack').submit(function() {
			$('form#infoPack span.error').hide();
			$('form#infoPack input.error').removeClass('error');
			$('form#infoPack span.tag').show();
			var hasError = false;
			$('.required').each(function() {
				if(jQuery.trim($(this).val()) == '') {
					$(this).parent().find('span.enterYourEmail').fadeIn('slow');
					$(this).addClass('error');
					hasError = true;
				} else if($(this).hasClass('email')) {
					var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
					if(!emailReg.test(jQuery.trim($(this).val())) || $(this).val() == "your@email.com") {
						$(this).parent().find('span.enterYourEmail').fadeIn('slow');
						$(this).addClass('error');
						hasError = true;
					}
				}
			});
			if(!hasError) {
				$('form#infoPack input.submitButton')
				.fadeTo(500, 0.5)
				.fadeTo(500, 1)
				.fadeTo(500, 0.5)
				.fadeTo(500, 1)

				var formInput = $(this).serialize();
				$.post($(this).attr('action'),formInput, function(data){
					$('form#infoPack input.submitButton')
					.parent().find('span#status').fadeIn('slow');
					$('form#infoPack input.submitButton').attr('disabled', 'disabled');
					$('span.thankYouMessage').fadeIn('slow');
				});
			}
			return false;
		});
});
