Index: sandbox/newExpressoMail/prototype/modules/newMail/js/init.js
===================================================================
--- sandbox/newExpressoMail/prototype/modules/newMail/js/init.js	(revision 7210)
+++ sandbox/newExpressoMail/prototype/modules/newMail/js/init.js	(revision 7265)
@@ -1,143 +1,166 @@
+var BASE_PATH = '../prototype/';
+
 $(document).ready(function() {
 
-	Layout = $('#wrap').layout({ 
-		applyDefaultStyles: true,
-		north__size:		'auto',
-		north__closable:	false, 
-		north__resizable:	false,
-		north__slidable:	false, 
-		west__resizable:	false,
-		west__slidable:	false,
-		center__maxSize : 0
-	});
+    Layout = $('#wrap').layout({
+        applyDefaultStyles: true,
+        north__size:		'auto',
+        north__closable:	false,
+        north__resizable:	false,
+        north__slidable:	false,
+        west__resizable:	false,
+        west__slidable:	false,
+        center__maxSize : 0
+    });
 
-	$tabs = $("#tabs").wijtabs({ 
-		tabTemplate: "<li role='tab' style='cursor: pointer;'><a href='#{href}'>#{label}</a><span class='ui-icon tab-close ui-icon-close close' title='Fechar Aba'>Fechar Aba</span></li>", 
-		panelTemplate: "<div id='{href}'></div>",
-		add: function( event, ui ) { 
-		        $tabs.wijtabs('select', '#' + $tabs.find("div:last").attr("id")); 
-	         	$tabs.find("span.tab-close:last").hover(function(){$(this).toggleClass("ui-icon-circle-close ui-icon-close");}, function(){$(this).toggleClass("ui-icon-circle-close ui-icon-close");})
-		        $tabs.find("div:last").addClass("conteudo").attr("role", tab_role).append(tab_content); 
-		},
-		show: function(event, ui){
-			switch($( ui.panel ).attr("role")){
-				case "new":
-				case "search":
-					$("#footer_menu").hide();
-					break;
-				case "message":
-				case "draft":
-				case "folder":
-					$("#footer_menu").show();
-					break;
-			}
-		},
-		select: function(event, ui) { 
-			lastIndexSelected = ui.index;
-		},
-		scrollable: true,
-		sortable: true,
-        hideOption: { 
-        	blind: true, 
-        	fade: false, 
-        	duration: 200
-       	},
-       	showOption: {
-       		blind: true, 
-       		fade: false, 
-       		duration: 200
-       	}
-	});	
+    $tabs = $("#tabs").wijtabs({
+        tabTemplate: "<li role='tab' style='cursor: pointer;'><a href='#{href}'>#{label}</a><span class='ui-icon tab-close ui-icon-close close' title='Fechar Aba'>Fechar Aba</span></li>",
+        panelTemplate: "<div id='{href}'></div>",
+        add: function( event, ui ) {
+            $tabs.wijtabs('select', '#' + $tabs.find("div:last").attr("id"));
+            $tabs.find("span.tab-close:last").hover(function(){$(this).toggleClass("ui-icon-circle-close ui-icon-close");}, function(){$(this).toggleClass("ui-icon-circle-close ui-icon-close");})
+            $tabs.find("div:last").addClass("conteudo").attr("role", tab_role).append(tab_content);
+        },
+        show: function(event, ui){
+            switch($( ui.panel ).attr("role")){
+                case "new":
+                case "search":
+                    $("#footer_menu").hide();
+                    break;
+                case "message":
+                case "draft":
+                case "folder":
+                    $("#footer_menu").show();
+                    break;
+            }
+        },
+        select: function(event, ui) {
+            lastIndexSelected = ui.index;
+        },
+        scrollable: true,
+        sortable: true,
+        hideOption: {
+            blind: true,
+            fade: false,
+            duration: 200
+        },
+        showOption: {
+            blind: true,
+            fade: false,
+            duration: 200
+        }
+    });
 
-	draw_new_tree_folder();
+    draw_new_tree_folder();
 
-	$(".new-message-button").button({
-		icons: {
-			secondary : "ui-icon-plusthick"
-		}
-	});
+    $(".new-message-button").button({
+        icons: {
+            secondary : "ui-icon-plusthick"
+        }
+    });
 
-	var messages = DataLayer.get("message", {criteria : {folder: 'INBOX', rows: 999999}}, true);
+    var messages = DataLayer.get("message", {criteria : {folder: 'INBOX', rows: 999999}});
 
-	$('.button.config-menu').button({
-	    icons: {
-			primary: "ui-icon-gear",
-			secondary: "ui-icon-triangle-1-s"
-	    },
-	    text: false
-	});
+    $('.button.config-menu').button({
+        icons: {
+            primary: "ui-icon-gear",
+            secondary: "ui-icon-triangle-1-s"
+        },
+        text: false
+    });
 
-	var menus = $(".main-menus-content").clone();
-	$(".main-menus-content").remove();
+    var menus = $(".main-menus-content").clone();
+    $(".main-menus-content").remove();
 
-	$(".this-module").button().next().button({
-		icons :{
-			primary: "ui-icon-triangle-1-s"
-		},
-		text: false
-	}).parent().buttonset();
+    $(".this-module").button().next().button({
+        icons :{
+            primary: "ui-icon-triangle-1-s"
+        },
+        text: false
+    }).parent().buttonset();
 
-	$(".this-module").parent().append(menus);
+    $(".this-module").parent().append(menus);
 
-	$('.this-module').next().menu({
-		content: $('.main-menus-content').html(),
-		positionOpts: {
-			posX: 'left', 
-			posY: 'bottom',
-			offsetX: -140,
-			offsetY: 0,
-			directionH: 'right',
-			directionV: 'down', 
-			detectH: true, // do horizontal collision detection  
-			detectV: true, // do vertical collision detection
-			linkToFront: false
-		},
-		flyOut: true,
-		showSpeed: 100,
-		crumbDefaultText: '>'
-	});
+    $('.this-module').next().menu({
+        content: $('.main-menus-content').html(),
+        positionOpts: {
+            posX: 'left',
+            posY: 'bottom',
+            offsetX: -140,
+            offsetY: 0,
+            directionH: 'right',
+            directionV: 'down',
+            detectH: true, // do horizontal collision detection
+            detectV: true, // do vertical collision detection
+            linkToFront: false
+        },
+        flyOut: true,
+        showSpeed: 100,
+        crumbDefaultText: '>'
+    });
 
-	$('.block-horizontal-toolbox .main-config-menu').menu({
-		content: $('.main-config-menu-content').html(),
-		positionOpts: {
-			posX: 'left', 
-			posY: 'bottom',
-			offsetX: -140,
-			offsetY: 0,
-			directionH: 'right',
-			directionV: 'down', 
-			detectH: true, // do horizontal collision detection  
-			detectV: true, // do vertical collision detection
-			linkToFront: false
-		},
-		flyOut: true,
-		showSpeed: 100,
-		crumbDefaultText: '>'
-	});
-	setFolderTabName("Caixa de Entrada");
-	$(".folder-tab-total-msgs-number").html(messages.records);
-	setFolderTabTotalUnread($("#INBOX").find(".folder_unseen").html());
-	Grid = $("#imap-folder-table-messages").jqGrid({
-		datatype: "local",
-		data: messages.rows,
-		colNames:['#',' ', 'De', 'Assunto', 'Data', 'Tamanho'],
-		colModel:[
-			{name:'msg_number',index:'msg_number', width:45, hidden:true, sortable:false},
-			{name:'flags',index:'msg_number',edittype: 'image', width:60, sortable:false, title :false},
-			{name:'from.name',index:'msg_number', width:100, sortable:true},
-			{name:'subject',index:'subject', width:245, sortable:true},
-			{name:'timestamp',index:'timestamp', width:65, align:"center", sortable:true},
-			{name:'size',index:'size', width:55, align:"center", sortable:true, formatter: bytes2Size}
-		],
-		rowNum:50,
-		rowList:[10,25,50],
-		pager: "#imap-folder-table-pager",
-		sortorder: "desc",
-		multiselect: true,
-		autowidth: true,
-		height : '85.5%',
-		emptyrecords: 'A pasta nao contem nenhuma mensagem.',
-		viewrecords: true
-	});
-	Grid.jqGrid('bindKeys', {"onEnter":function( rowid ) { alert("You enter a row with id:"+rowid)} });
+    $('.block-horizontal-toolbox .main-config-menu').menu({
+        content: $('.main-config-menu-content').html(),
+        positionOpts: {
+            posX: 'left',
+            posY: 'bottom',
+            offsetX: -140,
+            offsetY: 0,
+            directionH: 'right',
+            directionV: 'down',
+            detectH: true, // do horizontal collision detection
+            detectV: true, // do vertical collision detection
+            linkToFront: false
+        },
+        flyOut: true,
+        showSpeed: 100,
+        crumbDefaultText: '>'
+    });
+    Tab.setFolderName("Caixa de Entrada");
+    $(".folder-tab-total-msgs-number").html(messages.records);
+    Tab.setFolderUnread($("#INBOX").find(".folder_unseen").html());
+    Grid = $("#imap-folder-table-messages").jqGrid({
+        url:BASE_PATH + 'REST.php?q=folder/INBOX/message',
+        datatype: "json",
+        colNames:['#',' ', 'De', 'Assunto', 'Data', 'Tamanho'],
+        colModel:[
+            {name:'msg_number',index:'msg_number', width:45, hidden:true, sortable:false},
+            {name:'flags',index:'msg_number',edittype: 'image', width:60, formatter:flags2Class, sortable:false, title :false},
+            {name:'from.name',index:'SORTFROM', width:100, sortable:true, formatter:subjectFormatter},
+            {name:'subject',index:'SORTSUBJECT', width:245, sortable:true},
+            {name:'timestamp',index:'SORTARRIVAL', width:65, align:"center", sortable:true, formatter: date2Time},
+            {name:'size',index:'SORTSIZE', width:55, align:"center", sortable:true, formatter: bytes2Size}
+        ],
+        jsonReader : {
+            root:"rows",
+            page: "page",
+            total: "total",
+            records: "records",
+            repeatitems: false,
+            id: "0"
+        },
+        rowNum:50,
+        rowList:[10,25,50],
+        pager: "#imap-folder-table-pager",
+        sortorder: "desc",
+        multiselect: true,
+        autowidth: true,
+        height : '85.5%',
+        emptyrecords: 'A pasta nao contem nenhuma mensagem.',
+        viewrecords: true,
+        loadComplete: function(data) {
+            lastLoadedMessages = data.rows;
+
+            // aplica o contador
+            $('.timable').each(function (i) {
+                $(this).countdown({
+                    since: new Date(parseInt(this.title)),
+                    significant: 1,
+                    layout: 'h&aacute; {d<}{dn} {dl} {d>}{h<}{hn} {hl} {h>}{m<}{mn} {ml} {m>}{s<}{sn} {sl}{s>}',
+                    description: ' atr&aacute;s'
+                });
+            });
+        }
+    });
+    Grid.jqGrid('bindKeys', {"onEnter":function( rowid ) { alert("You enter a row with id:"+rowid)} });
 });
