(function ($) {
	window.timeOuts = new Array();
	
	$.fn.funBars = function () {
		// get width and height of container
		var width = $(this).width();
		var height = $(this).height();
		var barCount = 5;
		
		// add an overflow container
		$(this).append('<div id="funBarOverflow" style="position: absolute; top: 0px; left: 0px; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px; overflow: hidden;"></div>');
		
		// load up bars at random times
		for(var i = 0; i < barCount; i++)
		{
			window.timeOuts[i] = setTimeout(function () { generateBar($("#funBarOverflow"), i); }, Math.floor(Math.random() * (i*10) * 1000));
		}
	};
	
	function generateBar(container, i) {
		var color = "#fff";
		var maxWidth = Math.floor(container.width() / 5);
		var minWidth = 10;
		var width = Math.floor((Math.random() * (maxWidth - minWidth)) + minWidth);
		var height = container.height();
		var left = Math.floor(Math.random() * container.width()) - width; left = left > 0 ? left : 0;
		var id = "randomWhitebox" + Math.floor(Math.random() * 99999);
		var orientation = Math.round(Math.random()) ? -1 : 1; // controls direction
		var opacity = (Math.random() * 0.7);
		var speed = Math.floor(Math.random() * 5000) + 3000;
		container.append('<div id="' + id + '"></div>');
		var bar = container.find('#' + id);
		bar.css({'background-color': color, 'position': 'absolute', 'top': (height * orientation) + 'px', 'width': width + 'px', 'left': left + 'px', 'height': height + 'px', 'opacity': opacity});
		bar.animate({'top': (height * orientation * -1) + 'px'}, speed, function () {
			bar.remove();
			// start again
			window.timeOuts[i] = setTimeout(function() { generateBar(container, i) }, speed);
		});
	}
})(jQuery);
