userIdTag = {
	init: function() {
		var onlineIds = [];
		$('[online]').each(function(i, v) {
			onlineIds.push($(v).attr('online'));
		})
		
		if (onlineIds != null) {
			$.post('/cli/online.php', {
				online: $.toJSON(onlineIds)
			}, userIdTag.showOnline, "json");
		}
		
		var twiterIds = [];
		$('[twiter]').each(function(i, v) {
			twiterIds.push($(v).attr('twiter'));
			
		});
		if (twiterIds != null) {
			$.post('/cli/twiter.php', {
				twiter: $.toJSON(twiterIds)
			}, userIdTag.showTwiter, "json");
		}
	},
	
	showOnline: function(data) {
		if (typeof data == 'object') {
			for (i in data) {
				var el = $('[online=' + data[i]['id'] + ']').find('span').attr('class', data[i]['class']);
				if (data[i]['class'] == 'online') {
					el.parent().show();
				}
				if (data[i]['class'] == 'offline' && data[i]['date']) {
					el.html(data[i]['date']).parent().show();
				}
			}
		}
	},
	
	showTwiter: function(data) {
		if (typeof data == 'object') {
			for (i in data) {
			
				line = 0
				msg = ''
				max = 50
				if (data[i].length > max) {
					$(data[i].split(' ')).each(function(i, v) {
						line += v.length;
						if (line < max) {
							msg = msg + ' ' + v;
						}
						else {
							return false;
						}
					});
					msg += '...'
				}
				else {
					msg = data[i];
				}
				
				$('[twiter=' + i + ']').html(msg);
			}
			//
		
			//                $('[twiter='+v.user_id+']').attr('title',v.text_html).unbind().hover(
			//                function(e) {
			//                    this.t = this.title;
			//                    this.title = '';
			//                    this.top = (e.pageY + 15); this.left = (e.pageX - 15);
			//
			//                    $('body').append( '<p id="vtip"><img id="vtipArrow" />' + this.t + '</p>' );
			//
			//                    $('p#vtip #vtipArrow').attr("src", '/framework/client/images/vtip_arrow.png');
			//                    $('p#vtip').css("top", this.top+"px").css("left", this.left+"px").fadeIn("slow");
			//
			//                },
			//                function() {
			//                    this.title = this.t;
			//                    $("p#vtip").fadeOut("slow").remove();
			//                }
			//                ).mousemove(
			//                function(e) {
			//                    this.top = (e.pageY + 15);
			//                    this.left = (e.pageX - 15);
			//
			//                    $("p#vtip").css("top", this.top+"px").css("left", this.left+"px");
			//                }
			//                );
			//
		
		}
	}
}


$(document).ready(function() {
	userIdTag.init();
});
