$(document).ready(function(){
	
	/* Home Page Gallery */
	$('#slideshow')
		.before('<div id="slideNav">')
		.cycle({ 
	    fx:     'scrollDown',
		sync: true,
		speedIn:       1600,
		speedOut:      400,
		easeIn:  'easeOutBounce',
		easeOut: 'easeInBack',
		delay:   -2000,
	    speed:   500, 
	    timeout: 5000,
	    pause:   1,
		pager:  '#slideNav'
	});
	/* End Home Page Gallery */
	
	/* Remove Links from TagList */
	$('.tagList a').removeAttr('href');
	/* End Remove List */
	
	/* Nav Menu */
	$("#nav li ul").hide();
	
	$("#nav > li").bind("mouseenter",function(){
		$("#nav li ul").hide();
	      $("ul",this).show();
	    }).bind("mouseleave",function(){
	      $("#nav li ul").hide();
	    });
	
		var config = {    
		     sensitivity: 50, // number = sensitivity threshold (must be 1 or higher)    
		     interval: 200, // number = milliseconds for onMouseOver polling interval    
		     over: makeTall, // function = onMouseOver callback (REQUIRED)    
		     timeout: 500, // number = milliseconds delay before onMouseOut    
		     out: makeShort // function = onMouseOut callback (REQUIRED)    
		};

		function makeTall(){  
							$("#navCont").stop().animate({ 
							        height: "90px"
							      }, 	{
									                    duration: 'slow',
									                    easing: 'easeOutBounce'
									                } );		
		}
		function makeShort(){
			$("#navCont").stop().animate({ 
			        height: "30px"
			      }, 	{
					                    duration: 'slow',
					                    easing: 'easeOutBounce'
					                } );
		}

		$("#navCont").hoverIntent( config );
		
		// Go To Form and Color It.
		$("a[href='#contact']").bind("click",function(e){
			$("#contact").animate({backgroundColor: "#fe0"}, {duration: 'slow'}).animate({backgroundColor: "#000"}, 'fast');
		    });
	/* End Nav Menu */
	
	/* Clients List */
	$("#clientList").hide();
	$("#showList").bind("click",function(){
		$("#clientList").toggle('slow');
		// $.jGrowl("Hello world!");
		return false;
	    });
	/* End clients list */
	
	/* Show Portfolio Item ColorBox */
	$("a.iframe").colorbox({width:"980px", height:"1500px", iframe:true, opacity: 0.8});
	$("a.image").colorbox({scaleContent: true, maxWidth: "90%", opacity: 0.8});
	$("a.video").colorbox({scaleContent: true, maxWidth: "90%", opacity: 0.8});
	/* Show Portfolio Item */
	
	/* Contact Form Actions */
	$("#name,#email,#message").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
	
	
	$("#contact #submit").click(function(){
		
		$("#contact input").removeClass('errorField');
		
		 // show the red text spinner
		 $('#contact fieldset.second p').html('Checking fields...');
		
		/* Get and Check Name field */
		var name = $("#contact #name").val();
		if (name == "") {  
		      $("#contact #name").addClass('errorField');  
		      $("#contact #name").focus();
				$('#contact fieldset.second p').addClass('red').html('Please check your name.');
		      return false;  
		    }
		
		/* Get and Check Message field */
		var message = $("#contact #message").val();
		if (message == "") {  
		      $("#contact #message").addClass('errorField');  
		      $("#contact #message").focus();
				$('#contact fieldset.second p').addClass('red').html('Please check your message.');
		      return false;  
		    }
		
		/* Get and Check Email field */
		var email = $("#contact #email").val();
		function isValidEmailAddress(emailAddress) {
		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		return pattern.test(emailAddress);
		}
		if (email == "" || (isValidEmailAddress(email) == false) ) {  
		      $("#contact #email").addClass('errorField');  
		      $("#contact #email").focus();
				$('#contact fieldset.second p').addClass('red').html('Please check your email.');
		      return false;  
		    }
		
		/* Get Submit Action Value */
		// var action = $("#contact #submit").val();
		
		/* Create dataString for Ajax call */
		var dataString = 'name='+ name + '&email=' + email + '&message=' + message + '&submit=submit';  
		
		 //the main ajax request
		 $.ajax({
				type: "POST",
				data: dataString,
				url: "/wp-content/themes/badshark/contact.php",
				success: function(data, message) {
					$('#contact').html('<div class="messageOut"></div>');
					$('#contact .messageOut').html(data);
				}
		  });
		return false;
	});
	/* End Contact Form Actions */
	
});
