/**
 *
 * Site functions
 *
 **/
$(document).ready(function(){
	
	// start tummy sick animation
	tummy_sick();
	
	// "setInterval" is used to repeatedly check if these two elements are NOT being “:animated”. 
	// If this condition is not met, then it means that atleast one of them is still getting animated. 
	// So, "setInterval" will check for the same condition again in 200 ms until the condition is met.
	var wait = setInterval(function() {
		if( !$("#animation .tummy-left").is(":animated") ) {
			clearInterval(wait);
			tear_falls();
		}
	}, 200);	
});

var tummy_i = 0;

function tummy_sick() {
	// tummy sick animation
	var t_left = $('#animation .tummy-left');
	var t_right = $('#animation .tummy-right');
	
	t_left.animate({left:"+=5px"}, 500);
	t_right.animate({left:"-=5px"}, 500);
	t_left.animate({left:"-=5px"}, 500);
	t_right.animate({left:"+=5px"}, 500);
	
	tummy_i++;
	if ( tummy_i < 5 ) {
		tummy_sick();	
	}
}

function tear_falls() {
	// animations occur after tummy animation is complete
	var tear = $('#animation .tear');
	
	tear.animate({top:"75px"}, 1000, function() {
		tear.hide(5, function() { 
			tear.css({top: '5px'}); // return tear to top for re-animation
			$("#animation .eyebrow, #animation .tummy-left, #animation .tummy-right, #animation .sick-tummy, #animation .sad-mouth").fadeOut(200);
			$("#animation .happy-mouth, #animation .belly-btn").fadeIn(500);
			$("#animation .sun").animate({top:"-55px"}, 1500);
		});
	});
}





