$(document).ready(function() {
/* apre tutti i link con la classe external in una nuova pagina */

    $('a.external').click( function() {
	    window.open(this.href);
	    return false;
    });
	
		// select #flowplanes and make it scrollable. use circular and navigator plugins
		$("#flowpanes").scrollable({ circular: true, mousewheel: false }).navigator({
	
			// select #flowtabs to be used as navigator
			navi: "#navbar_footer",
	
			// select A tags inside the navigator to work as items (not direct children)
			naviItem: 'a',
	
			// assign "current" class name for the active A tag inside navigator
			activeClass: 'active',
	
			// make browser's back button work
			history: true
	
		});

		$('#navbar a').click(function() {
			var ancora = $(this).attr("href");	
			//in realtà è la navbar del footer la principale, triggero il click su di lei
			$('#navbar_footer a').each(function() {
				if (ancora == $(this).attr('href')) {
					$(this).click();
				}
			});
			//imposto la classe corretta anche sulla navbar dell'header
			$('#navbar a').each(function() {
				$(this).removeClass('active');
				if (ancora == $(this).attr('href')) {
					$(this).addClass('active');
				}
			});
			
			return false;
		
		});
		
		//se click su navbar del footer, cambio stile a navbar del header
		$('#navbar_footer a').click(function() {
			var ancora = $(this).attr("href");
			$('#navbar a').each(function() {
				$(this).removeClass('active');
				if (ancora == $(this).attr('href')) {
					$(this).addClass('active');
				}
			});	
		});	
		
		$('#slideshow').cycle({
			fx: 'scrollLeft',
			next: '#slideshow',
			timeout: 0,
			easing: 'easeInOutBack'
		});
	
	$.tools.tabs.slideshow.conf.interval = 8000;
	$.tools.tabs.slideshow.conf.autoplay = true;
	$("#navSlideHome").tabs(".SlideHome > img", {
		effect: 'fade',
		fadeOutSpeed: 1300,
		fadeInSpeed:1300,

	// start from the beginning after the last tab
	rotate: true

	// use the slideshow plugin. It accepts its own configuration
	}).slideshow();
	//$("#navSlideHome").data("slideshow").play();
	//console.dir($.tools);
	
	/**** pag contatti ****/
	$('.contatti_left form').submit(function() {
		$('input[type=submit]').attr("disabled", "true");
		$('.messaggioInvia').append("<span class='preload'><img style='margin-left:15px' width='16' height='16' src='includes/css/images/preload.gif' /></span>");
		$('input[name=nome]').css('border','1px solid #9B9D5A');
		$('input[name=email]').css('border','1px solid #9B9D5A');
		$('textarea').css('border','1px solid #9B9D5A');
		$.ajax({
			type: 'post',
			url: 'contatti/submit',
			dataType: 'json',
			data: $(this).serialize(),
			success: function(data) {
				$('.preload').remove();
				if (data.valido == false) {
					$('input[type=submit]').removeAttr("disabled");
					if (data.nome != "")
						$('input[name=nome]').css("border","1px solid #f00");
					if (data.email != '')
						$('input[name=email]').css('border','1px solid #f00');
					if (data.messaggio != '')
						$('textarea').css('border','1px solid #f00');
					$('input[type=submit]', this).removeAttr("disabled");
				}
				else {
					$('.messaggioInvia').html("<span class='preload'>"+data.data+"</span>");
				}
			}
		});
		return false;
	});
		
} );

