$(function(){
	$(".scrollable").scrollable({ vertical: true, mousewheel: true });
	
	// reset email form
	$("#resetForm").click(function(){
		$("#eml-alert").html('');					   
	});
	
	// process email form
	$("#sendEmail").click(function(){
		$("#sendEmail").disabled = true;
		$("#sendEmail").text("Processing. Please Wait...");
		
		// insert ajax function to send email
		  var url = $("input#url").val();
		  var email = $("input#email").val();
		  var name = $("input#name").val();
		  var project = $("input#project-type").val();
		  var info = $("input#additionalinfo").val();
		  var dataString = 'name='+ name + '&email=' + email + '&url=' + url + '&project=' + project + '&additionalinfo=' + info;
		  
		  $.ajax({
			  method: "POST",
			  url: "sendemail.php",
			  data: dataString,
			  dataType: "text",
			  success: function(o) {

				if(o.match(/^OK/) != null) {
					//alert('Your message has been sent!');
					$("#eml-alert").html('Your message has been sent!').css('color','#090');
					$("input#url").val('');
					$("input#email").val('');
					$("input#name").val('');
					$("select#project-type").val('');
					$("input#additionalinfo").val('');
				} else {
					//alert(o);
					var strReplaceAll = o;
					var intIndexOfMatch = strReplaceAll.indexOf( "\n" );
					 
					// Loop over the string value replacing out each matching
					// substring.
					while (intIndexOfMatch != -1){
						// Relace out the current instance.
						strReplaceAll = strReplaceAll.replace( "\n", "<br />" )
						 
						// Get the index of any next matching substring.
						intIndexOfMatch = strReplaceAll.indexOf( "\n" );
					}
					
					$("#eml-alert").html(strReplaceAll).css('color','#900');
				}

				  $('#sendEmail').text("Send Email");
				  $('#sendEmail').disabled = false;
				}
			});
		  return false;
	});
	
	$('#tweets').tweetable({username: 'dalewatkinscom', time: false, limit: 4});
});