$(document).ready(function() {
	//PNGFIX
	$(document).pngFix();
	//GALLERY
	$("a[rel^='gallery_overlay']").prettyPhoto({theme: 'dark_rounded'});
	$("a[rel^='gallery_overlay']").hover(function(){
		$(this).append('<span class="hover"></span>');
	}, function() {
		$('span.hover', this).remove();
	});	

	$('.link_video a').click(function(){return false;});	
								  
	$('.torna_su a').click(function(){
		$.scrollTo( this.hash, 2000);
		return false;
	});

	//RIMUOVE CLASSE PER IL CSS NOJS
	$('body').removeClass('nojs');

	//CORNER
	$('.corner').rounded();

	//chiudi_benvenuto per le versioni diverse di home
	$('.chiudi_benvenuto').click(function () {$('.benvenuto, .benvenuto_home').slideUp();});

	//EVENTI SCROLLER VERTICALE 
	$('.home_eventi_carousel').jCarouselLite({
		vertical: true,
		hoverPause: true,
		visible: 3,
		auto: 1500,
		speed: 1000
	});

	//SLIDE HOME
	//nascondo l'immagine e la metto come sfondo del div
	$('.item_slide').each(function() { $(this).css('background-image', 'url(' + $(this).find('img').attr('src') + ')'); $('img', this).hide(); });
	$('.content_slide').cycle({ 
		fx: 'fade', 
		timeout: 5500,
		speed: 1500,
		fit: 1,
		random: 1,
		requeueOnImageNotLoaded: true,		
		next:   '#next_slide', 
		prev:   '#prev_slide' 
	});
	//slide home offerte
	$('.offerte_slide').cycle({timeout: 4000, speed: 1000});	
	//slide magnifica italia	
	$('.magnifica_italia_slide').cycle({timeout: 4000, speed: 1000});
	
	//slide testata home
//	$('.slide_testata_home').cycle({ timeout: 10000, speed: 1000, requeueOnImageNotLoaded: true});	

	
	
	//STESSA ALTEZZA COLONNE RICERCA
	$('.ricerca_scelta_campi .stessa_altezza').equalHeight();	
	
	//SCROLL
	$('.condividi .scrollable').scrollable({ keyboard: false, clickable: false, size: 4 });
	$('.preview_foto .scrollable').scrollable({ keyboard: false, clickable: false, size: 3 });
	$('.preview_video .scrollable').scrollable({ keyboard: false, clickable: false, size: 3 });
	$('.preview_idee_vacanze_home .scrollable').scrollable({ keyboard: false, clickable: false, size: 1 });
	$('.gallery_home .scrollable').scrollable({ keyboard: false, clickable: false, size: 1 });
	$('.preview_idee_vacanze .scrollable').scrollable({ keyboard: false, clickable: false, size: 1 });
	$('.preview_virtual_tour .scrollable').scrollable({ keyboard: false, clickable: false, size: 1 });
	$('.preview_much_more .scrollable').scrollable({ keyboard: false, clickable: false, size: 1 });	
	$('.gallery_idee_vacanze .scrollable').scrollable({ keyboard: false, clickable: false, size: 5 });

	//fix per hover ie
	$('a.prev, a.next, a.prevPage, a.nextPage').hover(function(){$(this).addClass('hover');}, function() {$(this).removeClass('hover');});
	
	
	//Prendo l'alt delle immagini dei cluster e la metto come caption in home page
	$('.x3 a').each(function() {
		$(this).append('<span class="caption_x3"><span>' + $(this).find('img').attr('alt') + '</span></span>');
	});
	$('.x4 a').each(function() {
		$(this).append('<span class="caption_x4"><span>' + $(this).find('img').attr('alt') + '</span></span>');
	});
	$('.preview_virtual_tour .scrollable div a').each(function() {
		$(this).append('<span class="caption_vt"><span>' + $(this).find('img').attr('alt') + '</span></span>');
	});
	$('.preview_much_more .scrollable div a').each(function() {
		$(this).append('<span class="caption_vt"><span>' + $(this).find('img').attr('alt') + '</span></span>');
	});
	$('.item_link_sidebar a').each(function() {
		$(this).append('<span class="caption_link"><span>' + $(this).attr('title') + '</span></span>');
	});
	
	//APRI CHIUDI RICERCA
	$('.ricerca_itinerari form').hide();
	$('.apri_ricerca').click(function () {
		$('.ricerca_itinerari form').slideToggle('fast');
		$('.tabs_itinerari').toggleClass('ricerca_aperta');
		return false;
	});
	$('.chiudi_ricerca').click(function () {
		$('.ricerca_itinerari form').slideUp('fast');
		$('.tabs_itinerari').removeClass('ricerca_aperta');
		return false;
	});


	/*
	$('.ricerca_itinerari form').hover(function(){
		//nessuna azione
	}, function() {
		$(this).slideUp('fast');
		$('.tabs_itinerari').removeClass('ricerca_aperta');		
	});	
	*/

	//TAB Singolo Itinerario	
	$('ul.tab_primo_livello').tabs('div.pannelli_primo_livello > div'); 
	$('ul.tab_secondo_livello').tabs('div.pannelli_secondo_livello > div');
	$('ul.tab_media').tabs('div.pannelli_media > div');

	//SCELTA VISTA ITINERARI	
	$('ul.scelta_vista li').hover(function () { $(this).addClass('hover'); }, function () { $(this).removeClass('hover'); });
	$('.vedi_schede').click(function () { $('.blocco_itinerari').removeClass('vista_lista').addClass('vista_schede'); });
	$('.vedi_lista').click(function () { $('.blocco_itinerari').removeClass('vista_schede').addClass('vista_lista'); });

	//OPACITY a rollover
	$('.preview').hover(function(){$('img', this).css("opacity", 0.7);}, function() {$('img', this).css("opacity", 1.0);});	

	//ITINERARIO
	//nascondo l'immagine e la metto come sfondo del div
	$('.img_itinerario').each(function() {$(this).css('background-image', 'url(' + $(this).find('img').attr('src') + ')');$('img', this).hide();});

/*

	$('.itinerario').each(function(){$('.nome_itinerario', this).css({top:'185px'});});
	$('.itinerario').hover(function(){$('.nome_itinerario', this).stop().animate({top:'94px'},{queue:false,duration:160});}, function() {$('.nome_itinerario', this).stop().animate({top:'185px'},{queue:false,duration:160});});		

*/

	$('.vista_schede .nome_itinerario h2 a').jTruncate({
		length: 35,
		moreText: " "
	});
	/*$('.testo_benvenuto').jTruncate({length: 37});*/
	

	$('.vista_schede .itinerario').hover(function(){
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});	

	//STAR RATING -- VOTO ITINERARI
	$('.rating_itinierario').show();
	$('.vota_itinerario :submit').hide();
	$('.auto-submit-star').rating({
		callback: function(value, link){
		 this.form.submit();
		}
 	});
	
	//APRI CHIUDI SINGOLO POI
//	$('.singolo_poi_contenuto').hide();	
	$('.apri_chiudi_poi h3').css('cursor', 'pointer');	
	$('.apri_chiudi_poi').click(function () {
		$('h3', this).toggleClass('aperto'); 
		$('.singolo_poi_contenuto', this).slideToggle();
	});	

	// funzione per aggirare il problema dell'iframe 
	// $('.call_iframe').load("idee-di-vacanza.html");
	
	$("a[rel^='esterno']").click(function(){
		 this.target = "_blank";
	});	
		
	
});








