$(document).ready(function(){

	$(".btn-slide").click(function(){
		$("#panel").slideToggle("slow");
		$("input#name").focus();
		$(this).toggleClass("active"); return false;
	}); 

});

$(function() {

	$("#contact-form .error").hide();

	$(".contact-us").click(function() {
		$("html,body").animate({scrollTop: 0},"slow");
		window.setTimeout(function(){$(".btn-slide").click();}, 2000);
		return false;
	});	

	$(".button").click(function() {

		// validate and process form
		// first hide any error messages
		$("#contact-form .error").hide();
	
		var source = $("input#source").val();
	
		var name = $("input#name").val();
		if (name == "") {
			$("#contact-form .error").show();
			$("input#name").focus();
			return false;
		}

		var company = $("input#company").val();
		if (company == "") {
			$("#contact-form .error").show();
			$("input#company").focus();
			return false;
		}

		var phone = $("input#phone").val();
			if (phone == "") {
			$("#contact-form .error").show();
			$("input#phone").focus();
			return false;
		}

		var email = $("input#email").val();
		if (email == "") {
			$("#contact-form .error").show();
			$("input#email").focus();
			return false;
		}

		var message = $("textarea#message").val();
		if (message == "") {
			$("#contact-form .error").show();
			$("textarea#message").focus();
			return false;
		}
		

		var dataString = 'source=' + source + '&name='+ name + '&company=' + company + '&email=' + email + '&phone=' + phone + '&message=' + message;
		//alert (dataString);return false;
		
		$.ajax({
			type: "POST",
			url: "http://www.unwiredrevolution.com/send-mail.aspx",
			data: dataString,
			success: function() {
				$('#contact-form').html("<div id='message'></div>");
				$('#message').html("<img src='http://www.unwiredrevolution.com/images/heading-thank-you.gif' alt='thank you'>")
				.append("<p>Thank you for your interest in Unwired Revolution.  We will respond to your request within the next two business days.</p><p><a href='javascript:closeslider()'>close</a></p>")
				.hide()
				.fadeIn(1500, function() {
					//$('#message').append("<img id='checkmark' src='images/check.png' />");
				});
			
			window.setTimeout('$("#panel").slideUp("slow");',7000)	
				
			}
		});
	

		return false;

	});
});

function closeslider()
{
	$("#panel").slideUp("slow");
	$(this).toggleClass("active");
	return false;
}


//runOnLoad(function(){
//	$("input#name").select().focus();
//});
