//Page Scroller
function scrollpage(anchor){
    $('html, body').animate({scrollTop: $("#" + anchor).offset().top-20 }, 300);
}

//Hide-Show Div
function showdiv(id) {
	$("#" + id).fadeIn(300);
	return false;
};

function hidediv(id) {
	$("#" + id).fadeOut(300);
	return false;
};

//Twitter Feed
getTwitters('tweets', { 
  id: 'jbatterton', 
  count: 2, 
  enableLinks: true, 
  ignoreReplies: false, 
  clearContents: true,
  template: '<p>@jbatterton-<br /> %text% <br /><span>%time%</span></p>'
});

//Contact Form AJAX
function ajaxFunction(){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("There has been an error. Please try again later.");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			document.myForm.time.value = ajaxRequest.responseText;
		}
	}
	var contact_name = document.getElementById('C1').value;
	var email        = document.getElementById('C2').value;
	var url          = document.getElementById('C3').value;
	var message      = document.getElementById('C4').value;
	
	if (contact_name == 'Name*' || email == 'Email*' || message == 'Message*'){
	}else{
	
	var queryString = "?contact_name=" + contact_name + "&email=" + email + "&url=" + url + "&message=" + message;
	ajaxRequest.open("GET", "/contact_post.php" + queryString, true);
	ajaxRequest.send(null); 
	
	$('html, body').animate({scrollTop: $("#nav").offset().top-20 }, 300);
	$("#contact form div.form").fadeOut(300);
	$("#contact form div.success").fadeIn(300);
	
    }
}

//Fix Contact Height
function fix_contact(){
  var document_height = $(document).height();
    
  if (document_height > 1000){
    $("#contact").animate ({ height: document_height }, 300);   
  }else{
  }
}