function mycarousel_initCallback(carousel) {
    jQuery('#listphoto-hmp-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#listphoto-hmp-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
		
		jQuery('#listphoto-next').bind('click', function() {
        carousel.next();
        return false;
    });
		jQuery('#listphoto-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};
function equalHeight(group) {
   tallest = 0;
   group.each(function() {
      thisHeight = $(this).height();
      if(thisHeight > tallest) {
         tallest = thisHeight;
      }
   });
   group.height(tallest);
}

function startHorizontalGallery(url) {
	$("#photo-wrap").load(url, 
		function (responseText, textStatus, XMLHttpRequest) {
			if (textStatus == "success") {
				jQuery('#listphoto').jcarousel({
					scroll: 1,
					initCallback: mycarousel_initCallback,
					// This tells jCarousel NOT to autobuild prev/next buttons
					buttonNextHTML: null,
					buttonPrevHTML: null
				});
			}
			if (textStatus == "error") {
					 alert(textStatus);
			}
			
		});
}

$(document).ready(function () {
// carousel home page video verticale	
jQuery('#listvideo-hmp').jcarousel({
        // Configuration goes here
				vertical: true
    });
// carousel home page foto orizzontale
jQuery("#listphoto-hmp").jcarousel({
				scroll: 1,
        initCallback: mycarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
// carousel home page foto orizzontale
jQuery("#listphoto").jcarousel({
				scroll: 1,
        initCallback: mycarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null,
				itemFallbackDimension: 600
    });

	// tabs 
//Default Action
	$(".tab-content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("on").show(); //Activate first tab
	$(".tab-content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("on"); //Remove any "active" class
		$(this).addClass("on"); //Add "active" class to selected tab
		$(".tab-content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});
// accordion
//Set default open/close settings
$('.acc_container').hide(); //Hide/close all containers
$('.acc_trigger:eq(0)').addClass('on').next().show(); //Add "active" class to first trigger, then show/open the immediate next container
$('.lst-mod-nazioni .acc_trigger:eq(0)').addClass('on').next().show();
//On Click
$('.acc_trigger').click(function(){
	if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
		$('.acc_trigger').removeClass('on').next().slideUp(); //Remove all .acc_trigger classes and slide up the immediate next container
		$(this).toggleClass('on').next().slideDown(); //Add .acc_trigger class to clicked trigger and slide down the immediate next container
	}
	return false; //Prevent the browser jump to the link anchor
});

// slider
$('.lst-news-flash').cycle({ 
    prev:	'.slider-news-flash-pre', 
    next:   '.slider-news-flash-next', 
    timeout: 0 
});

$(".subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
	
	$("ul.topnav li span").hover(function() { //When trigger is hover...
		
		//Following events are applied to the subnav itself (moving subnav up and down)
//this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
		$(this).parent().find(".subnav").show().addClass("left"); //Drop down the subnav on click
		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find(".subnav").hide().removeClass("left"); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});

	equalHeight($(".lst-index")); //pareggia l'altezza delle colonne
// TextSize
$('#mytextsize').atextsize();
});
