jQuery(document).ready(function(){  
  
  
    $("#nav-menu li a").mouseover(function() { 

        $(this).parent().find("ul.subnav").slideDown('fast').show(); 
  
        $(this).parent().hover(function() {  
        }, function(){  
            $(this).parent().find("ul.subnav").stop(true, true).hide();
        });  
  
        });

			$('input[name=callback]').keyup(function(e) {

				var code = e.keyCode || e.which;
				 if(code == 13) {

				   call();

					return false;
				 }else{
					return false;
				}

			});	
		
				
});

function call(){
	var fail = 0;
	
	if($('input[name=callback]').val().length < 6){
		
		$('input[name=callback]').css({'borderColor':'#d73636', 'borderWidth':'2px', 'padding':'4px'});
		$('input[name=callback]').val('Num invalid');
		$('#button').css({'backgroundColor':'#f2bbbb', 'borderColor':'#d73636'});
		var fail = 1;
	}else{
		
		var number = $('input[name=callback]').val();
		
	}
	
	if(fail == 0){
	
	$('#button').html('<img src=\"http://www.prettyklicks.com/blog/wp-content/themes/Pretty-Klicks/images/loader.gif\" />');
	
	
	$.ajax({
		type: "POST",
		url: "http://www.prettyklicks.com/blog/wp-content/themes/Pretty-Klicks/process.php",
		data: "call=1&number=" + number,
		dataType: 'json',
		success: function(msg){
			
			if(msg.state == "fail"){
				
				if(msg.message == "invalid"){
					
						$('input[name=callback]').css({'borderColor':'#d73636', 'borderWidth':'2px', 'padding':'4px'});
						$('input[name=callback]').val('Num invalid');
						
						$('#button').css({'backgroundColor':'#f2bbbb', 'borderColor':'#d73636'});
						$('#button').html('Submit');
						
				}else if(msg.message == "fail"){
					
						$('input[name=callback]').css({'borderColor':'#aaaaaa', 'borderWidth':'1px', 'padding':'5px'});
						$('input[name=callback]').val('Try again');
						
						$('#button').css({'backgroundColor':'#f2bbbb', 'borderColor':'#d73636'});
						$('#button').html('Submit');
					
				}
			}else if(msg.state == "success"){
				
				$('input[name=callback]').css({'borderColor':'#aaaaaa', 'borderWidth':'1px', 'padding':'5px'});
				$('input[name=callback]').val('Sent!');
				
				$('#button').css({'backgroundColor':'#b6dab1', 'borderColor':'#70a868'});
				$('#button').html('Done!');
				$('#button').attr('onclick', '');
				
			}
		}
	});
  }
}


