$(document).ready(function() {
 
	//Navigation Drop-Down 
	
	$("#navigation ul ul").css({display: "none"}); // Opera Fix
		$(" #navigation li ").hover(function(){
				$(this).find('ul:first').stop(true,true).delay(300).css({visibility: "visible",display: "none"}).slideDown(400);
				},function(){
				$(this).find('ul:first').stop(true,true).delay(300).fadeOut(200);
	});  
		
		
	//Portfolio hover
	
	$("a.portfolio-item").hover(function(){
			$(this).find('span:first').stop(false,true).fadeIn(400);
			},function(){
			$(this).find('span:first').stop(false,true).fadeOut(200);
	});
		
	//Cufon replacement
	
		Cufon.replace("h1");
		Cufon.replace("h2");
		Cufon.replace("h3");
		Cufon.replace("h4");
		Cufon.replace("#recent-posts h1",{textShadow: '0 2px white'});
		Cufon.replace("#navigation ul li a",{textShadow: '0 1px white',hover: true});
		Cufon.replace(".btn_alt",{textShadow: '0 1px #291937'});
		Cufon.replace(".btn_white");
		Cufon.replace(".name");
		
	// Contact form
	jQuery('form#contactForm').submit(function() {
		jQuery('form#contactForm .error').remove();
		var hasError = false;
		jQuery('.requiredField').each(function() {
			if(jQuery.trim(jQuery(this).val()) == '') {
				var labelText = jQuery(this).prev('label').text();
				jQuery(this).parent().append('<span class="error">You forgot to enter your '+labelText+'.</span>');
				jQuery(this).addClass('inputError');
				hasError = true;
			} else if(jQuery(this).hasClass('email')) {
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				if(!emailReg.test(jQuery.trim(jQuery(this).val()))) {
					var labelText = jQuery(this).prev('label').text();
					jQuery(this).parent().append('<span class="error">You entered an invalid '+labelText+'.</span>');
					jQuery(this).addClass('inputError');
					hasError = true;
				}
			}
		});
		if(!hasError) {
			var formInput = jQuery(this).serialize();
			jQuery.post(jQuery(this).attr('action'),formInput, function(data){
				jQuery('form#contactForm').slideUp("fast", function() {				   
					jQuery(this).before('<p class="thanks"><strong>Thanks!</strong> Your email was successfully sent.</p>');
				});
			});
		}
		
		return false;
		
	});
	
	// Take a tour functionality
	$('ul#tour li.current a').animate({marginBottom: '20'})
					$('.step').click(function() {
						if($(this).parent().hasClass('current')) {
							

						} else {
							$('ul#tour li.current div').slideUp('slow',function() {
								$(this).parent().removeClass('current');
							}).siblings('a').animate({marginBottom: '0'});
							$(this).animate({marginBottom: '20'}).siblings('div').slideToggle('slow',function() {
								
								$(this).parent().toggleClass('current');
							});

						}
						return false;
	});
});
