function IsEmail(email) {
    var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (regex.test(email)) return true;
    else return false;
} 

function openGive() {
	mywindow = window.open ("https://www.uwgc.org/index.cfm?fuseaction=home.donateonline#CFForm_1","mywindow","location=1,status=1,scrollbars=1,width=800,height=900");
    return false;
} 

 function processEmail() {
   var email = $(".emailInput").val();
		if (!IsEmail(email)) {  
		    $(".emailStatus").html("Invalid Email!");
			$(".emailInput").focus();  
		}else{
			var dataString = 'email=' + email;  
			//alert (dataString);return false;  	
			$.ajax({  
				type: "POST",  
				url: "/wp/wp-content/themes/uwgc/processEmail.php",  
				data: dataString,  
				success: function() {  
					$(".emailStatus").html("Email Submitted!");  
					$(".emailInput").val("your email address");
				}  
			});  
			
		}
		$("#emailStatus").fadeTo(500, 1).fadeTo(3000,1).fadeTo("slow", 0);
 }


$(document).ready(function(){
		

	$(".emailStatus").fadeTo(0,0);
    $("#nav li.n2 ul").hide();
	$("#nav li.n2").hover(function() { //When trigger is clicked...
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find(".n2 ul").slideDown('slow').show() //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("#nav li.n2 ul").slideUp('slow').hide(); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() { 
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
		
	});
/*
	$('#n2img').hover(function() {
		$(this).attr("src","/wp/wp-content/themes/uwgc/images/nav_advocate_on.jpg");
		}, function() {
			$('#n2img').attr("src",curimg);
		});
*/		
	curN2Img=$('#n2img').attr("src");
	$('.n2 img').hover(function() {
		$(this).attr("src","/wp/wp-content/themes/uwgc/images/nav_advocate_on.jpg");
		}, function() {
			$(this).attr("src",curN2Img);
		});

	$('.n1 img').hover(function() {
		$(this).attr("src","/wp/wp-content/themes/uwgc/images/nav_give_on.jpg");
		}, function() {
			$(this).attr("src","/wp/wp-content/themes/uwgc/images/nav_give.jpg");
		});
	$('.n3 img').hover(function() {
		$(this).attr("src","/wp/wp-content/themes/uwgc/images/nav_volunteer_on.jpg");
		}, function() {
			$(this).attr("src","/wp/wp-content/themes/uwgc/images/nav_volunteer.jpg");
		});		

   $(".subbutton").click(function(){  
 		processEmail();
	});
	
	$("form .emailInput").bind("keypress", function(e) {
             if (e.keyCode == 13) {
			     processEmail();
                 return false;
            }
    });
	
	$('a.linkprint').click(function() {
		window.print();
		return false;
	});
	
	$("#scroller").simplyScroll({
			autoMode: 'loop', 
			horizontal:  false
	});
	
});