var beenumber 	= 1;
var maxbees 	= 10;
var lifespan 	= [];
var creator;
var screenw;
var screenh;

function ani1(id) {
	var rh  = Math.floor(Math.random()*screenh);
	var rw  = Math.floor(Math.random()*screenw);	
	var rh2  = Math.floor(Math.random()*screenh);
	var rw2  = Math.floor(Math.random()*screenw);	
	var duration1  = Math.floor(Math.random()*7000)+1000;
	var duration2  = Math.floor(Math.random()*7000)+1000;
	var duration3  = Math.floor(Math.random()*7000)+1000;
	var duration4  = Math.floor(Math.random()*7000)+1000;
	var dice  = Math.floor(Math.random()*2);
	if(dice==1){
	} else {
		rh2=screenh-rh2;
		rw2=screenw-rw2;
	}
	
		
	$('#lilbee'+id).stop().animate( { top:rh2, left:rw } , duration1 , 'ellipse' , function() {
		$(this).animate( {			  top:rh, left:rw2 } , duration2 , 'ellipse' , function() {
			$(this).animate( { 		  top:rh2, left:0 } , duration3 , 'ellipse' , function() {
				$(this).animate( {    top:0, left:rw2 } , duration4 , 'ellipse' , function() {
					ani1(id);
				})
			})
		})
	}).css({opacity: 1});
};


function showBees(){
	screenw = $(document).width();
	screenh = $(document).height();

	createBee();
	//creator = setInterval('createBee()',10000);
	creator = setInterval('createBee()',500);
}


function createBee(){
	beenumber++;
	
	if(beenumber>maxbees){
		clearInterval(creator);
	} else {	
		var rh  = Math.floor(Math.random()*screenh);
		var speed  = Math.floor(Math.random()*2000)+2000;
		$('#lilbee'+beenumber).css('top',rh+'px');
		$('#lilbee'+beenumber).css('left',20+'px');
		$('#lilbee'+beenumber).fadeIn('slow');
	
		//$('#lilbee'+beenumber).html('<h1>B'+beenumber+'</h1>');

		//setTimeout('moveBee('+beenumber+')',speed);
		//setTimeout('ani1('+beenumber+')',speed);
		ani1(beenumber);
	}
}

function moveBee(i){
	var rw =  Math.floor(Math.random()*screenw-100)+50;
	var rh =  Math.floor(Math.random()*screenh-100)+50;

	var speed  = Math.floor(Math.random()*2000)+500;
			
	$('#lilbee'+i).animate({
    	left: rw+'px',
    	top:  rh+'px',
    	easing: 'swing',
    	duration: speed
    },speed);
    	
	var speed  = Math.floor(Math.random()*2000)+2000;
	setTimeout('moveBee('+i+')',speed);
}


