$(document).ready(function() {
   
        $(':input[title]').each(function() {
  var $this = $(this);
  if($this.val() === '') {
    $this.val($this.attr('title'));
  }
  $this.focus(function() {
    if($this.val() === $this.attr('title')) {
      $this.val('');
    }
  });
  $this.blur(function() {
    if($this.val() === '') {
      $this.val($this.attr('title'));
    }
  });
     
});

$(":range").rangeinput();

$('#range1').autoNumeric({aNeg: '-', aSign: '$', mDec: '0'}).trigger('change');

helser_smoothscroll();

});


// Smooth Scroll
        function helser_smoothscroll() {
            
               $('#arrow').click(function() {
        
       var newHash=this.hash;
       
       if(newHash != '' && newHash != '#' )
       {
           var target=$(this.hash).offset().top,
               oldLocation=window.location.href.replace(window.location.hash, ''),
               newLocation=this,
               duration=3000,
               easing='easeOutQuint';
        
            
            
            
           // make sure it's the same location      
           if(oldLocation+newHash==newLocation)
           {
              // animate to target and set the hash to the window.location after the animation
              $('html:not(:animated),body:not(:animated)').animate({ scrollTop: target }, duration, easing, function() {
        
                 // add new hash to the browser location
                 window.location.href=newLocation;
              });
        
              // cancel default click action
              return false;
           }
        
        }
    
    }); 
    }   
    
    
$(document).ready(function(){
	
	$('#message').hide();
	
	// Add validation parts
	$('#contact-form input[type=text], #contact-form input[type=number], #contact-form input[type=email], #contact-form input[type=url], #contact-form input[type=tel]').each(function(){
		$(this).after('<mark class="validate"></mark>');
	});
	
	// Validate as you type
	$('#firstname, #lastname, #phone').focusout(function() {
		if (!$(this).val()) 
			$(this).addClass('error').parent().find('mark').removeClass('valid').addClass('error');
		else 
			$(this).removeClass('error').parent().find('mark').removeClass('error').addClass('valid');
	});
	$('#email').focusout(function() {
		if (!$(this).val() || !isEmail($(this).val())) 
			$(this).addClass('error').parent().find('mark').removeClass('valid').addClass('error');
		else 
			$(this).removeClass('error').parent().find('mark').removeClass('error').addClass('valid');
	});
	$('#website').focusout(function() {
		var web = $(this).val();
		if (web && web.indexOf("://") == -1) {
			//$(this).addClass('error').parent().find('mark').removeClass('valid').addClass('error');
			$(this).val('http://' + web);
			$(this).removeClass('error').parent().find('mark').removeClass('error').addClass('valid');			
		} else if (web)
			$(this).removeClass('error').parent().find('mark').removeClass('error').addClass('valid');
		else 
			$(this).removeClass('error').parent().find('mark').removeClass('error').removeClass('valid');
	});
	
	
	$('#send').click(function() {
		$("#message").slideUp(200,function() {
			$('#message').hide();
		
			// Kick in Validation
			$('#firstname, #lastname, #phone, #range1, #website, #email').triggerHandler("focusout");
			
			if ($('#contact-form mark.error').size()>0) {
				$('#contact-form').effect('shake', { times:2 }, 75, function(){
					$('#contact-form input.error:first').focus();
				});				
				return false;
			}
			
		});
	});
	
	$('#contact-form').submit(function(){
		
		if ($('#contact-form mark.error').size()>0) {
			$('#contact-form').effect('shake', { times:2 }, 75);
			return false;
		}
		
		var action = $(this).attr('action');
		
 		$('#send')
			.after('<img src="assets/ajax-loader.gif" class="loader" />')
			.attr('disabled','disabled');
		
		$.post(action, { 
			fname: $('#firstname').val(),
			lname: $('#lastname').val(),
			email: $('#email').val(),
			phone: $('#phone').val(),
			website: $('#website').val(),
			comp: $('#competitors').val(),
			budget: $('#range1').val(),
		},
			function(data){
				$('#message').html( data );
				$('#message').slideDown();
				$('#contact-form img.loader').fadeOut('slow',function(){$(this).remove()});
				$('#contact-form #send').attr('disabled',''); 
				if(data.match('success') != null) $('#contact-form').slideUp('slow');
				
			}
		);
		
		return false; 
	
	});
	
	function isEmail(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);
	}
	
	function isNumeric(input) {
    	return (input - 0) == input && input.length > 0;
	}
	
});

