Index: trunk/expressoMail1_2/index.php
===================================================================
--- trunk/expressoMail1_2/index.php	(revision 7420)
+++ trunk/expressoMail1_2/index.php	(revision 7437)
@@ -32,5 +32,6 @@
 		<link rel="stylesheet" type="text/css" href="../prototype/plugins/fullcalendar/fullcalendar.print.css"></link>
 		<link rel="stylesheet" type="text/css" href="../prototype/plugins/icalendar/jquery.icalendar.css"></link>
-		
+		<link rel="stylesheet" type="text/css" href="../prototype/plugins/jquery.jrating/jRating.jquery.css"></link>
+
 		<script type="text/javascript" src="../prototype/plugins/jquery/jquery.min.js"></script>
 		<link href="../prototype/modules/filters/filters.css" rel="stylesheet" type="text/css">
@@ -66,4 +67,5 @@
 		<script type="text/javascript" src="../prototype/plugins/datejs/parser.js"></script>
 		<script type="text/javascript" src="../prototype/plugins/jq-raty/js/jquery.raty.min.js"></script>
+		<script type="text/javascript" src="../prototype/plugins/jquery.jrating/jRating.jquery.js"></script>
 
 		<script type="text/javascript" src="../prototype/plugins/watermark/jquery.watermarkinput.js"></script>
@@ -346,5 +348,5 @@
 	
 	';
-	
+
 
     // End Set Imap Folder names options
Index: trunk/expressoMail1_2/js/main.js
===================================================================
--- trunk/expressoMail1_2/js/main.js	(revision 7427)
+++ trunk/expressoMail1_2/js/main.js	(revision 7437)
@@ -39,6 +39,35 @@
 } 
 
-function updateDynamicContact(){
-	dynamicContacts = new Array();
+function updateDynamicContact(userContacts){
+
+    if(!userContacts)
+        userContacts = REST.get("/usercontacts", false);
+
+    if(userContacts.collection && !userContacts.collection.error){
+        dynamicData = normalizeContacts(userContacts.collection.itens);
+    }else{
+        dynamicData = [];
+    }
+
+    if(dynamicData){
+        var dynamicContactsList = [];
+        $.each(dynamicData, function(index, dynamic){
+
+            var dataType = userContacts.collection.itens[index].dataType;
+
+            dynamic['value'] = (dynamic.name ? dynamic.name +' - ': '') + dynamic.mail;
+            dynamic['type'] = dataType
+            dynamic['typel'] = (dataType.substring(0,7) == "/shared" ? "/"+dataType.substring(7,dataType.length)+"s" : dataType);
+
+            topContact = dynamic.number_of_messages > topContact ? dynamic.number_of_messages : topContact;
+
+            dynamicContactsList.push(dynamic);
+        });
+    }
+
+    dynamicData = dynamicContactsList;
+
+
+	/*dynamicContacts = new Array();
 
     var dynamicUsers = REST.get("/dynamiccontacts");
@@ -61,5 +90,5 @@
 			dynamicContacts.push(dynamic);
 		});
-	}
+	}*/
 }
 
@@ -2907,5 +2936,5 @@
 			if(!stop){
 				var exist = 0;
-				$.each(dynamicContacts, function(x, valuex){
+				$.each(dynamicData, function(x, valuex){
 					if(valuex.mail == $(value).find("input").val().match(reComplexEmail)[1]){
 						exist = valuex.id;
Index: trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- trunk/expressoMail1_2/js/draw_api.js	(revision 7422)
+++ trunk/expressoMail1_2/js/draw_api.js	(revision 7437)
@@ -4050,5 +4050,5 @@
 		if(parseInt(preferences.use_dynamic_contacts) && !input.hasClass("box-input")){
 			//SELECIONA O CONTATO E EVITA OUTROS COMANDOS
-			if ( e.keyCode === $.ui.keyCode.TAB && $( this ).data( "catcomplete" ).menu.active ) {
+			if ( e.keyCode === $.ui.keyCode.TAB && $( this ).data( "autocomplete" ).menu.active ) {
 				e.preventDefault();
 				return false;
@@ -4056,5 +4056,5 @@
 			
 			//FECHA OS CONTATOS DINÂMICOS
-			if( (e.keyCode == 27) && $( this ).data( "catcomplete" ).menu.active ){
+			if( (e.keyCode == 27) && $( this ).data( "autocomplete" ).menu.active ){
 				   e.stopPropagation();
 				   e.preventDefault();
@@ -4062,12 +4062,12 @@
 			
 			//SELECIONA O CONTATO E EVITA OUTROS COMANDOS
-			if(e.keyCode == $.ui.keyCode.ENTER && $( this ).data( "catcomplete" ).menu.active){
+			if(e.keyCode == $.ui.keyCode.ENTER && $( this ).data( "autocomplete" ).menu.active){
 				e.preventDefault();
 				return false;
 			}
 			
-			if(e.keyCode == $.ui.keyCode.DELETE && $( this ).data( "catcomplete" ).menu.active){
-				if($($( this ).data( "catcomplete" ).menu.element).find(".ui-state-hover").parents("li:first").hasClass("dynamic-recent"))
-					$($( this ).data( "catcomplete" ).menu.element).find(".ui-state-hover").next().trigger("click");
+			if(e.keyCode == $.ui.keyCode.DELETE && $( this ).data( "autocomplete" ).menu.active){
+				if($($( this ).data( "autocomplete" ).menu.element).find(".ui-state-hover").parents("li:first").hasClass("dynamic-recent"))
+					$($( this ).data( "autocomplete" ).menu.element).find(".ui-state-hover").next().trigger("click");
 				return false;
 			}
@@ -4443,4 +4443,6 @@
 }
 
+dynamicData = false;
+currentTypeContact = '';
 
 //FUNÇÃO QUE "SETA" OS BINDS DOS CAMPOS PARA - CC - CCO
@@ -4488,137 +4490,184 @@
 	//VERIFICA PREFERENCIA DE CONTATOS DINÂMICOS ESTA ATIVA
 	if(parseInt(preferences.use_dynamic_contacts)){
+
+        REST.get("/usercontacts", false, updateDynamicContact);
+
 		//PREPARAÇÃO DA ARRAY DOS CONTATOS DINÂMICOS
 
-		$.widget( "custom.catcomplete", $.ui.autocomplete, {
-			_renderMenu: function( ul, items ) {
-				var self = this,
-				currentType = "";
-				$.each( items, function( index, item ) {
-					if ( item.typel != currentType) {
-						if(item.typel == "/groups" && $(ul).find(".dynamic-recent").length)
-							self._renderItem( ul, {name:"", value:"", type:"linha"} );
-						if(item.typel == "/personalContact" && ($(ul).find(".dynamic-group").length || $(ul).find(".dynamic-recent").length))
-							self._renderItem( ul, {name:"", value:"", type:"linha"} );	
-						currentType = item.typel;
-					}
-					self._renderItem( ul, item );
-					$(ul).find("li:last").find(".dynamic-stars").raty({
-						readOnly : true,
-						half : true,
-						hints : ['','','','',''],
-						score    : ((item.number_of_messages*5)/topContact) > 0.5 ? ((item.number_of_messages*5)/topContact) : 0.5,
-						starOn  : '../../prototype/plugins/jq-raty/img/star-on.png',
-						starOff : '../../prototype/plugins/jq-raty/img/star-off.png',
-						starHalf : '../../prototype/plugins/jq-raty/img/star-half.png'
-					});
-				});
-				if($(ul).find("li:last").hasClass("dynamic-separator")){
-					$(ul).find("li:last").remove();
-				}
-				$(ul).scroll(function(){
-					canMakeBox = false;
-				});
-			}
-		});
-		//INSERÇÃO DO AUTO COMPLETE AO INPUT
-		div.find("textarea").catcomplete({
-			minLength: 1,			
-			source: function(request, response){
-				if ( request.term in cache ) {
-					response( cache[ request.term ] );
-					return;
-				}
-				dynamicContactsList = new Array();
-				REST.get("/usercontacts", false, function(data){
-					dynamicData = data.collection.itens;
-					if(dynamicData){
-						$.each(dynamicData, function(index, value){
-							dynamic = {};
-							$.each(value.data, function(index, value){
-								dynamic[value.name] = value.value;
-							});
-							dynamic['value'] = (dynamic.name ? dynamic.name +' - ': '') + dynamic.mail;
-							dynamic['type'] = value.dataType;
-							dynamic['typel'] = (value.dataType.substring(0,7) == "/shared" ? "/"+value.dataType.substring(7,value.dataType.length)+"s" : value.dataType) ;
-							dynamicContactsList.push(dynamic);
-						});
-					}
-					var data = $.ui.autocomplete.filter(dynamicContactsList, request.term );
-					cache[ request.term ] = data;
-					response( data );
-				});
-			},
-			focus: function() {
-				return false;
-			},
-			
-			//EVENTO AO SELECIONAR UM CONTATO DINÂMICO
-			select: function( event, ui ) {
-				canMakeBox = false;
-				event.preventDefault();
-				$(this).val("");
-				if(ui.item.typel == "/personalContact")
-					draw_email_box(""+ui.item.id, $(this), true, (ui.item.type.substring(0,7) == "/shared" ? true : false));
-				else if(ui.item.typel == "/groups")
-					draw_email_box(""+ui.item.id, $(this), "G", (ui.item.type.substring(0,7) == "/shared" ? true : false));
-				else
-					draw_email_box(ui.item.name ? "\""+ui.item.name+"\" <"+ui.item.mail+">" : ui.item.mail, $(this));
-				return false;
-			},
-			autoFocus: true,
-			position : { my: "left top", at: "left bottom", collision: "fit" },
-			delay : 400
-		}).bind('catcompleteopen', function(event, ui) {
-			$(this).data('is_open',true);
-		}).bind('catcompleteclose', function(event, ui) {
-			canMakeBox = true;
-			$(this).data('is_open',false);
-		})
-		
-		//MONTAGEM DA LISTA DE CONTATOS DINÂMICOS DO AUTO COMPLETE
-		.data( "catcomplete" )._renderItem = function( ul, item ) {
-			if($(ul).find("li").length < 50){
-				var autocomplete = $(this)[0].element;
-				//cálculo dinâmico da largura da lista
-				var minwidth = 450;
-				var width = (item.label ? item.label.length : (item.value ? item.value.length : (item.mail ? item.mail.length : 30 )));
-				width = (is_ie ? width*2 : (is_webkit && !is_mozilla ? width*4 : width*5)) + 30;
-				if (width < minwidth)
-					width = minwidth;				
-				ul.css({"min-width":width,"max-height" : "180px", "overflow-y" : "auto", "min-height": "30px"});
-				var listContacts = DataLayer.render("../prototype/modules/mail/templates/listContacts.ejs", item);
-				return $(listContacts).data( "item.autocomplete", item ).appendTo( ul ).find("span:last").button({
-						icons : {
-						primary : "ui-icon-close"
-					},
-					text: false
-				}).click(function(event){
-					var removeLi = $(this).parents("li:first");
-					if(!event.keyCode)
-						autocomplete.catcomplete( "close" );
-					canMakeBox = false;
-					$.Zebra_Dialog('Deseja remover <b>'+(item.name ? (item.name.length <=30 ? item.name: item.name.substr(0,27)+"...")+" - " : "")+ item.mail+'</b>?', {
-							'type':     'question',
-							'custom_class': (is_ie ? 'configure-zebra-dialog' : ''),
-							'title':    'Atenção',
-							'buttons': ['Sim','Não'],		
-							'overlay_opacity': '0.5',
-							'onClose':  function(caption) {
-								if(caption == 'Sim'){
-									$(removeLi).remove();
-									REST['delete']("/dynamiccontact/"+item.id);
-									updateDynamicContact();
-									cache = new Array();
-								}else if(caption == 'Não'){
-									$(focusIn).focus();
-								}
-							}
-					});
-				});
-			}
-			return;
-		};
-	}
-	
+        var decodeType = {
+            '/dynamiccontacts': {
+                css: 'recent',
+                img: 'recent',
+                text: 'Contato Recente'
+                },
+            '/personalContact':{
+                css: 'personal',
+                img: 'personal',
+                text: 'Contato pessoal'
+		    },
+            '/sharedcontact':{
+                css: 'personal',
+                img: 'sharedcontact',
+                text: 'Contato compartilhado'
+            },
+            '/groups':{
+                css: 'group',
+                img: 'group',
+                text: 'Grupo pessoal'
+            },
+            '/sharedgroup':{
+                css: 'group',
+                img: 'sharedgroup',
+                text: 'Grupo compartilhado'
+            }
+	    }
+
+        div.find("textarea").autocomplete({
+            source: function(request, response){
+                if ( request.term in cache ) {
+                    response( cache[ request.term ] );
+                    return;
+                }
+
+                if(dynamicData === false){
+                    updateDynamicContact();
+                }
+
+                var data = $.ui.autocomplete.filter(dynamicData, request.term ).slice(0, 50);
+                cache[ request.term ] = data;
+                response( data );
+
+            },
+            focus: function() {
+                return false;
+            },
+
+            //EVENTO AO SELECIONAR UM CONTATO DINÂMICO
+            select: function( event, ui ) {
+                canMakeBox = false;
+
+                event.preventDefault();
+                $(this).val("");
+
+                var isShared = (ui.item.type.substring(0,7) == "/shared");
+
+                switch (ui.item.typel){
+                    case '/personalContact':
+                        draw_email_box(""+ui.item.id, $(this), true, isShared);
+                        break;
+                    case '/groups':
+                        draw_email_box(""+ui.item.id, $(this), "G", isShared);
+                        break;
+                    default:
+                        draw_email_box(ui.item.name ? ("\""+ui.item.name+"\" <"+ui.item.mail+">") : ui.item.mail, $(this));
+                }
+
+                return false;
+            },
+            autoFocus: true,
+            position : { my: "left top", at: "left bottom", collision: "fit" },
+            delay : 120,
+            minLength: 0
+        }).bind('catcompleteopen', function(event, ui) {
+
+            $(this).data('is_open',true);
+
+        }).bind('catcompleteclose', function(event, ui) {
+
+            canMakeBox = true;
+            $(this).data('is_open',false);
+
+        }).data( "autocomplete" )._renderItem = function( ul, item ) {
+            var autocomplete = $(this)[0].element;
+
+            //cálculo dinâmico da largura da lista
+            var minwidth = 450;
+            var width = (item.label ? item.label.length : (item.value ? item.value.length : (item.mail ? item.mail.length : 30 )));
+            width = (is_ie ? width*2 : (is_webkit && !is_mozilla ? width*4 : width*5)) + 30;
+            if (width < minwidth)
+                width = minwidth;
+
+            ul.css({"min-width":width, "max-height" : "180px", "overflow-y" : "auto", "min-height": "30px"});
+
+            item.raty = ((item.number_of_messages*10)/topContact) > 1 ? ((item.number_of_messages*10)/topContact) : 1;
+
+            if ( item.typel != currentTypeContact) {
+                if((item.typel == "/groups" && $(ul).find(".dynamic-recent").length) || (item.typel == "/personalContact" && ($(ul).find(".dynamic-group").length || $(ul).find(".dynamic-recent").length))){
+                    currentTypeContact = item.typel;
+                    item.asDiv = true;
+                }else{
+                    currentTypeContact = item.typel;
+                }
+            }
+
+            var li = '';
+            if(item.asDiv){
+                li = '<li class="dynamic-separator"><div class="line-separator">&nbsp;</div></li>';
+            }
+            li += '<li class="dynamic-'+ decodeType[item.type].css +'">';
+            li += '<a style="width:'+(item.type == '/dynamiccontacts' ? '91%' : '97.5%')+';  display: inline-block; background: none;">';
+            li += '<img style="position:relative; top:2px; "src="../prototype/modules/mail/img/'+ decodeType[item.type].img +'.png" title="'+ decodeType[item.type].text +'"/>';
+            li += ($.trim(item.name) != "" ? ((item.name.length > 20 ? item.name.substring(0,17)+"..." : item.name) + " - " ) : '')  + item.mail;
+            li += item.type == '/dynamiccontacts' ? '<div class="dynamic-stars" style="display: inline-block;float: right;" id="'+item.raty+'_'+item.id+'"/>' : ''
+            li += '</a>';
+            li += '<span style="width:16px; height:16px; top:1px; left:7px; '+ (item.type == '/dynamiccontacts' ? '': 'display:none') +'">Excluir contato recente</span>';
+            li += '</li>';
+
+
+            li = $( li )
+                .data( "item.autocomplete", item )
+                //.append( li )
+                .appendTo( ul );
+
+            li.find("span").button({
+                icons : {
+                    primary : "ui-icon-close"
+                },
+                text: false
+            }).click(function(event){
+                    if(!event.keyCode)
+                        autocomplete.autocomplete( "close" );
+
+                    canMakeBox = false;
+                    $.Zebra_Dialog('Deseja remover <b>'+(item.name ? (item.name.length <= 30 ? item.name: item.name.substr(0,27)+"...")+" - " : "")+ item.mail+'</b>?', {
+                        'type':     'question',
+                        'custom_class': (is_ie ? 'configure-zebra-dialog' : ''),
+                        'buttons': ['Sim','Não'],
+                        'overlay_opacity': '0.5',
+                        'onClose':  function(caption) {
+                            if(caption == 'Sim'){
+
+                                REST['delete']("/dynamiccontact/"+item.id);
+                                updateDynamicContact();
+                                cache = new Array();
+                            }else if(caption == 'Não'){
+                                $(focusIn).focus();
+                            }
+                        }
+                    });
+                });
+
+            li.find(".dynamic-stars").jRating({
+                step:true,
+                length : 5, // nb of stars
+                decimalLength: 2, // number of decimal in the rate
+                rateMax: 10,
+                isDisabled:true,
+                bigStarsPath : '../prototype/plugins/jquery.jrating/icons/stars.png', // path of the icon stars.png
+                smallStarsPath : '../prototype/plugins/jquery.jrating/icons/small.png' // path of the icon small.png
+            });
+
+            if($(ul).find("li:last").hasClass("dynamic-separator")){
+                $(ul).find("li:last").remove();
+            }
+
+            $(ul).scroll(function(){
+                canMakeBox = false;
+            });
+
+            return li;
+        };
+	}
+
 	//FUNÇÃO DOS BOTÕES PARA - CC - CCO
 	div.parents("tr:first").find("button").button().click(function(){
