// Replace all @ symbols in email fields, so can be replaced via img
(function($){
	$(document).ready(function() {
		$(".field-name-field-email, .views-field-field-email").each(function() {
			$(this).html($(this).html().replace('@','<span class="img_at"></span>'));
		});
	});
})(jQuery);


// Apre le mappe di Google al click sull'icona e gestisce l'icona stessa
(function($){
	$(document).ready(function() {
		// Se esiste la mappa visualizzo l'icona della mappa, sposto il blocco dentro
		// .location-locations-wrapper e attivo il slideToggle
		if($('.block-gmap-location').length){
			
			$('.location-locations-header').addClass('gmap_present');
			
			var GMapOpenFirstTime = true;
			$(".location-locations-header").click(function() {
				var myGMap = $(".block-gmap-location").detach();
				myGMap.appendTo(".location-locations-wrapper");
				if (GMapOpenFirstTime == true) {
					$(".block-gmap-location").hide();
					$(".block-gmap-location").css('left','0');
					$(".block-gmap-location").slideToggle(700);
					GMapOpenFirstTime = false;
				} else {
					$(".block-gmap-location").slideToggle(700);
				}
			});
		}
	});
})(jQuery);


// Nasconde/mostra gli appuntamenti del Vescovo dal 6° in poi
(function($){
	$(document).ready(function() {
		// Controllo se esiste il 6° appuntamento (':eq(5)'), se sì aggiungo i pulsanti e nascondo gli appuntamenti.
		if ($(".view-agenda-vescovo .views-row:eq(5)").length) {
			//$(".view-agenda-vescovo .view-content").append('<a id="toggle_items" href="#">Nascondi</a>');
			$("#toggle_items").show();
			$("#toggle_items").click(function(event){
				event.preventDefault();
				$(".view-agenda-vescovo .views-row:eq(4)").nextAll().not('#toggle_items').slideToggle('1800');
				if ($("#toggle_items").text() == 'Mostra Tutti') {
					$("#toggle_items").text('Nascondi');
				} else {
					$("#toggle_items").text('Mostra Tutti');
				}
			});
			//$(".view-agenda-vescovo .views-row:eq(4)").nextAll().not('#toggle_items').slideToggle('1000');
			$("#toggle_items").click();
		} else {
			$("#toggle_items").hide();
		}
	});
})(jQuery);


// Hide 'Related Videos' on YouTube videos at the end of the video
(function($){
	$(document).ready(function() {
		$('iframe.youtube-player').each(function() {	
			var newsrc = $(this).attr('src') + '&rel=0';
			$(this).attr('src', newsrc);
		});
	});
})(jQuery);

//
// Colorbox js enhancement for ddl theme
//(function ($) {
//	Drupal.behaviors.initColorboxStockholmsyndromeStyle = {
//	  attach: function (context, settings) {
//	    
	    // gestione tasto start/stop presentazione
//	    $('#cboxSlideshow').live('click',function(){
//	    	if ($('#cboxSlideshow').text() == 'avvia presentazione') {
//	    	  $('#cboxSlideshow').css('background-position', 'center -150px');
//	    	} else {
//	    	  $('#cboxSlideshow').css('background-position', 'center -450px');
//	    	}
//	    });
//	    $('#cboxSlideshow').mouseleave(function(){
//	      $('#cboxSlideshow').stop().fadeTo('slow',0);
//	    });
//	    $('#cboxSlideshow').mouseenter(function(){
//	      $('#cboxSlideshow').stop().fadeTo('slow',1);
//	    });
//	    
//	    $(document).bind('cbox_open', function () {
	      // Hide close button initially.
//	      $('#cboxClose', context).css('opacity', 0);
//	      $('#cboxPrevious', context).css('opacity', 0);
//	      $('#cboxNext', context).css('opacity', 0);
//	    });
//	    $(document).bind('cbox_load', function () {
	      // Hide close button. (It doesn't handle the load animation well.)
//	      $('#cboxClose', context).css('opacity', 0);
//	    });
//	    $(document).bind('cbox_complete', function () {
	      // Show close button with a delay.
//	      $('#cboxClose', context).fadeTo('slow', 1, function () {$(this).css('opacity', 1)});
//	    });
//	    
//	    $(document).bind('cbox_complete', function () {
	      // Only run if there is a title.
	      //if ($('#cboxTitle:empty', context).length == false) {
//	        
//       
//	        setTimeout(function () {
//	          $('#cboxTitle', context).slideUp();
//	          $('#cboxCurrent', context).slideUp();
//	        }, 2000);
//	        $('#cboxLoadedContent img', context).bind('mouseover', function () {
//	          $('#cboxTitle', context).slideDown();
//	          $('#cboxCurrent', context).slideDown();
//	        });
//	        $('#cboxOverlay', context).bind('mouseover', function () {
//	          $('#cboxTitle', context).slideUp();
//	          $('#cboxCurrent', context).slideUp();
//	        });
	      //}
	      //else {
	        //$('#cboxTitle', context).hide();
	        //$('#cboxCurrent', context).hide();
	      //}
//	      
	      // show Previous and Next on mouse over the img
//	      $('#cboxLoadedContent img', context).bind('mouseover', function () {
//	        $('#cboxPrevious', context).stop().fadeTo('slow', 1);
//	        $('#cboxNext', context).stop().fadeTo('slow', 1);
//	      });
//	      $('#cboxOverlay', context).bind('mouseover', function () {
//	        $('#cboxPrevious', context).stop().fadeTo('slow', 0);
//	        $('#cboxNext', context).stop().fadeTo('slow', 0);
//	      });
//	      
//	    });
//	        
//	  }
//	};
//
//})(jQuery);
//
;

