
function MostraBox(nomepagina){
	
	if (window.addEventListener)
	window.addEventListener('DOMMouseScroll', wheel, false);
	window.onmousewheel = document.onmousewheel = wheel;
				
	
	if($('#fondopagina').offset().top > document.body.clientHeight)
	{
		$('#oscuro').height($('#fondopagina').offset().top + 'px');
	}
	else
	{
		$('#oscuro').height(document.body.clientHeight + 'px');
	}
	
	//alert($('oscuro').style.height);
	$('#oscuro').show(); 	
	
	
	$('#box').css('margin-top','-200px');
	var marginebox = $('#box').css('margin-top').replace('px','');
	marginebox = parseInt(marginebox);


	var scrollbody = $("#bodyId").scrollTop();


	//var scrollbody = parseInt(document.body.scrollTop);
	
	var margineboxtot = marginebox + scrollbody;
	
	//alert(margineboxtot);
	
	$('#box').css('margin-top', margineboxtot + 'px');	
		
	
	$('#box').show();
	$('#box').animate({
     width: "700px"
  	}, 800, function() {
    	// Animation complete.
		$('#box').animate({
			 width: "600px"
		  }, 300, function() {
			// Animation complete.
			$('#box').animate({
			 width: "700px"
		  	}, 300, function() {
				// Animation complete.
				$('#box').animate({
				 width: "650px"
			 	 }, 300, function() {
					// Animation complete.
					$('#box').animate({
					 width: "700px"
					}, 300, function() {
						// Animation complete.				
						$('#box').animate({
						 height: "400px"
					  	}, 800, function() {
							// Animation complete.
							$('#box').animate({
							 height: "300px"
						  	}, 300, function() {
								// Animation complete.
								$('#box').animate({
									 height: "400px"
								  }, 300, function() {
									// Animation complete.
									$('#box').animate({
										 height: "350px"
									  }, 300, function() {
										// Animation complete.
										$('#box').animate({
										 height: "400px"
									  	}, 300, function() {
											// Animation complete.
											$('#chiudi').fadeIn('slow');
											$('#contenutobox').fadeIn('slow');
											
											//$('#contenutoboxcontainer').show();
											$('#contenutoboxcontainer').fadeIn('slow', function() {
												// Animation complete
												$.ajax({
												   type: "get",
												   url: nomepagina,
												   success: function(html){
													 //alert('complete');
													 $('#contenutoboxcontainer').html(html);
																													 
													 if($('#contenutoboxcontainer').css('height') > '350px')
													 {
														
														$('#bottom').fadeIn('slow');
														$('#top').fadeIn('slow');
																													
																														
																														
													 }
												   }
												 });
										 });

																												
												
																										  });
																								  });
																						  });
																			  });
																	  });
																	  
															});
													  
												 });
										  });
						  });
  });

	}




function ChiudiBox()
			{
				if (window.removeEventListener)
				window.removeEventListener('DOMMouseScroll', wheel, false)
				window.onmousewheel =  document.onmousewheel = null;
				$('#contenutobox').fadeOut('slow');
				$('#contenutoboxcontainer').html('');
				$('#contenutobox').scrollTop(0);
				
				
				$('#chiudi').hide();
				$('#bottom').hide();
				$('#top').hide();
				
				//Effect.Fade('contenutobox',{duration:0.2});
				
				////////Effect.Fade('contenutoboxcontainer',{duration:0.2});
				
				//Effect.Fade('chiudi',{duration:0.3});
				//Effect.Fade('bottom',{duration:0.3});
				//Effect.Fade('top',{duration:0.3});
				
				
				
				$('#box').fadeOut('slow', function() {
					// Animation complete
					$('#oscuro').fadeOut('slow', function() {
						// Animation complete
						$('#box').css('width','10px');
						$('#box').css('height','10px');
					}
					);		
												
				}
				);
				
				
				

				//Effect.Fade
//				('box', 
//					{
//						afterFinish: function(effect) 
//						{
//							effect.element.setStyle({ width: '10px', height: '10px' })
//							$('oscuro').hide();
//							//alert($('contenutobox').scrollTop);
//							//alert($('contenutoboxcontainer').scrollTop);
//							
//							
//
//						}
//				
//					}
//				);
		
				
			}




function MostraBoxOLD(nomepagina)
			{
				
				if (window.addEventListener)
				window.addEventListener('DOMMouseScroll', wheel, false);
				window.onmousewheel = document.onmousewheel = wheel;
				
				//$('contenutobox').setStyle({ height: '0px'});
				//alert($('contenutobox').getHeight());
				//alert($('provola').offsetTop);
				if($('fondopagina').offsetTop > document.body.clientHeight)
				{
					$('oscuro').style.height = $('fondopagina').offsetTop + 'px';
				}
				else
				{
					$('oscuro').style.height = document.body.clientHeight + 'px';
				}
				
				//alert($('oscuro').style.height);
				$('oscuro').show(); 
				
				Effect.Appear('box',{duration:0.2});

				
				//alert(document.body.scrollTop);
				//alert($('box').getStyle('marginTop'));
				$('box').style.marginTop = '-200px';
				var marginebox = $('box').getStyle('marginTop').replace('px','');
				marginebox = parseInt(marginebox);


				var scrollbody = $("bodyId").scrollTop;


				//var scrollbody = parseInt(document.body.scrollTop);
				
				var margineboxtot = marginebox + scrollbody;
				
				//alert(margineboxtot);
				
				$('box').style.marginTop = margineboxtot + 'px';
					
				$('box').morph
				('width:700px',
					{
						transition: Effect.Transitions.spring,duration:2, from: 0.5, to: 1 ,
						afterFinish: function(effect) 
						{
							$('box').morph
							('height:400px',
								{
								transition: Effect.Transitions.spring,duration:2,from: 0.5, to: 1,
								afterFinish: function(effect) 
									{
									Effect.Appear('chiudi',{duration:0.3});
									
									
									Effect.Appear('contenutobox',{duration:0,
									
									
									afterFinish: function(effect) 
									{
										//alert('ciao');
										
										$('contenutobox').scrollTop = 0;
										Effect.Appear('contenutoboxcontainer',{duration:0.3});
										
										
										$('contenutobox').scrollTop = 0;
										
									new Ajax.Updater('contenutoboxcontainer', nomepagina, 
									{
									method: 'get',
									onComplete: function() {
									//$('provola').update('pippo' + $('contenutobox').getHeight());
									//alert($('contenutoboxcontainer').clientHeight);
									//alert($('contenutoboxcontainer').getHeight());
										if($('contenutoboxcontainer').getHeight() > 350)
										{
											//alert('pippo');
											Effect.Appear('bottom',{duration:0.3});
											Effect.Appear('top',{duration:0.3});
											
											
										}
									
									}
									
									
									
									});
										
										
									}
									
									
									
									});
																
									
									
									
									}
								}
							);
						}
					}
				);
				
				
			}	



			function ChiudiBoxOLD()
			{
				if (window.removeEventListener)
				window.removeEventListener('DOMMouseScroll', wheel, false)
				window.onmousewheel =  document.onmousewheel = null;
				
				Effect.Fade('contenutobox',{duration:0.2});
				//Effect.Fade('contenutoboxcontainer',{duration:0.2});
				
				Effect.Fade('chiudi',{duration:0.3});
				Effect.Fade('bottom',{duration:0.3});
				Effect.Fade('top',{duration:0.3});

				Effect.Fade
				('box', 
					{
						afterFinish: function(effect) 
						{
							effect.element.setStyle({ width: '10px', height: '10px' })
							$('oscuro').hide();
							//alert($('contenutobox').scrollTop);
							//alert($('contenutoboxcontainer').scrollTop);
							
							

						}
				
					}
				);
		
				
			}



var controlclear = 0;
			var scrolltopbody = 0;
			
			function ScrollContenutoBottom(vel,box)
			{
				//alert('pippo');
				controlclear = 1;
				loop= true;
				scrolltimer= null;
				var element = $('#' + box);
				//alert(element);
				var elementStr = box;
				speed= vel;
				
				if (loop == true)
				{
					
					element.scrollTop(element.scrollTop() + speed);
					scrolltimer= setTimeout("ScrollContenutoBottom(" + vel + ",'" + box + "')",20)

				}
				//scrolltopbody = document.body.scrollTop;
				
			}
			
			function ScrollContenutoTop(vel,box)
			{
				//alert('inizio');
				controlclear = 1;
				loop= true;
				scrolltimer= null;
				var element = $('#' + box);
				var elementStr = box;
				speed= - vel;
				//alert('meta');
				
				if (loop == true)
				{
						//alert('prima');
					element.scrollTop(element.scrollTop() + speed);
					scrolltimer= setTimeout("ScrollContenutoTop(" + vel + ",'" + box + "')",20)
						//alert('dopo');

				}
				
				
				//scrolltopbody = document.body.scrollTop;

			}
			
			function ScrollContenutoStop()
			{
				//$("bodyId").scrollTop = scrolltopbody;

				if (controlclear==1)
				{
					loop = false;
					clearTimeout(scrolltimer);
					//document.body.scrollTop = scrolltopbody;
					
				}
				
			}
			
			
			
			/** This is high-level function; REPLACE IT WITH YOUR CODE.
			 * It must react to delta being more/less than zero.
			 */
			function handle(delta) {
				if (delta < 0)
					{
						//alert($('contenutobox').getStyle('display'));
						/* something. */;
						if ($('#contenutobox').css('display') != 'none')
						{
						//alert('ciaoooo2');
						ScrollContenutoBottom(50,'contenutobox');
						ScrollContenutoStop();
						}
						
					
					}
					
				else
					{
						if ($('#contenutobox').css('display') != 'none')
						{
						/* something. */;
						ScrollContenutoTop(50,'contenutobox');
						ScrollContenutoStop();
						}
					}
					
			}

			function wheel(event){

				var delta = 0;
				if (!event) event = window.event;
				if (event.wheelDelta) {
					delta = event.wheelDelta/120; 
					if (window.opera) delta = -delta;
				} else if (event.detail) {
					delta = -event.detail/3;
				}
				if (delta)
					handle(delta);
					if (event.preventDefault)
							event.preventDefault();
					event.returnValue = false;

			}

			/* Initialization code. */
			//if ($('contenutobox').getStyle('display') != 'none')
			//{
				//if (window.addEventListener)
				//window.addEventListener('DOMMouseScroll', wheel, false);
				//window.onmousewheel = document.onmousewheel = wheel;
			//}


			function CambiaTab(nomediv,q){
				alert($(nomediv).style.display);
				if (q==0){
					alert("q=0");
					if($(nomediv).style.display!= 'none'){//se il nome del div che passo NON è nascosto
						alert(nomediv+"="+$(nomediv).style.display);
					}else{
						$('divcategorie').toggle();
						$('divmarche').toggle();
						if($('TabCategorie').hasClassName('urlprodotti')){
							$('TabCategorie').className ='urlprodattivo';
							$('TabMarche').className = 'urlprodotti';
						}else{
							$('TabCategorie').className ='urlprodotti';
							$('TabMarche').className ='urlprodattivo';
						}
					}						
				}else{
					alert("q>0");
					switch(q){
						case 1:
							$('divcategorie').style.display='block';
							$('divmarche').style.display='none';
							break;
						case 2:
							$('divcategorie').style.display='none';
							$('divmarche').style.display='block';
							break;
					}
				}

			}
				
				
				
				
				function VediMarcheCat()
				{
					//new Ajax.Updater('contenutoprodotti', 'ciao', 
									//{
//									method: 'get'
//
//									});	
					
					$('contenutoprodotti').update('ciao');
					
				}




