var x;
var y;
$(document).mousemove(function(ee){
	x=ee.pageX
	y=ee.pageY
}); 
$(document).ready(function(){
    var e = $("<div></div>").attr('id','tooltip').appendTo("body");
	$('.tooltip').hover(function(){	   
	 	$('#tooltip').html($(this).attr('lang'))
		$('#tooltip').css('display','block')
		$('#tooltip').css('top',y+10)
		$('#tooltip').css('left',x+15)
		$('#tooltip').fadeTo(0.1,0.9)
	},function(){		
		$('#tooltip').css('display','none')
	})
	$('.tooltip').mousemove(function(){
		$('#tooltip').css('top',y+10)
		$('#tooltip').css('left',x+15)
	})
   $(".rounded").corner();
   $('#slideshow1').cycle({ 
    delay:  7000, 
    speed:  1000
   }); 
});
function addtochart(id){
    $.ajax({
      url: basecarrello+"add/"+id,
      cache: false,
      success: function(html){
        showcarrello(html);
      }
    });
}
function leavefromchart(id,qta){
    $.ajax({
      url: basecarrello+"leave/"+id+"/"+qta,
      cache: false,
      success: function(html){
        showcarrello(html);
      }
    });
}

function showcarrello(html){
        $("#dialog-content").html(html);
        $("#dialog-confirm").dialog({
        	resizable: false,
            width: 'auto',
        	modal: true,
        	buttons: {
        		'Svuota Carrello': function() {
        		      $.ajax({
                      url: basecarrello+"leaveall",
                      cache: false,
                      success: function(html){
                        showcarrello(html);
                      }
                    });
      			
        		},
                'Vai alla Cassa': function() {
        			location.href = baseordini;
        		},
        		'Continua gli acquisti': function() {
        			$(this).dialog('close');
        		}
        	}
        });
}

function loadindirizzo(divid,indirizzoid){
    if(indirizzoid){
         $.ajax({
      url: baseordini+"loadindirizzo/"+indirizzoid+"/"+divid,
      cache: false,
      success: function(html){
        $('#'+divid).html(html);
        $('#'+divid).show();
        if($('#sel1').val() && $('#sel2').val()){
            $('#avanti').show();    
        }
        else{
            $('#avanti').hide();
        }
      }
    });        
    }
    else{
        $('#'+divid).hide();
    } 
}
var pagamento;
var spedizione;
function selectpagamento(id){
    if(id){
         $.ajax({
      url: baseordini+"selectpagamento/"+id,
      cache: false,
      success: function(html){
        if(html!='error')
            pagamento = id;
        if(pagamento && spedizione){
            $('#avanti').show();    
        }
        else{
            $('#avanti').hide();
        }
      }
    });        
    }
}
function selectspedizione(id){
    if(id){
        $.ajax({
              url: baseordini+"selectspedizione/"+id,
              cache: false,
              success: function(html){
                if(html!='error')
                    spedizione = id;
                if(pagamento && spedizione){
                    $('#avanti').show();    
                }
                else{
                    $('#avanti').hide();
                }
              }
        });        
}
}
