var temp_menu;
var temp_sottomenu;
var temp_sotto_sottomenu;
var temp_sotto_sotto_sottomenu;
var temp;
$( 
	function() {
		$('.livello_0').next().slideUp('slow');
		$('.livello_1').next().slideUp('slow');
		$('.livello_2').next().slideUp('slow');
		$('.livello_3').next().slideUp('slow');
		
		$('.livello_3').bind('click' , function() {
       			if ((temp_sotto_sotto_sottomenu!=null)) {
       				temp_sotto_sotto_sottomenu.slideUp('slow');
       				$(this).next().slideDown('slow');
       				temp_sotto_sotto_sottomenu=$(this).next();
       			} else {
	       			$(this).next().slideDown('slow');
	       			temp_sotto_sotto_sottomenu=$(this).next();	       			
	       		}
     	});
		       
       $('.livello_2').bind('click' , function() {
       			if ((temp_sotto_sottomenu!=null)) {
       				temp_sotto_sottomenu.slideUp('slow');
       				$(this).next().slideDown('slow');
       				temp_sotto_sottomenu=$(this).next();
       			} else {
	       			$(this).next().slideDown('slow');
	       			temp_sotto_sottomenu=$(this).next();	       			
	       		}
     	});

		$('.livello_1').bind('click' , function() {
       			if ((temp_sottomenu!=null)) {
       				temp_sottomenu.slideUp('slow');
       				$(this).next().slideDown('slow');
       				temp_sottomenu=$(this).next();
       			} else {
	       			$(this).next().slideDown('slow');
	       			temp_sottomenu=$(this).next();	       			
	       		}
     });
     $('.livello_0').bind('click' , function() {
       			if ((temp_menu!=null)) {
       				temp_menu.slideUp('slow');
       				$(this).next().slideDown('slow');
       				temp_menu=$(this).next();
       			} else {
	       			$(this).next().slideDown('slow');
	       			temp_menu=$(this).next();	       			
	       		}
       			
     });
     
     zoomIn=false;
     videoIn=false;
      /*$('#lente').bind('click' , function() {    	  
    	  if (!zoomIn) {
    		  $(this).attr('href', '#zoom' );
    		  $('#zoom').fadeIn('slow', function() {
    			 zoomIn=true;
    		  }); 
    	  } else {
    		  $('#zoom').fadeOut('slow', function() {    			 
     			 zoomIn=false;
     		  });
    		  $(this).attr('href', '#' ); 
    	  }
      });*/
      /*$('.lente').bind('click' , function() {    	  
    	  $(this).parent().prev().children(0).children(0).children(0).fadeIn('slow');
      });*/
     
     $('.lente').bind('click' , function() {    	  
    	 try {
 			temp.fadeOut('slow');
    	 }
 		 catch (e) {
 		 }    	  
    	 $(this).parent().prev().children(0).children(0).next().fadeIn('slow');
    	 temp=$(this).parent().prev().children(0).children(0).prev();
     });
     
     $('#lente').bind('click' , function() {    	  
   	  if (!zoomIn) {
   		  if (!videoIn) {
   			  $('#video').fadeIn('slow', function() {
   				  videoIn=true;
   			  });
   		  } else {
   			  $('#video').fadeOut('slow', function() {
 				  videoIn=false;
 			  }); 
   		  }   		  
   	  } else {
   		  $('#zoom').fadeOut('slow', function() {    			 
    			 zoomIn=false;
    			 $('#video').fadeIn('slow', function() {
      				  videoIn=true;
      			 });
    		  });
   	  }
     });
     
      $('.img_art').bind('click' , function() {
    	  try {
    			temp.fadeOut('slow');
    	  }
    		catch (e) {
    	  }    	  
    	  temp=$(this).parent().prev().prev();
    	  $(this).parent().prev().prev().fadeIn('slow');
      });
      
      $('#img_art').bind('click' , function() {
    	  if (!videoIn) {
    		  if (!zoomIn) {
    			  $('#zoom').fadeIn('slow', function() {
    				  zoomIn=true;
    			  }); 
    		  } else {
    			  $('#zoom').fadeOut('slow', function() {    			 
    				  zoomIn=false;
    			  });
    		  }
    	  } else {
    		  $('#video').fadeOut('slow', function() {    			 
     			 videoIn=false;
     			 $('#zoom').fadeIn('slow', function() {
       				  zoomIn=true;
       			 });
     		  });
    	  }
      });
      
      $('#chiudi_zoom').bind('click' , function() {    	  
    	   $('#zoom').fadeOut('slow', function() {    			 
     			 zoomIn=false;
    	   });
      });
      $('#chiudi_video').bind('click' , function() {    	  
    	   $('#video').fadeOut('slow', function() {    			 
    			 videoIn=false;
    	   });
     });
      
      $('.chiudi_zoom').bind('click' , function() {
    	  $(this).parent().parent().parent().fadeOut('slow');
      });
      $('.chiudi_video').bind('click' , function() {
    	  $(this).parent().parent().parent().fadeOut('slow');
      });
      
      var options = { 
        target:        '#catalogo',   // target element(s) to be updated with server response 
        //beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse,  // post-submit callback 
 
        // other available options: 
        url:       '/shop-ajax/utente/save'         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 
      
      var options_account = { 
    	        target:        '#catalogo',   // target element(s) to be updated with server response 
    	        //success:       showResponse_account,  // post-submit callback 
    	        url:       '/account-ajax/save'         // override for form's 'action' attribute     	       
    	    }; 
      var options_error = { 
  	        target:        '#catalogo',   // target element(s) to be updated with server response 
  	       // success:       showResponse_account,  // post-submit callback 
  	        url:       '/account-ajax/new'         // override for form's 'action' attribute   	       
  	    };
    
    $('#form-dati-utente').submit(function() { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(options); 
 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    }); 
    
    $('#login-shop').submit(function() { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(options_account); 
 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    }); 
    
    $('#error-form').submit(function() {
		$(this).ajaxSubmit(options_error); 
		 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false;
	})
    
});

function showResponse(responseText, statusText)  {
											
}

function showResponse_account(responseText, statusText)  {
									
}

function pop(URL,nome,winWidth,winHeight,winLeft,winTop,SB,RSZ) {
	if (winLeft < 0)
		winLeft = screen.width - winWidth + winLeft
	if (winTop < 0)
		winTop = screen.height - winHeight + winTop
	if (winTop == "cen")
		winTop = (screen.height - winHeight)/2 - 20
	if (winLeft == "cen")
		winLeft = (screen.width - winWidth)/2
	if (winLeft>0 & winTop>0)
		window.open(URL, nome, 'width='+winWidth+',height='+winHeight+',fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars='+SB+',resizable='+RSZ+',directories=no,location=no,left='+winLeft+',top='+winTop+',screenX='+winLeft+',screenY='+winTop);
}		





function fzoom(box) {
	document.getElementById(box).style.display='block';
}


function nozoom(box) {
	document.getElementById(box).style.display='none';
}


function zoom(box,imgZoom,title) {
	try {
		document.getElementById(temp).style.display='none';
	}
	catch (e) {
	}
	document.getElementById(box).innerHTML='<fieldset class=\"zoom_container\"><legend><a name="zoom"></a>'+title+'</legend><img alt="" src="/ext/shop/img/'+ imgZoom +'" /><div style="text-align:right"><span onclick="nozoom(temp)" class="chiudi_zoom">chiudi</span></div></fieldset>';
	//alert('http://1.pre.wineuropa.net/ext/shop/img/'+ imgZoom);
	temp=box;
	setTimeout('fzoom(temp)',500);
}

function img_zoom(img,src) {
	document.getElementById(img).src='/ext/shop/img/'+src;
}
