function randomFromTo(from, to){
	return Math.floor(Math.random() * (to - from + 1) + from);
}

function sparkleStars (){

	var from = 0;
	var to = $('.sparkle').size() - Number(1);
	
	var randSparkle = randomFromTo(from, to);

	var sparkle = $('.sparkle:eq(' + randSparkle + ')');
	
	sparkle.animate({opacity: 0}, 700, function(){
		$(this).animate({opacity: 1}, 700);	
	});
	
	
}

$(function(){
	
	// Only move the clouds if there are some present.
	// At night the clouds turn to stars!
		
	if ($('.cloud').size() > 0){
		
		
		setInterval(function(){
			
			
			var movePx = 2;
			var animateTime = 350;
			
			$('.cloud1').animate({top: parseFloat($('.cloud1').css('top')) - movePx}, animateTime);	
			$('.cloud1').animate({top: parseFloat($('.cloud1').css('top')) + (movePx - movePx)}, animateTime);	
			
			$('.cloud3').animate({top: parseFloat($('.cloud3').css('top')) - movePx}, animateTime);	
			$('.cloud3').animate({top: parseFloat($('.cloud3').css('top')) + (movePx - movePx)}, animateTime);	
			
			$('.cloud4').animate({top: parseFloat($('.cloud4').css('top')) - movePx}, animateTime);	
			$('.cloud4').animate({top: parseFloat($('.cloud4').css('top')) + (movePx - movePx)}, animateTime);	
			
			$('.cloud6').animate({top: parseFloat($('.cloud6').css('top')) - movePx}, animateTime);	
			$('.cloud6').animate({top: parseFloat($('.cloud6').css('top')) + (movePx - movePx)}, animateTime);	
			
			
			setTimeout(function(){
				
				var movePx = 2;
				var animateTime = 350;
			
				$('.cloud2').animate({top: parseFloat($('.cloud2').css('top')) - movePx}, animateTime);	
				$('.cloud2').animate({top: parseFloat($('.cloud2').css('top')) + (movePx - movePx)}, animateTime);	
				
				$('.cloud5').animate({top: parseFloat($('.cloud4').css('top')) - movePx}, animateTime);	
				$('.cloud5').animate({top: parseFloat($('.cloud4').css('top')) + (movePx - movePx)}, animateTime);	
				
			}, 350);	
				
		}, 1500);
	
	}
	
	
	if ($('.sparkle').size() > 0){
	
	
		setInterval(function(){
			sparkleStars();			
		}, 100);
					

	}
	
	
	
	

});

