	
		$(function(){
		var root = $('input[name=root]').val()	
			
			
			//menu a discesa sx
			$('ul a').collapsor();
			//select decorate
			$("li.numeri_carrello select").uniform();
			
			
			//inizializzo box notifica
			$("#container").notify();
			
			
			//al click dell'acquisto....
			$('input.bottone[value=Aggiungi] ').click(function(){
				//chiudo il carrello nel caso fosse aperto 
					if( $("a#link_c").attr('class')  =='bottone_carrello active' ){
						$("#carrello").slideToggle("slow");
						$("a#link_c").toggleClass("active");	
					} 

							
				//recupero valori 
				//var id =  $(this).parent().parent().parent().children('span').html();
					var id = $(this).attr('name')
					var n = $('[id=dati_'+id+']').val() ;
					var nome = $('[id=nome_'+id+']').val() ;
					var disponibile = $('[id=disponibile_'+id+']').val() ;

				if(disponibile == 0){
					//avvio box di errore
					$("#container").notify("create", "errore", {
						title: 'OOOOPS!!!',
						text: 'Prodotto non disponibile'
					})
					
					$('#dialog-form input[name=id_tmp]').val(id );
					$('#dialog-form').dialog('open');
					
					
					
					return false;
				}
					
			

				if (n != 00) {
					//avvio il box di notifica 
					$("#container").notify("create", "corretto", {
						title: 'Prodotto aggiunto al carrello',
						text: '' + nome,
						text_2: 'Pezzi:' + n
					});
					//gestisco la sessione con ajax
					$.ajax({
						type: "GET",
						url: root+"/lib/ajax/carrello.php",
						data: '&id=' + id + '&n=' + n,
						dataType: "html",
						error: function(event, request, settings){
							alert(event + request + settings)
						},
						success: function(msg){
							//alert(msg)
							$('span#oggetti_ajax').html(msg)
						}
					})
				}else{
					//avvio box di errore
					$("#container").notify("create", "errore", {
						title: 'OOOOPS!!!',
						text: 'Quantitativo errato'
					})
				}
		})
		
		
		
		
		
		
		/*visualizza nasconde carrello*/
		
		
			$(".bottone_carrello").click(function(){							
					if ($("a#link_c").attr('class') == 'bottone_carrello active') {
						return false;
					}
						
		
					
						$("#carrello").slideToggle("slow");					
					$("#c_carrello").load(root+'/tpl/pagine/inc/carrello.php');		
					$("a#link_c").toggleClass("active"); return false;
	});

	// link alla scheda tecnica
	$("a[class^=info_]").prettyPhoto({theme:'facebook'});	
	
	
	//password persa	
	$('a#password_persa').click(function(){
		var mail = $('div#blocco_login input[name=nome]').val()
		if(mail == ''){
			
			jAlert('Scrivi il tuo indirizzo nel campo "E-mail".\n Una nuova password ti verrà inviata automaticamente. ','Attenzione')
		}else{
			$.ajax({
				type: "POST",
				url: root+"/lib/ajax/chk_mail.php",
				data: '&mail=' + mail,
				dataType: "html",
				error: function(event, request, settings){
					alert(event + request + settings)
				},
				success: function(msg){
					msg = msg.trim()
					if(msg =='no'){
						//la mail esiste quindi procedo
						$.ajax({
							type: "POST",
							url: root+"/tpl/pagine/mail/recupero_psw.php",
							data: '&mail=' + mail,
							dataType: "html",
							error: function(event, request, settings){
								alert(event + request + settings)
							},
							success: function(msg){
								alert(msg)
									jAlert('Abbiamo spedito all\'indirizzo "'+mail+'" le istruzioni per il recupero della password.','Attenzione')					
								}
							});
					}else{
						//la mail non esiste
						jAlert('Il tuo indirizzo non è stato trovato nel nostro sistema.\nRicontrolla per favore. ','Attenzione')
					}
				}
			})	
		}	
	})		
});
