if (!rollListName) {
	var rollListName = '#jqroll';
}
if (!rollLeftButtonName) {
	var rollLeftButtonName = '#LPic';
}
if (!rollRightButtonName) {
	var rollRightButtonName = '#RPic';
}
if (!rollImageWidth) {
	var rollImageWidth = 77;
}
if(!rollVisual){
	var rollVisual = 8; // Numero di roll da visualizzare - roll to be displayed
}
var intervallo = 500000; // >1500
var jqRollRotateing = false;

$(document).ready(function() {
    // Totale roll
    var numRoll = $(rollListName).children().length;

    // Controllo di overflow
    if (rollVisual > numRoll) {
        rollVisual = numRoll;
    }

    // Hide delle roll superflue all'inizializzazione
    for (var i = rollVisual; i < numRoll; i++) {
        $($(rollListName).children()[i]).css("opacity", "0").css("width", "0");
    }

    var gestInter = setInterval(jqRollRotate, intervallo);

    // Gestione del mouseover-mouseout
    $(rollListName).mouseover(function() { clearInterval(gestInter) });
    $(rollListName).mouseout(function() { gestInter = setInterval(jqRollRotate, intervallo); });
    $(rollLeftButtonName).click(function() {
    	if (!jqRollRotateing) {
	    	clearInterval(gestInter);
	    	jqRollRotate();
	    	gestInter = setInterval(jqRollRotate, intervallo);
    	}
    });
    $(rollRightButtonName).click(function() {
    	if (!jqRollRotateing) {
    		clearInterval(gestInter);
    		jqRollRotateReverse();
    		gestInter = setInterval(jqRollRotate, intervallo);
    	}
    });
});

function jqRollRotate(_rollVisual) {
	jqRollRotateing = true;
	
    // Inserire lo stesso valore utilizzato per definire l'altezza ed i margini dei div nel file css/style.css
//    var altezzaDiv = -118;
//    var margineDiv = 0;

    var list = $(rollListName).children();
    var hideItem = $(list[0]);
    // Hide della prima roll
    hideItem.animate({ opacity: 0, width: 0 }, 200, "linear", function() {
    // Movimento verso l'alto
//        $(list[0]).animate({ marginTop: altezzaDiv }, 200, "linear", function() {
        // Ripristino posizione elemento nascosto
//            $(list[0]).css("margin", margineDiv);
            // Spostamento in coda dell'elemento nascosto
            $(rollListName).append(hideItem);
            // Visualizzazione dell'ultima roll
            var index = (list.length <= rollVisual) ? 0 : rollVisual;
            var showItem = $(list[index]);
            showItem.css('width', rollImageWidth).animate({ opacity: 1}, 200, "linear", function () {
            	jqRollRotateing = false;
            });
//        });
    });
}

function jqRollRotateReverse(_rollVisual) {
	jqRollRotateing = true;
	
	var list = $(rollListName).children();
	var hideItem = $(list[rollVisual-1]);
	hideItem.animate({ opacity: 0}, 200, "linear", function() {
		hideItem.css('width', 0);
		var showItem = $(list[list.length - 1]);
		showItem.insertBefore($(list[0]));
//		hideItem.css('width', 0);
		showItem.animate({ opacity: 1, width: rollImageWidth}, 200, "linear", function () {
			jqRollRotateing = false;
		});
	});
}

