$(document).ready(function() {
	$('#gallery').cycle({
		fx:      'scrollHorz',
		speed:   1500,
		timeout: 8000,
		next:    '#gallery-next', 
	    prev:    '#gallery-prev',
		after:   onAfter,
		sync:    1
	});
			
	$("#gallery-over").mouseover(function () {
	    $('#gallery').cycle('pause'); 
	});
	$("#gallery-over").mouseout(function () {
		$('#gallery').cycle('resume'); 
	});
	$("#gallery-next").mouseover(function () {
	    $('#gallery').cycle('pause'); 
	});
	$("#gallery-next").mouseout(function () {
		$('#gallery').cycle('resume'); 
	});
	$("#gallery-prev").mouseover(function () {
	    $('#gallery').cycle('pause'); 
	});
	$("#gallery-prev").mouseout(function () {
		$('#gallery').cycle('resume'); 
	});
	$("#gallery-didascalia-command").click(function () {
		if ($("#gallery-didascalia").is(":hidden")) {
			$("#gallery-didascalia").animate({ height: "30px"}, 500 );
			$("#gallery-didascalia-command").html('-');
		} else {
			$("#gallery-didascalia").animate({ height: "0"}, 1000 );
			$("#gallery-didascalia-command").html('+');
		}
	});
   if($("#gallery > *").size() <= 1){
		$("#gallery-next").hide();
		$("#gallery-prev").hide();
	}

});
function onAfter() { 
    $('#gallery-didascalia-text').html('<h4>' + this.title + '</h4>');
}