the_selected_id = "none";
convio_normal = { "whatsatstake":"10520","getinvolved":"10519","policy":"10518","whoowns":"10517","donate":"10516"};
convio_hover = { "whatsatstake":"11006","getinvolved":"11004","policy":"11005","whoowns":"11007","donate":"11003"};
img_path = "https://secure2.convio.net/free/images/content/pagebuilder/";
	
	
//checks for a valid zip code
function CheckValidZip(thefield) {
	var filter = /^([0-9]{5})+$/;
	if (!filter.test(thefield)) {
		$("#signupalert").html("Please enter a valid zip code"); 
		return false; }
	else if (thefield==null || thefield==""){
		$("#signupalert").html("Please enter a zip code");
		return false;
	}
	return true;					
}

//checks for a valid email address   
function CheckEmailAddr(thefield) {
	var filter  = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(thefield)) {
		$("#signupalert").html("Please enter a valid email address");
		return false; }
	else if (thefield==null||thefield==""){
		$("#signupalert").html("Please enter an email address!");
		return false;
	}
	return true;		
}


jQuery.preloadImages = function() {
	for(var i = 0; i<arguments.length; i++)
	{
		jQuery("<img>").attr("src", arguments[i]);
	}
}



$(document).ready(function() {

	$.preloadImages(img_path+"11003.gif",
									img_path+"11004.gif",
									img_path+"11005.gif",
									img_path+"11006.gif",
									img_path+"11007.gif");
	
	$("#sectionnav a").prepend("&raquo;&nbsp;");

	$("#signupsubmit").hover( function() {
		$(this).addClass("submithover");
	}, function() {
		$(this).removeClass("submithover");
	});

	$("#signup form input").focus(function() {
 		if ($(this).val() == "email address" || $(this).val() == "zip") $(this).val("");
 	});

 	$("#addme").submit(function() {
 		
 		$("#homelink").hide();
 		
		if (!CheckEmailAddr($("#email").val()) || !CheckValidZip($("#zipcode").val())) {
			$("#signup #mesg").fadeOut("fast", function(){
				$("#signup #mesg").html("Please enter a valid email address and/or zip code!");
				$("#signup #mesg").fadeIn("normal");
			});

			
		} else {
	
		//else, do ajax thing
		$.post("/ajax/signup.php", { email:$("#email").val(), zipcode:$("#zipcode").val(), submitted:"yes" }, function(data) {
			if (data == "1") {
				$("#signup #mesg").fadeOut("fast", function(){
					$("#addme").fadeOut("fast");
					$("#signup").css("background-color","#eee");
					$("#signup #mesg").html("<b>Thanks for signing up for updates from StopBigMedia.com!</b> We've added you to our email list. (Don't forget to review <a href=\"http://www.freepress.net\">our privacy policy</a>)");
					$("#signup #mesg").fadeIn("normal");
				});	
			} else {
				$("#signup #mesg").fadeOut("fast", function(){
					$("#signup #mesg").html("Sorry, an error occurred. Please try again!");
					$("#signup #mesg").fadeIn("normal");
				});
			}}	
		);
		} //end else
		
	});
	
	$(".actbox").hover(function(){
		$(this).addClass("acthover");
	},function(){
		$(this).removeClass("acthover");
	});
	
	$(".actbox").click(function(){
		window.location = $(this).children("a:first").attr("href");
	});
	
	$("#sbm_logo").click(function(){
		window.location = "http://www.stopbigmedia.com/";
	});
	
	$('#navbar img').hover(function(){
		which = $(this).attr('id');
		if ($(this).attr('id') != the_selected_id) $(this).attr('src',img_path+ convio_hover[which] +".gif");
 	}, function() {
		which = $(this).attr('id');
		if ($(this).attr('id') != the_selected_id) $(this).attr('src',img_path+ convio_normal[which] +".gif");
 	});	


	$("a#minoritydetails").click(function() {
		$("#explanation").fadeIn("normal");
	});

	$("#explanation").click(function() {
		$("#explanation").fadeOut("fast");
	});
});

/*
$(window).load(function() {
	setTimeout('$("#sectionnav table").fadeIn("slow")',1000);
});
*/
