$.chatModule.addEventListener('tappedAvatar', function(data) {
	Ti.API.info('!!!!! tappedAvatar = ' + data.index);

	//Get message data
	var message = dataSource.getMessageByIndex(data.index);

	//Check avatar loading state (to web url avatar)
	if (data.loaded) {
		Ti.API.info('!!!!! avatar ' + message.avatar + ' already loaded.');
	} else if (data.loading) {
		Ti.API.info('!!!!! avatar ' + message.avatar + ' is loading...');
	} else {
		//Try to reload avatar image from web url
		$.chatModule.reloadAvatar(message.avatar);
	}
});
$.chatModule.cellSenderNameCustomization = function(data) {
	//Get message data
	var message = dataSource.getMessageByIndex(data.index);
	//Check data to enable customization
	if (message.echo) {
		//Return customization properties
		return {
			//Sender name cell customization...
			//showSenderName
			//senderNameHeight
			senderNameColor : '#e00000'
			//senderNameFont
			//senderNameContent (string)
		};
	}
	//Return no customization
	return null;
};
$.chatModule.cellBubbleCustomization = function(data) {
	//Get message data
	var message = dataSource.getMessageByIndex(data.index);
	//Check data to enable customization
	if (message.echo) {
		//Return customization properties
		return {
			//Bubble cell customization...
			//showBubbles
			//bubbleKind
			bubbleColor : '#ff8080'
			//textColor
			//textAlignment
			//bubbleFont
		};
	}
	//Return no customization
	return null;
};
$.chatModule.cellAvatarCustomization = function(data) {
	//Get message data
	var message = dataSource.getMessageByIndex(data.index);
	//Check data to enable customization
	if (message.echo) {
		//Return customization properties
		return {
			//Avatar cell customization...
			//showAvatar
			avatarSize : 20
			//avatarOverlay
			//textAvatarBackgroundColor
			//textAvatarColor
			//textAvatarFont
		};
	}
	//Return no customization
	return null;
};
$.chatModule.cellTimestampCustomization = function(data) {
	//Get message data
	var message = dataSource.getMessageByIndex(data.index);
	//Check data to enable customization
	if (message.echo) {
		//Return customization properties
		return {
			//Timestamp cell customization...
			//showTimestamp
			//timestampHeight
			timestampColor : '#800000'
			//timestampFont
			//timestampPrefixFont
			//timestampContent (string)
			//timestampPrefixContent (string)
		};
	}
	//Return no customization
	return null;
};
//Simulate a received message from a button click
function btnReceiveClick(e) {
	//Ger datasource info
	var data = dataSource.getMessagesData();
	if (data && data.read > 0) {
		//Get last read message from datasource
		var message = dataSource.getMessageByIndex(data.read -1);
		//Check if is a valid and "not echo" message 
		if (message && !message.echo) {
			//Scroll message view to bottom
			$.chatModule.scrollToBottomAnimated(true);
			//Add new message to datasource
			dataSource.pushMessage({
				echo : true,
				message : message.message.split('').reverse().join(''),
				avatar : 'demo_avatar_jobs',
				date : moment.utc().format("YYYY-MM-DDTHH:mm:ss.SSS")
			});
			//Update message view after changed datasource (receiving)
			$.chatModule.finishReceivingMessage();
		}
	}
}
$.chatModule.messageDataForIndex = function(data) {
	//Return message from datasource by index
	return dataSource.getMessageByIndex(data.index);
};