Index: /sandbox/2.4.2-expresso1/prototype/modules/calendar/js/calendar.alarms.js
===================================================================
--- /sandbox/2.4.2-expresso1/prototype/modules/calendar/js/calendar.alarms.js	(revision 6768)
+++ /sandbox/2.4.2-expresso1/prototype/modules/calendar/js/calendar.alarms.js	(revision 6774)
@@ -26,5 +26,8 @@
 		    };
 		*/
-		    desktopNotification.showNotification();
+		    desktopNotification.showNotification(false, function(){
+				window.focus();
+				this.cancel();
+			});
 
 		}else{
Index: /sandbox/2.4.2-expresso1/prototype/modules/calendar/js/desktop.notification.js
===================================================================
--- /sandbox/2.4.2-expresso1/prototype/modules/calendar/js/desktop.notification.js	(revision 6768)
+++ /sandbox/2.4.2-expresso1/prototype/modules/calendar/js/desktop.notification.js	(revision 6774)
@@ -4,13 +4,13 @@
 
     initDesktopNotificationAddon: function(){
-	if(useDesktopNotification()){
+		if(useDesktopNotification()){
 
-	    if (!window.webkitNotifications && $.browser.mozilla)
-		this.installDektopNotificationAddon();
+			if (!window.webkitNotifications && $.browser.mozilla)
+			this.installDektopNotificationAddon();
 
-	    if(window.webkitNotifications && window.webkitNotifications.checkPermission())
-		window.webkitNotifications.requestPermission();
+			if(window.webkitNotifications && window.webkitNotifications.checkPermission())
+			window.webkitNotifications.requestPermission();
 
-	}
+		}
     },
 
@@ -19,10 +19,10 @@
 	var params = {
 	    "Foo": { 
-		URL: '../prototype/plugins/desktop.notification/html_desktop_notifications-1.0.7-fx.xpi' ,
-		IconURL:'../prototype/plugins/desktop.notification/desktop-notification.png',
-		//Hash:'sha1:28857e60d043447c5f4550853f2d40770b326a13',
-		toString: function () {
-		    return this.URL;
-		}
+			URL: '../prototype/plugins/desktop.notification/html_desktop_notifications-1.0.7-fx.xpi' ,
+			IconURL:'../prototype/plugins/desktop.notification/desktop-notification.png',
+			//Hash:'sha1:28857e60d043447c5f4550853f2d40770b326a13',
+			toString: function () {
+				return this.URL;
+			}
 	    }
 	};
@@ -35,27 +35,34 @@
     verifyComplement: function(){
 
-	if(!window.webkitNotifications)
-	    return false;
+		if(!window.webkitNotifications)
+			return false;
 
-	if(window.webkitNotifications.checkPermission())
-	    return false;
+		if(window.webkitNotifications.checkPermission())
+			return false;
 
-	return true;
-
+		return true;
     },
 
     sentNotification: function(icon, title, body){
-	this.notification[this.notification.length] = window.webkitNotifications.createNotification( icon, title, body);
-    },
+		var reference = this.notification.length;
+		this.notification[reference] = window.webkitNotifications.createNotification( icon, title, body);
+		return reference;
+	},
 
+	cancelByReference: function(index){
+		if(this.notification[index])
+			this.notification[index].cancel();
+	},
+	
+	
     showNotification: function(onClose, onClick, onDisplay, onError){
-	var length = this.notification.length -1; 
+		var length = this.notification.length -1; 
 
-	this.notification[length].ondisplay = onDisplay;
-	this.notification[length].onclose = onClose;
-	this.notification[length].onclick = onClick;
-	this.notification[length].onerror = onError;
+		this.notification[length].ondisplay = onDisplay;
+		this.notification[length].onclose = onClose;
+		this.notification[length].onclick = onClick;
+		this.notification[length].onerror = onError;
 
-	this.notification[length].show();
+		this.notification[length].show();
     }
 }
@@ -67,14 +74,12 @@
 	    activePage = true;  
 	    if(!desktopNotification.verifyComplement()){
-		setTimeout(function(){		    
-		    console.log(desktopNotification.notification);
-		    
-		    for(var i = 0; i < desktopNotification.notification.length; i++){
-			desktopNotification.notification[i].cancel();
-		    }		    
-		    desktopNotification.notification = [];
-
-		    console.log(desktopNotification.notification);
-		}, 60000);
+			setTimeout(function(){		    
+				
+				for(var i = 0; i < desktopNotification.notification.length; i++){
+				desktopNotification.notification[i].cancel();
+				}		    
+				desktopNotification.notification = [];
+				
+			}, 60000);
 	    }
 	})
Index: /sandbox/2.4.2-expresso1/expressoMail1_2/js/main.js
===================================================================
--- /sandbox/2.4.2-expresso1/expressoMail1_2/js/main.js	(revision 6765)
+++ /sandbox/2.4.2-expresso1/expressoMail1_2/js/main.js	(revision 6774)
@@ -13,5 +13,5 @@
 var auxNotification;
 
-var notifyNewMessage = [];
+var countNewMessage = 0;
 var notifyNewMessageFilter = [];
 
@@ -560,65 +560,4 @@
 }
 
-
-//here
-var window_focus;
-function Notifier() {}
-
-function refreshCriteria(){
-	if(auxNotificationCriteriaVetor.length > 0){
-		for(var i=0; i<auxNotificationCriteriaVetor.length; i++){
-			auxNotificationCriteriaVetor[i].cancel();
-		}
-	}
-}
-function refreshNewMsg(){
-	if(auxNotification){
-		auxNotification.cancel();
-		notifyNewMessage = [];
-	}
-}
-
-$(document).ready( function(){
-
-	$(window).focus(function() {
-		window_focus = true;
-	}).blur(function() {
-		window_focus = false;
-	});
-	
-    Notifier.prototype.HasSupport = function() {
-      if (window.webkitNotifications) 
-			return true;
-       else 
-			return false;
-      
-    }
-
-    Notifier.prototype.RequestPermission = function(cb) {
-      window.webkitNotifications.requestPermission();
-    }
-
-    Notifier.prototype.Notify = function(icon, title, body) {
-      if (window.webkitNotifications.checkPermission() == 0) {
-        var popup = window.webkitNotifications.createNotification(
-        icon, title, body);
-        popup.show();
-
-        return true;
-      }
-
-      return false;
-    }
-
-    $(function() {
-		var notifier = new Notifier();
-		
-		if (window.webkitNotifications.checkPermission() != 0){
-			notifier.RequestPermission();
-		}
-	});
-});
-
-
 function auto_archiving() {
 	expresso_mail_sync.start_sync();
@@ -628,5 +567,5 @@
 function notificationFilter(data, notifyCriteria){
 	
-	if(parseInt(notifyCriteria)  && data.length > 0 && !window_focus ){
+	if(parseInt(notifyCriteria)  && data.length > 0 && !activePage ){
 	
 		var howManyCriteria = $('div.gray.filtersDeadline .message-list li').length;
@@ -635,30 +574,21 @@
 		if(differenceOfNewCriteria > 0){
 			for(var i=data.length - differenceOfNewCriteria; i < data.length; i++){
-		
-			notificationCriteriaVetor = webkitNotifications.createNotification("","Critério de filtro",data[i].from+" - "+data[i].subject);
-			notificationCriteriaVetor.onclick = function(){
-				window.focus();
-				this.cancel();
-			};
-			
-			notificationCriteriaVetor.show();
-			auxNotificationCriteriaVetor.push(notificationCriteriaVetor);
-			}
-		}
 	
-	}
-
+				desktopNotification.sentNotification("","Critério de filtro",data[i].from+" - "+data[i].subject);
+				
+				desktopNotification.showNotification(false, function(){
+					window.focus();
+					this.cancel();
+				});
+			}
+		}
+	}
 }
 
 function refresh(alert_new_msg, notifyPermission){
-
-	if(window_focus){
-		setTimeout('refreshCriteria()', 5000);
-		setTimeout('refreshNewMsg()', 5000);
-	}
 
 	getFromAlertRules();
 	var handler_refresh = function(data){
-		handlerMessageFilter = function (data) {
+		handlerMessageFilter = function (data) {			
 			notificationFilter(data, notifyPermission);
 			if(checkAlarmsFilter){
@@ -682,5 +612,5 @@
 			showEmptyBoxMsg(box);
 
-		if (data.length > 0 || notifyNewMessage.length > 0){
+		if (data.length > 0 || countNewMessage > 0){
 			for(var i=0;i< data.length;i++){
 				if (!onceOpenedHeadersMessages[current_folder])
@@ -812,33 +742,26 @@
 				select_msg("null","reload_msg","null");
 		
-			if(parseInt(alert_new_msg) && data.new_msgs > 0 && window_focus)
+			if(parseInt(alert_new_msg) && data.new_msgs > 0 && activePage)
 				alert(data['new_msgs'] > 1 ? get_lang("You have %1 new messages", data['new_msgs']) + "!" : get_lang("You have 1 new message") +"!");
 			
 			
-			if(parseInt(notifyPermission)  && (data.new_msgs > 0 || notifyNewMessage.length > 0) && !window_focus ){
+			if(parseInt(notifyPermission)  && (data.new_msgs > 0 || !!countNewMessage) && !activePage ){
 			
-				for(var i=0; i<data.length; i++){
-					notifyNewMessage.push(true);
-				}
-					
-				notification = webkitNotifications.createNotification("","Notificação",notifyNewMessage.length > 1 ? get_lang("You have %1 new messages", notifyNewMessage.length) + "!" : get_lang("You have 1 new message") +"!");
-					notification.onclick = function(){
-						window.focus();
-						this.cancel();
-						notifyNewMessage = [];
-					};
-					
-					notification.onclose = function(){
-						notifyNewMessage = [];
-					}
-					
-					if(auxNotification)
-						auxNotification.cancel();
-					
-					notification.ondisplay = function(){
-						auxNotification = notification;
-					};
-					notification.show();
-
+				countNewMessage += data.length;
+				
+				desktopNotificationAux = desktopNotification.sentNotification("","Notificação", countNewMessage > 1 ? get_lang("You have %1 new messages", countNewMessage) + "!" : get_lang("You have 1 new message") + "!");
+				
+				if(auxNotification !== 'undefined')
+					desktopNotification.cancelByReference(auxNotification);
+				
+				desktopNotification.showNotification(function(){
+					countNewMessage = 0;
+				}, function(){
+					window.focus();
+					this.cancel();
+					countNewMessage = 0;
+				});
+				
+				auxNotification = desktopNotificationAux;
 			}
 			build_quota(data['quota']);
