
Math.randomInt = function(min, max) {
	return Math.floor(Math.random() * (max - min + 1)) + min;
};

Array.prototype.split = function(n) {
	var ret = [], i = 0;
	while (n && (ret[i++] = this.splice(0, n)).length == n && this.length);
	return ret;
};


JSTweener.frameRate = 30;


if (typeof Maedaya == 'undefined') Maedaya = {};


Maedaya.Todo = {
	top_positions: [],
	every    : 5,

	setup: function() {
		Deferred.wait(0.7).next(this.show);
	},

	show: function() {
		var self = Maedaya.Todo;

		var todos = $('#listTodo li').get();
		todos = todos.split(self.every);
		Deferred.loop(todos.length, function(n) {
			var todo = todos[n];
			for (var i = 0, l = todo.length; i < l; i++) (function(i) {
				var li = todo[i];
				$(li).css({
					left: self.left(),
					top : self.top($(li).outerHeight())
				});
				var style = li.style;
				JSTweener.addTween(style, {
					time      : 0.7,
					transition: 'linear',
					onUpdate  : function() {
						var opacity = Math.min((new Date().getTime() - this.startTime) / (this.endTime - this.startTime), 1);
						if ($.browser.msie)
							style.filter  = 'alpha(opacity='+(opacity * 100)+')';
						else
							style.opacity = opacity;
					}
				});
			})(i);
			return Deferred.wait(0.3);
		});
	},

	left: function() {
		var left = Math.randomInt(0, 80);
		return left+'%';
	},

	top: function(h) {
		var top = Math.randomInt(25, 475 - h);
		return top;
	}
};

