//<![CDATA[


//
var Cavalleri = {

  // Utilizzare una variabile per fare riferimento al file SWF incorporato.

	DOMready: function () {
		
		if ($('#slideshow').length > 0) { Cavalleri.slideSwitch(); };
		if ($('.data-content').length > 0) { Cavalleri.accordion(); };
		if ($('.submenu li a img').length > 0) { Cavalleri.subMenuHover(); };
		if ($('#mappa').length > 0) { Cavalleri.mappa(); };
		if ($('#creazioni').length > 0) { Cavalleri.subMenuHover(); };
		if ($('.vecchieAnnate').length > 0) { Cavalleri.vecchieAnnate(); };
		if ($('.popup').length > 0) { Cavalleri.popup(); };
		if ($("p[rel*='traccia-contatti']").length > 0) { Cavalleri.TracciamentoAnalytics('inviata-modulo-informazioni-' + lingua + '.html') };

	}, // fine DOMReady
	
	// metodo usato per ottenere il percorso giusto in base alla posizione
	returnPath: function () {
	  var path = location.pathname;
	  var li = path.length;
	  var lf = path.replace(/\//g, '').length;
	  // Windows var n = li-lf-2;
	  var n = li - lf - 1;
	  var resultPath = "";
	
	  for (var i = 0; i < n; i++) {
		resultPath += "./";
	  }
	
	  return resultPath
	}, // fine returnPath
	
	slideSwitch: function () {
		
		$('#slideshow').nivoSlider({
				effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
				//slices:15, // For slice animations
				//boxCols: 8, // For box animations
				//boxRows: 4, // For box animations
				animSpeed:500, // Slide transition speed
				pauseTime:5000, // How long each slide will show
				startSlide:0, // Set starting Slide (0 index)
				directionNav:false, // Next & Prev navigation
				directionNavHide:true, // Only show on hover
				controlNav:true, // 1,2,3... navigation
				controlNavThumbs:false, // Use thumbnails for Control Nav
				controlNavThumbsFromRel:false, // Use image rel for thumbs
				controlNavThumbsSearch: '.jpg', // Replace this with...
				controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
				keyboardNav:true, // Use left & right arrows
				pauseOnHover:true, // Stop animation while hovering
				manualAdvance:false, // Force manual transitions
				captionOpacity:0.8, // Universal caption opacity
				prevText: 'Prev', // Prev directionNav text
				nextText: 'Next', // Next directionNav text
				beforeChange: function(){}, // Triggers before a slide transition
				afterChange: function(){}, // Triggers after a slide transition
				slideshowEnd: function(){}, // Triggers after all slides have been shown
				lastSlide: function(){}, // Triggers when last slide is shown
				afterLoad: function(){} // Triggers when slider has loaded
			});

	},	/* fine slideSwitch */
	
	subMenuHover: function () {
		$('.submenu li a').each(function () {

            var obj = $(this);
			var thumb = obj.children('img');
			
			thumb.css('display', 'none');
			
			obj.hover(
			  function () {
					thumb.fadeIn();
			  }, 
			  function () {
					thumb.fadeOut();
			  }
			)
        });			
	}, /* fine subMenuHover */
	
	accordion: function () {
		
		$('.data-content').hide();  
		$('.data-title').click(function() {
			
			//$(this).addClass('on');
			var $nextObj = $(this).next();
			var $visibleSiblings = $nextObj.siblings('ul:visible');
			
			if ($visibleSiblings.length) {
				$visibleSiblings.slideUp('low', function() {
					$nextObj.slideToggle('low');
				})//;
			} 
			else {
				$nextObj.slideToggle('low')
			}
			return false;
		});		
	}, /* fine Accordion */
	
	vecchieAnnate: function () {
		
		var obj = $('.vecchieAnnate');
		var listTitle = $('.vecchieAnnate h2');
		var listLink = $('.vecchieAnnate ul');
		
		listLink.css('display', 'none');
		
		listTitle.click(function() {
			listLink.slideToggle();
		});
		
		listLink.mouseleave(function() {$(this).slideUp()})
	}, /* fine vecchieAnnate */
	
	mappa: function (){
		
		$('#appezzamenti li').each(function () {

            var obj = $(this);
			var trigger = obj.children('a');
            var info = obj.children('.preview');
						
			info.css('display', 'none');
			
			trigger.hover(
			  function (e) {
				var x = e.pageX - this.offsetLeft;
				if (x>480) info.css('left', '-480px');
					info.fadeIn();
			  }, 
			  function () {
					info.fadeOut();
			  }
			)
        });	
		
		var obj = $('#mappa .azienda');
		var image = obj.children('.preview');
		var myLink = obj.children('a')
		
		
		image.css('display','none');
		
		myLink.hover(
		  function (e) {
			var x = e.pageX - this.offsetLeft;
			if (x>480) image.css('left', '-480px');
				image.fadeIn();
		  }, 
		  function () {
				image.fadeOut();
		  }
		)		
		
	}, /* fine mappa */
	
	toolTip: function (){
	  $('.toolTip').tooltip({ showURL: false });
	}, /* fine toolTip */
	
	popup: function () {
		
//		if ($("#privacyForm").length)
//			$("#privacyForm").parent().css('display', 'none');
		
		$(".privacyForm").colorbox({width:"50%", height:"50%", iframe:true});
		
	}, // fine privacyForm
	
	TracciamentoAnalytics: function (pagina) {
	  
	  try {
	    var pageTracker = _gat._getTracker('UA-27424191-1');
		pageTracker._trackPageview(pagina);
	  }
	  catch (err) { }
	  
	} // fine TracciamentoAnalytics
	

} // chiusura classe Cavalleri

///////////////////////////////////////////////////////

$(document).ready(function() { Cavalleri.DOMready() });
//]]>
