/*######################
	Atedrake website v1.1
	© 2010 Atedrake
	JS File for DOM
	Created : 11.14.2009 by Mike Kivikoski
	Last Modified  : 3.16.10 by Mike Kivikoski
	
	Please keep Last Modified up to date
	
	Table of Contents
		
		When DOM is ready:
			1. Form Validation
			2. Masthead inputs
			3. Masthead form hint 
			4. Masthead Form Validation
			5. Fadeout Masthead
			6. Portfolio Fact Rollover
			7. Process link
########################*/

$(document).ready(function(){
						   
	// 1.


	$('#contact-form').validate({
		rules: {
			email: {required: true,minlength:2,email: true},
			name: {required: true,minlength: 3},
			message: {required: true,minlength: 10}	
		},
		messages:{
			email: "Please enter a valid email",
			name: "Please enter your name",
			message: "Please enter your message (min 10 characters)"
		 },
		 submitHandler: function(form){
	 		 $(form).ajaxSubmit({
		 		 success: function() { 
	                $('#contact-form').hide();
	                $('.form').append("<div id='thanks'><h3>And it has started</h3><h4>Thanks for saying Hi!</h4> <p>We'll be in touch with you sooner then you think. Until then, <a href='http://www.twitter.com/atedrake'>follow us on twitter</a>.</p></div>"); 
	             }
	         });
		 }						 
	 });

	 
	// 2.
	 inputHints();						
				function inputHints() {
				
					//Define our vars
					var el = $('input[title]');
					var value = $('input[value]');
					var inputText = $('input[type="text"]');
					
					var submitGoods = $('#home #masthead #submit-goods');
					
					$(submitGoods).addClass('hide');
					/*

						value.each(function(j){
							if($(this).attr('value') !== $(this).attr('title')){
								$(this).addClass('value-defined');									
								return true
  							}
						});
*/
						
					/*
						inputText.each(function(e){
							if($(this).attr('value') !== $(this).attr('title')){
								$(submitGoods).removeClass('hide').addClass('show');
							}
						});
*/
						
						//Loop through our inputs with titles and assign empty values with full titles
						el.each(function(i){
							if($(this).attr('value') !== ''){				
								$(this).attr('value' , $(this).attr('value'));		
							} else if ($(this).attr('value') == ''){
								$(this).attr('value' , $(this).attr('title'));
								
							}
						 });
					
						// hook up the blur & focus
						el.focus(function() {
							if ($(this).attr('value') == $(this).attr('title'))
								$(this).attr('value', '');
								//$(this).addClass('value-defined');
						}).blur(function() {
							if ($(this).attr('value') == '')
								$(this).attr('value', $(this).attr('title'));
								//if ($(this).attr('value') == $(this).attr('title'))
									//$(this).removeClass('value-defined');									
							
	
									
						});
				}

	// 3.
		$(function(){
		
			var formHint = $('#home #masthead #form-hint');
			var fact = $('#home #masthead #fact');
			var submitGoods = $('#submit-goods');
			var mastheadInputs = $('#home #masthead h2 input[type="text"]');
			
			$(formHint).addClass('hide');
			$(submitGoods).addClass('hide');
			

			$(mastheadInputs).focus(function(){
				$(fact).removeClass('show').addClass('hide');
				$(formHint).removeClass('hide').addClass('show');
			}).blur(function(){ 
				$(formHint).removeClass('show').addClass('hide');
				$(fact).removeClass('hide').addClass('show');
			});


			$(mastheadInputs).each(function(e){
				$(this).focus(function(){
					if($(submitGoods).is(':visible')){
						
					}else{
						$(submitGoods).fadeIn('slow');						
					}
				})
			});
		});
		

	// 4.
	
		$('#masthead form').validate({
		rules: {
			your: {required: true,minlength:1},
			experience: {required: true,minlength:1},
			superDuper: {required: true,minlength:1},
			mname: {required: true,minlength:2},
			mcontact: {required: true, minlength: 3}
		},
		messages:{
			mname: "Please enter your name",
			mcontact: "Please enter your email or twitter"
		 },
		 submitHandler: function(form){
	 		 $(form).ajaxSubmit({
		 		 success: function() { 
	                $('#masthead #submit-goods').hide();
	                $('#masthead').append("<div id='mast-thanks'><h3>Thank you for participating!</h3><p>Your awesome Atedrake tagline has been successfully submitted! Soon we&rsquo;ll be placing some of the best taglines for the world to see.</p> </div>"); 
	             }
	         });
		 }						 
	 });

	
	//5 . 
	setTimeout(function(){
		$("#mast-thanks").fadeOut("slow", function () {
		$("#mast-thanks").remove();
		});
	}, 8000);   
	
	$('#masthead form h2 input').focus(function(){
		if($('#mast-thanks').is(':visible')){
			$('#mast-thanks').fadeOut('50');	
			$("#mast-thanks").remove();	
		}	
	});
	

	// 6.
	var portFact = $("#portfolio #fact");
	
	$(portFact).click(function(){
		window.location = '/contact.php';	
	});
	

	// 7.	
	$('#services #fact').click(function(){	
		window.location = "/process.php"	
	});
	

});//End jQuery