
WebApp.AnteprimaCarrello = function(){
	var _show = false;
	var _over = false;
  var _timeout = null;
  	
	function visualizzaCarrello(result) {
  	var countObj = document.getElementById("bodyAnteprimaCarrello");
    countObj.innerHTML = result.html;  
	}
	
	function showLoading() {
  	var countObj = document.getElementById("bodyAnteprimaCarrello");
    countObj.innerHTML = '<div style="text-align:center; padding-top: 90px;"><img src="' + WebApp.assetsUrl + '/imagescons/loading.gif" alt="Operazione in corso" /><br />Caricamento in corso...</div>';  
	}
	
	function show() {
		_show = true;
		var cont = document.getElementById("cart");
		Element.addClassName(cont,"show");			
		showLoading();
			
    var request = new HttpRequest();    
		request.setFunctionOperationComplete(visualizzaCarrello);      
   	request.send(WebApp.baseUrl + "/anteprimaCarrello.do");			
	}
  
  function closeBox() {
    var cont = document.getElementById("cart");
    Element.removeClassName(cont,"show");		
    _show = false;	  
  }
	
	return {	
		remove : function(id) {
			showLoading();
	    var request = new HttpRequest();    
			request.setFunctionOperationComplete(function(){
								  	WebApp.Carrello.remFromCartByExtern(id);
										show();										
									});      
	   	request.send(WebApp.baseUrl + "/removeFromCart.do","id=" + id);			
		},
		update : function() {
			if (_show) {
				show();
			}
		},
  	show : function() {
      _over = true;
      _timeout = setTimeout(function() {
          if (_over) {	 
      			show();
          }
        }, 700);		     	
    },
    close : function() {
      closeBox();
    },
    hide : function() {
  		_over = false;
      clearTimeout(_timeout);	    
    }     		
  }
}();
