function nova_carousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    //carousel.buttonNext.bind('click', function() {
    //    carousel.startAuto(0);
    //});

    //carousel.buttonPrev.bind('click', function() {
    //    carousel.startAuto(0);
    //});

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery(document).ready(function(){
	$('ul#scrollticker').show(); 
	$('ul#scrollticker').liScroll(); 

	$('a.ticker-fancy-selector').fancybox({
		'transitionIn'		:	'elastic',
		'transitionOut'		:	'elastic',
		'speedIn'			:	600,
		'speedOut'			:	200,
		'overlayShow'		:	false,
		'opacity'			:	true,
		'cyclic'			:	true,
		'titleShow'			:	false,

		'showNavArrows'		:	false,
		'showCloseButton'	:	false,

		'onComplete'			:	function(selectedArray, selectedIndex, selectedOpts) {
			$('.fancy-btn-prev').click(function(e) {
				e.preventDefault();
				$.fancybox.prev();
			});

			$('.fancy-btn-next').click(function(e) {
				e.preventDefault();
				$.fancybox.next();
			});

			$('.fancy-btn-close').click(function(e) {
				e.preventDefault();
				$.fancybox.close();
			});
		}
	});

	$('a.fancy-selector-gallery').fancybox({
      'titlePosition': 'inside'
    });

	$('a.fancy-selector').fancybox();

	$('#search_data_relativa').click(function() {
		$('#search_tipo_data_relativa').attr('checked', true);
	});

	$('#search_data_relativa').click(function() {
		$('#search_tipo_data_relativa').attr('checked', true);
	});

	$('#search_data_specifica_dal_day, #search_data_specifica_dal_month, #search_data_specifica_dal_year').click(function() {
		$('#search_tipo_data_specifica').attr('checked', true);
	});

	$('#search_data_specifica_al_day, #search_data_specifica_al_month, #search_data_specifica_al_year').click(function() {
		$('#search_tipo_data_specifica').attr('checked', true);
	});

  if ($('#header_username')) {
    $('#header_username').focus();
  }

  if ($('#login-auth-error-launch') && $('#login-auth-error')) {
    $('#login-auth-error-launch').fancybox({
      'transitionIn'		:	'elastic',
      'transitionOut'		:	'elastic',
      'speedIn'			:	600,
      'speedOut'			:	200,
      'width'			:	400,
      'height'			:	75,
      'autoDimensions'  : false
    });

    $('#login-auth-error-launch').click();
  }

  $('form#galleria_form select#categoria_id').change(function() {
    $('form#galleria_form').submit();
  });

  $('#rullino-carousel').jcarousel({
    easing: 'linear',
    animation: 1500,
    scroll:    1,
    auto: 0.00001,
    wrap: 'circular',
    initCallback: nova_carousel_initCallback,
    // This tells jCarousel NOT to autobuild prev/next buttons
    buttonNextHTML: null,
    buttonPrevHTML: null 
  });
});
