$(document).ready(function(){
	
    $.simpleWeather({
            zipcode: '91702',
            unit: 'f',
            success: function(weather) {
                    html = '<p><img src="' + weather.thumbnail + '" alt="' + weather.currently + '" align="left"/>';
                    html += ''+weather.temp+'&deg; / '+weather.currently+'<br />at Rosedale</p>';

                    $("#weather").html(html);
            },
            error: function(error) {
                    $("#weather").html("<p>"+error+"</p>");
            }
    });	
    
    // Main Navigation
    $("nav").dropmenu();
	
	// Popup Window
	$('a.pop').click(function(){
		window.open(this.href,"_blank","width=970,height=751,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0");
		return false;
	});

	$("a[rel^='prettyPhoto[sidebarCommunity]']").prettyPhoto({animationSpeed:'slow',slideshow:4000, autoplay_slideshow: false});

	// Question Form
	$("#sidebarSubmitAQuestionSubmit").click( function(){

		result = $("#submitAQuestion").validate({ 
			rules: {
				firstName: "required",
				lastName: "required",
				email: {
					required: true,
					email: true
				},
				message: "required"
				
			},
			messages: {
				firstName: "",
				lastName: "",
				email: "",
				message: ""
			}
	    }).form();
	    
	    
		if (result === true){


			var firstName = $('input[name=firstName]');
	        var lastName = $('input[name=lastName]');
	        var email = $('input[name=email]');
	        var message = $('textarea[name=message]');
	        var middleName = $('input[name=middleName]');
	        var comment = $('input[name=comment]');
		
	        var data = 'firstName=' + firstName.val() + '&lastName=' + lastName.val() + '&email=' + email.val() + '&message=' + message.val() + '&middleName=' + middleName.val() + '&comment=' + comment.val();
	         
	        //start the ajax
	        $.ajax({
	            url: "/ajax/questionFormProcess.php",
	            type: "POST",        
	            data: data,    
	            cache: false,
	            success: function (html) {             
	                //if process.php returned 1/true (send mail success)
	                if (html==1) {    
	                
	                	$("#submitAQuestion").html('<p><br /></p><h3>Thank You!</h3><p>Thank you for submitting a question. You should receive a response in a day or two.</p><p><br /></p>');             
	                	                     
	                //if process.php returned 0/false (send mail failed)
	                } else alert(html);              
	            }      
	        });
	    }
	    
		return false;
	});
		
		
});	

