/* Author: Andrew Hass

*/

$(document).ready(function() {
	$.address.change(function(event) {
		//checkHref();
	});
	
	$(function(){
			$().timelinr({
				orientation: 'vertical',
				issuesSpeed: 300,
				datesSpeed: 100,
				issuesSpeed: 500,
				arrowKeys: 'true',
				startAt: 2
			})
		});
	
	//$('.top').addClass('hidden');
	/*$.waypoints.settings.scrollThrottle = 50;
	$('#container').waypoint(function(event, direction) {
		$('.top').toggleClass('hidden', direction === "up");
	}, {
		offset: '-100%'
	}).find('#main-nav').waypoint(function(event, direction) {
		$(this).parent().toggleClass('sticky', direction === "down");
		event.stopPropagation();
	});
	
	$('.testimonial').each(function(){
		$(this).waypoint(function(event) {
			$(this).css('visibility', 'visible');
			$(this).toggleClass('bounceIn');
			event.stopPropagation();
		}, {
			offset: '75%',
			triggerOnce: true
		});
	});
	
	$('#img-about').waypoint(function(event) {
			$(this).css('visibility', 'visible');
			$(this).toggleClass('fadeIn');
			event.stopPropagation();
		}, {
			offset: '75%',
			triggerOnce: true
		});
	
	$('.animate').each(function(){
		$(this).waypoint(function(event, direction) {
			$(this).toggleClass('pulse');
			event.stopPropagation();
		}, {
			offset: '50%'
		});
	});*/
	
	/*$('.testimonial').waypoint(function(event) {
		$(this).css('visibility', 'visible');
		$(this).toggleClass('bounceIn');
		event.stopPropagation();
	}, {
		offset: '75%'
	});*/
	
	/*$('#about').waypoint(function(event) {
		$("#testimonials").children().toggleClass('bounceOut');
		event.stopPropagation();
	}, {
		offset: -225
	});*/

	$('#form-contact').submit(function() {
	    var isValid = true;
	    $(this).children("div").children(":input").each(function(i){
	    	if ((this.name == "name" || this.name == "email" || this.name == "phone") && this.value == "") {
	    		$(this).css("background-color", "#FFCC99");
	    		isValid = false;
	    	} else {
	    		$(this).css("background-color", "#fafafa");
	    	}
		});
	    
	    if (isValid) {
		    var queryString = $(this).serialize();
		    sendEmail(queryString);
			$(this).animate({"opacity": "hide"}, 200);
		}
		
		return false;
    });
});

function sendEmail(querydata) {
	$.ajax({
	  type: "POST",
	  url: "application/sendmail.php",
	  data: querydata,
	  success: function(){
	    onSendEmailComplete();
	  }
	});
}

function onSendEmailComplete(event) {
	$('#form-thank-you').animate({"opacity": "show"}, 200);
}





