/*<![CDATA[*/
  function makeScrollable(wrapper, scrollable){
	  // Get jQuery elements
	  var wrapper = jQuery(wrapper), scrollable = jQuery(scrollable);
	  // Hide images until they are not loaded
	  scrollable.hide();
	  var loading = jQuery('<div class="loading">Loading...</div>').appendTo(wrapper);
	  // Set function that will check if all images are loaded
	  var interval = setInterval(function(){
		  var images = scrollable.find('img');
		  var completed = 0;
		  
		  // Counts number of images that are succesfully loaded
		  images.each(function(){
			  if (this.complete) completed++;	
		  });
		  
		  if (completed == images.length){
			  clearInterval(interval);
			  // Timeout added to fix problem with Chrome
			  setTimeout(function(){
				  
				  loading.hide();
				  // Remove scrollbars	
				  wrapper.css({overflow: 'hidden'});						
				  
				  scrollable.slideDown('slow', function(){
					  enable();	
				  });					
			  }, 1000);	
		  }
	  }, 100);
	  
	  function enable(){
		  // height of area at the top at bottom, that don't respond to mousemove
		  var inactiveMargin = 99;					
		  // Cache for performance
		  var wrapperWidth = wrapper.width();
		  var wrapperHeight = wrapper.height();
		  // Using outer height to include padding too
		  var scrollableHeight = scrollable.outerHeight() + 2*inactiveMargin;
		  // Do not cache wrapperOffset, because it can change when user resizes window
		  // We could use onresize event, but it's just not worth doing that 
		  // var wrapperOffset = wrapper.offset();
		  
		  // Create a invisible tooltip
		  var tooltip = jQuery('<div class="sc_menu_tooltip"></div>')
			  .css('opacity', 0)
			  .appendTo(wrapper);
	  
		  // Save menu titles
		  scrollable.find('a').each(function(){				
			  jQuery(this).data('tooltipText', this.title);				
		  });
		  
		  // Remove default tooltip
		  scrollable.find('a').removeAttr('title');		
		  // Remove default tooltip in IE
		  scrollable.find('img').removeAttr('alt');	
		  
		  var lastTarget;
		  //When user move mouse over menu			
		  wrapper.mousemove(function(e){
			  // Save target
			  lastTarget = e.target;
   
			  var wrapperOffset = wrapper.offset();
		  
			  var tooltipLeft = e.pageX - wrapperOffset.left;
			  // Do not let tooltip to move out of menu.
			  // Because overflow is set to hidden, we will not be able too see it 
			  tooltipLeft = Math.min(tooltipLeft, wrapperWidth - 75); //tooltip.outerWidth());
			  
			  var tooltipTop = e.pageY - wrapperOffset.top + wrapper.scrollTop() - 40;
			  // Move tooltip under the mouse when we are in the higher part of the menu
			  if (e.pageY - wrapperOffset.top < wrapperHeight/2){
				  tooltipTop += 80;
			  }				
			  tooltip.css({top: tooltipTop, left: tooltipLeft});				
			  
			  // Scroll menu
			  var top = (e.pageY -  wrapperOffset.top) * (scrollableHeight - wrapperHeight) / wrapperHeight - inactiveMargin;
			  if (top < 0){
				  top = 0;
			  }			
			  wrapper.scrollTop(top);
		  });
		  
		  // Setting interval helps solving perfomance problems in IE
		  var interval = setInterval(function(){
			  if (!lastTarget) return;	
										  
			  var currentText = tooltip.text();
			  
			  if (lastTarget.nodeName == 'IMG'){					
				  // We've attached data to a link, not image
				  var newText = jQuery(lastTarget).parent().data('tooltipText');
   
				  // Show tooltip with the new text
				  if (currentText != newText) {
					  tooltip
						  .stop(true)
						  .css('opacity', 0)	
						  .text(newText)
						  .animate({opacity: 1}, 1000);
				  }					
			  }
		  }, 200);
		  
		  // Hide tooltip when leaving menu
		  wrapper.mouseleave(function(){
			  lastTarget = false;
			  tooltip.stop(true).css('opacity', 0).text('');
		  });			
		  
		  /*
		  //Usage of hover event resulted in performance problems
		  scrollable.find('a').hover(function(){
			  tooltip
				  .stop()
				  .css('opacity', 0)
				  .text(jQuery(this).data('tooltipText'))
				  .animate({opacity: 1}, 1000);
	  
		  }, function(){
			  tooltip
				  .stop()
				  .animate({opacity: 0}, 300);
		  });
		  */			
	  }
  }
	  
  jQuery(function(){	
	  makeScrollable("div.sc_menu_wrapper", "div.sc_menu");
		 //Append a div with hover class to all the LI  
    jQuery('#navMenu li').append('<div class="hover"><\\/div>');   
    
  });
  /*]]>*/


//<![CDATA[


jQuery(document).ready(function () {

	//Append a div with hover class to all the LI
	jQuery('#box2 li').append('<div class="hover"><\/div>');


	jQuery('#box2 li').hover(
		
		//Mouseover, fadeIn the hidden hover class	
		function() {
			
			jQuery(this).children('div').fadeIn('1000');	
		
		}, 
	
		//Mouseout, fadeOut the hover class
		function() {
		
			jQuery(this).children('div').fadeOut('1000');	
		
	}).click (function () {
	
		//Add selected class if user clicked on it
		jQuery(this).addClass('selected');
		window.location = "prodotti.php?pro_tipo=0";
		
	});

});

//]]>



//<![CDATA[


jQuery(document).ready(function () {

	//Append a div with hover class to all the LI
	jQuery('#box li').append('<div class="hover"><\/div>');


	jQuery('#box li').hover(
		
		//Mouseover, fadeIn the hidden hover class	
		function() {
			
			jQuery(this).children('div').fadeIn('1000');	
		
		}, 
	
		//Mouseout, fadeOut the hover class
		function() {
		
			jQuery(this).children('div').fadeOut('1000');	
		
	}).click (function () {
	
		//Add selected class if user clicked on it
		jQuery(this).addClass('selected');
		window.location = "prodotti.php?pro_tipo=1";
		
	});

});

//]]>


function slideShow(speed) {


	//append a LI item to the UL list for displaying caption
	//jQuery('ul.slideshow').append('<li id="slideshow-caption" class="caption"><div class="slideshow-caption-container"><h4></h4><p></p></div></li>');

	//Set the opacity of all images to 0
	jQuery('ul.slideshow li').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	//jQuery('ul.slideshow li:first').css({opacity: 1.0});
	
	//Get the caption of the first image from REL attribute and display it
	//jQuery('#slideshow-caption h4').html(jQuery('ul.slideshow a:first').find('img').attr('title'));
	//jQuery('#slideshow-caption p').html(jQuery('ul.slideshow a:first').find('img').attr('alt'));
		
	//Display the caption
	//jQuery('#slideshow-caption').css({opacity: 0.7, bottom:0});
	
	//Call the gallery function to run the slideshow
	gallery();
	var timer = setInterval('gallery()',speed);
	
	//pause the slideshow on mouse over
	jQuery('ul.slideshow').hover(
		function () {
			clearInterval(timer);	
		}, 	
		function () {
			timer = setInterval('gallery()',speed);			
		}
	);
	
}

function gallery() {


	//if no IMGs have the show class, grab the first image
	var current = (jQuery('ul.slideshow li.show')?  jQuery('ul.slideshow li.show') : jQuery('#ul.slideshow li:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption')? jQuery('ul.slideshow li:first') :current.next()) : jQuery('ul.slideshow li:first'));
		
	//Get next image caption
	var title = next.find('img').attr('title');	
	var desc = next.find('img').attr('alt');	

	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
	
	/*
	//Hide the caption first, and then set and display the caption
	jQuery('#slideshow-caption').animate({bottom:-70}, 300, function () {
			//Display the content
			jQuery('#slideshow-caption h4').html(title);
			jQuery('#slideshow-caption p').html(desc);				
			jQuery('#slideshow-caption').animate({bottom:0}, 500);	
	});		
	*/
	//Hide the current image
	current.animate({opacity: 0.0}, 1000).removeClass('show');

}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

	
