openBooking = function(url) {
	$.fancybox({
		'maxWidth'		: 800,
		'maxHeight'		: 600,
		'fitToView'		: false,
		'autoSize'		: true,
		'closeClick'	: false,
		'openEffect'	: 'none',
		'closeEffect'	: 'none',
		'href'			: url,
		'type'			: 'ajax'
	});	
}

$(window).load(function() {
	$('.slider').nivoSlider({
        effect: 'sliceDown', // 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: 8000, // 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: false, // 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: false, // Use left & right arrows
        pauseOnHover: true, // Stop animation while hovering
        manualAdvance: false, // Force manual transitions
        captionOpacity: 0, // Universal caption opacity
        prevText: 'Prev', // Prev directionNav text
        nextText: 'Next', // Next directionNav text
        randomStart: false, // Start on a random slide
        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
    });
});

$(document).ready(function() {
	
	// CAROUSEL HOMEPAGE
    $('#mycarousel').jcarousel({
    	wrap: 'circular'
    });
	
	// CORNERS FOR IE7/8
	if(jQuery().corner) {
		$('.rounded3').corner("3px");
		$('.rounded5').corner("5px");
		$('.roundedbottom3').corner("bottom 3px");
		$('.roundedbottom5').corner("bottom 5px");
	
		$('.scheda-bb tr.expanded td.stanza').corner("top 5px");
		$('.scheda-bb .descrizione td').corner("bottom 5px").corner("right 5px");
		
		$('#contactform input, #contactform textarea').corner("1px");
		$('#contactform .form-submit').corner("3px");
		$('.bookingBtn01').corner("10px");
		//$('.bookingBtn02').corner("top 10px");
		$('#references .col_14 div').corner("3px");
	}
	
	// FANCYBOX
	$('.fancybox').fancybox({});
	
	// BOOKING FORM
	//$('.bookingBtn02').css('right','-'+(parseInt($('.bookingBtn02').width()/2)+10)+'px');
	$('.bookingBtn01, .bookingBtn02').fadeIn(1000);
	
	$('.bookingBtn01 a, .bookingBtn02 a').click(function() {
		var lingua = $(this).attr("rel");
		openBooking(lingua+'/'+'prenota');
	});
	
	// FACEBOOK SHAREBOX/FANPAGE
	(function(d, s, id) {
		var js, fjs = d.getElementsByTagName(s)[0];
		if (d.getElementById(id)) return;
		js = d.createElement(s); js.id = id;
		js.src = "//connect.facebook.net/it_IT/all.js#xfbml=1&appId=154335414641137";
		fjs.parentNode.insertBefore(js, fjs);
	}(document, 'script', 'facebook-jssdk'));
	
	// TOGGLER DETTAGLI STANZA
	$('.toggler').bind('click', function(e, h){
		elm =$(this);
		elm.toggleClass('toggler-expand');
		elm.toggleClass('toggler-collapse');
		elm.parent().toggleClass('expanded');
		elm.parent().parent().toggleClass('expanded');
		$('#D'+elm.attr('rel')).toggle();
		
		if(jQuery().corner) $('.scheda-bb tr.expanded td.stanza').corner("top 5px");	
	});
	
	// CONTATTI - MAPPA
	if($("#map").length){
		var ll = $('#g-address').attr('rel').split(':');;
		var latlng = new google.maps.LatLng(ll[0], ll[1]);
		var myOptions = {
			scrollwheel:false,
			disableDefaultUI: true,
			zoomControl: true,
			zoom: 15,
			center: latlng,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		var map = new google.maps.Map(document.getElementById("map"), myOptions);
		var marker = new google.maps.Marker({
		  map: map,
		  position: latlng
		});	
	}
	
	// CONTATTI - FORM CONTATTO
	
	// Validazione form LOGIN
	var eMessagesContatti = {
		'it' :	{
					email			: {required: "inserisci il indirizzo email", email: "indirizzo email non valido"},
					nome 			: {required: "inserisci il tuo nome e cognome"},
					messaggio 		: {required: "scrivi il messaggio"}
				},
		'en' :	{
					email			: {required: "write your email address", email: "email address is invalid"},
					nome 			: {required: "write your name and surname"},
					messaggio 		: {required: "write your message"}
				},
		'fr' :	{
					email			: {required: "write your email address", email: "email address is invalid"},
					nome 			: {required: "write your name and surname"},
					messaggio 		: {required: "write your message"}
				},
		'de' :	{
					email			: {required: "write your email address", email: "email address is invalid"},
					nome 			: {required: "write your name and surname"},
					messaggio 		: {required: "write your message"}
				}
	}
	
	$("#contactform").validate({
		rules: {
			nome: "required",
			email: {
				required: true,
				email: true
			},
			messaggio: "required"
		},
		messages: eMessagesContatti[lang],
		
		success: function(label) {
			label.html("&nbsp;").addClass("checked");
		},
		submitHandler: function() {
			$('input:submit').val('attendere prego...');
			$.post(
				"/ajax/contatti.php",
				{ nome: $('#nome').val(), email: $('#email').val(), telefono: $('#telefono').val(), messaggio: $('#messaggio').val(), prodotto: $('#prodotto').val(), newsletter: $('#checkboxNewsletter').val(), IDLingua: $('#IDLingua').val() },
				function(data){
					$('#contactform').fadeOut("slow", function() {
						$("div#message").html(data);
						$("div#message").fadeIn("slow");
						$('#nome').val("");
						$('#email').val("");
						$('#telefono').val("");
						$('#messaggio').val("");
					  });
				}
			)
		}
	});
	
	// CONTATTI - NOTE LEGALI
	$("a.noteLegali").fancybox({
		'autoDimensions' 	:  false,
		'width'   			: 900,
		'height'            : 500,
		'scrolling'			: 'yes',
		'hideOnOverlayClick':  true,
		'showNavArrows' 	: true,
		'titleShow' 		: false
	});
	
	$('#checkboxNewsletter').click(function(){
		if ($(this).val()==0) {$(this).val('1');} else { $(this).val('0'); }
	});
	
	
	$(".highlight").hover(function(){
		var ID = $(this).attr("id");
		$('#highlight-'+ID).addClass('highlight');
	},
	  function () {
		var ID = $(this).attr("id");
		$('#highlight-'+ID).removeClass("highlight");
	  }
	);
	
});
