/**
 *
 * Header animation
 *
 **/
$(document).ready(function(){
	
	// start the clouds which will be continuous
	setInterval( 'moveClouds()', 80 );
	
});

// move the clouds
function moveClouds() {
	
	// update the left px amount
	// parseInt(curValue, 10) - 1 + 'px'; returns an integer only otherwise it would be "59px" for ie
	$('#clouds img#cloud1').css('left', function (index, curValue) {	
		return parseInt(curValue, 10) - 1 + 'px';
	});
	// if the clouds are off the screen then move them to the right off the screen
	if ( $('#clouds img#cloud1').css('left') == '-1001px' ) {
		$('#clouds img#cloud1').css({'left': '1000px'});
	}
	
	$('#clouds img#cloud2').css('left', function (index, curValue) {	
		return parseInt(curValue, 10) - 1 + 'px';
	});
	
	if ( $('#clouds img#cloud2').css('left') == '-1001px' ) {
		$('#clouds img#cloud2').css({'left': '1000px'});
	}
	
	if ( $('#clouds img#cloud1').css('left') == '-25px' ) {
		birdSequenceOne(); 
	}
	
	if ( $('#clouds img#cloud1').css('left') == '-75px' ) {
		birdSequenceTwo(); 
	}
	
}

function birdSequenceOne() {
	// bird moves to the right a little
	$('#bird').animate({left:'+=2px'}, 1500);
}

function birdSequenceTwo() {
	// bird changes bg position for flight
	$('#bird').css({ backgroundPosition: "-53px 0" });
	setInterval( 'flapWingsUp()', 400 );
	setInterval( 'flapWingsDown()', 300 );
	$('#bird').animate({left:'+=200px', top:'-=50px'}, 3000);
}

function flapWingsUp() {
	// flap wings
	$('#bird').css({ backgroundPosition: "-43px 0" });
}

function flapWingsDown() {
	// flap wings
	$('#bird').css({ backgroundPosition: "-22px 0" });	
}
