$(document).ready(function() {
	$('#dropmenu-title').click(function() {
		$('#dropmenu').toggleClass('hidden');		
	});

	$("img.rollover").hover(
		function() { $(this).attr("src", $(this).attr("src").split("_s.").join("_o.")); },
		function() { $(this).attr("src", $(this).attr("src").split("_o.").join("_s.")); }
	);
	grabTwitterFeeds();
});

function grabTwitterFeeds() {
	/* at the very bottom, grab twitter feeds */
	var script = document.createElement("script");
	script.src = "http://twitter.com/statuses/user_timeline/estorick.json?callback=twitterCallback2&count=4";
	script.type = "text/javascript";
	document.getElementsByTagName("head")[0].appendChild(script);
}


/* check email @ mailing list */
function checkForm(formObj) {
	var formOK = true;
	alert_info = "";
		
	formOK = checkEmail(formObj.email.value);

	if (formOK == true) {
		formObj.submit();
	}
	else {
		window.alert(alert_info);
	}

}

function checkEmail(email) {

	if (email.length == 0) {
		alert_info += "You must provide your e-mail address.\n";
		return false;
	}
	if (email.indexOf("/") > -1) {
		alert_info += "E-mail address has invalid character: /\n";
		return false;
	}
	if (email.indexOf(":") > -1) {
		alert_info += "E-mail address has invalid character: :\n";
		return false;
	}
	if (email.indexOf(",") > -1) {
		alert_info += "E-mail address has invalid character: ,\n";
		return false;
	}
	if (email.indexOf(";") > -1) {
		alert_info += "E-mail address has invalid character: ;\n";
		return false;
	}
	if (email.indexOf("@") < 0) {
		alert_info += "E-mail address is missing @\n";
		return false;
	}
	if (email.indexOf("\.") < 0) {
		alert_info += "E-mail address is missing .\n";

		return false;
	}

	return true;
}

function checkContactForm(formObj) {
	var formOK = true;
	alert_info = "";

	if (formObj.name.value == "") { //check name
		alert_info += "You must provide your name.\n";
		formOK = false;
	}
	
	formOK = checkEmail(formObj.email.value); // check email
	
	count = 0;  // check select box
	chks = document.getElementsByName("nature[]");
	for (var i=0; i<chks.length; i++) {
		if (chks[i].checked == false) {
			count ++;
		}
	}
	if (count == chks.length) {
		alert_info += "You must check at least one checkbox. \n";
		formOK = false;
	}


	
	if (formOK == true) {
		formObj.submit();
	}
	else {
		window.alert(alert_info);	
	}


}
