var MAX_OBJECTS = 3 + r(10);	// up to 20 objects


var h, w;
	
$(function () {

	//get height and width of page (used in parralax calc)
	h = $(document).height();
	w = $(document).width();

	//add the initial objects to the page
	for (var i = 0; i < MAX_OBJECTS; i++) add_cloud();	
	
	$('.object').each(stuff);
	
	change();
});

function add_cloud () {
	//random size up to 382 wide
	var s = r(382);
	
	//set up html
	var html = '<div class="object"><img src="http://james.revillini.com/scripts/2009/05/26/phpthumb/phpThumb.php?src=/scripts/2009/05/26/test.png&f=png&w='+s+'" /></div>';

	//add the object.  
	$('body').append(html).find('.object:last').each(stuff);
}

function remove_cloud () {
	$o = $('.object');
	$o.eq(r($o.length)).fadeOut(2500, function (){$(this).remove();});
}

function change () {
	setTimeout(add_cloud, 1000 + r(4000));
	setTimeout(remove_cloud, 1000 + r(4000));
	setTimeout(change, r(5000));
}

function stuff(o) {

	var s = r(382);
	var t = r(h);
	// x position can be whatever
	var l = r(w*3/4);
	
	var $o = $(this);
	$o.hide();
	$o.css({
		top	: t,
		left	: l,
		zIndex	: r(382)
	});
	$o.fadeIn((1000+s)*3);
	//$o.animate({left : w}, 60000 + r(60000));

}

function r (maks) {
	return Math.floor(Math.random()*maks);
}
