var MRIM = (function(){
	var _url = 'http://status.mail.ru/batch.js?';
	return {
		fetch: function(c){
		    var links = document.body.getElementsByTagName('i');
		    var mrim = {'el':[],'em':[]}, mail = null;
		    for(var i = 0;i < links.length;i++) {
				mail = $(links[i]).readAttribute('email');
				if(!mail) continue;
				mrim.el.push(links[i]);
				mrim.em.push(mail);
		    }
			this.get(mrim);
		},
		get: function(links) {
			this.links = links;
			while(links.em.length) {
				var sc = document.body.appendChild(document.createElement('script'));
				sc.src = _url + links.em.splice(0,30).join(',');
			}
			return;
		},
		update: function(c) {
			if(!c) return;if(!c.length) return;
			c = c.split('');
			var els = this.links.el.splice(0,30);
			for(var i = 0; i < els.length; i++) 
				els[i].className += ' mrim-'+(c[i] == 0?'offline':c[i] == 1?'online':c[i] == 2?'away':'offline');
		}
	};
})();
$(document).observe('dom:loaded', MRIM.fetch.bindAsEventListener(MRIM));
