var bannerFunction = function () {
    var sposta = 0;
	//variabile myClick
    bn = 0;
    //nВ° banner da far ruotare
    myBox = $("div#banners .box").length;
	//alert(myBox)
    maxL = myBox - 3;
    //alert(myBox);
    //alert(myBox-3)
    //calcolo la larghezza effettiva del box;
    mLeft = parseInt($('.box').css('margin-left'));
    mRight = parseInt($('.box').css('margin-left'));
    bWidth = parseInt($('.box').css('width'));
    bslide = parseInt(bWidth + mLeft + mRight);
    //calcolo e riassegno la larghezza del container
    bSlideWidth =parseInt( bslide * myBox);
    //alert(slideWidth)
	$('#banners').css({
	  'width': bSlideWidth
	});

    //azione slide avanti
    $('#next').click(function () {
        
		
		//controllo se è l'ultimo banner
        if (bn - maxL >= -1) {
			//alert("ultimo")
            $('#next').css('visibility', 'hidden');
            $('#nextOff').css('visibility', 'visible');
            bn++;
			sposta = parseInt(bslide * bn);
        } else {
			//alert("next")
            bn++;
        }

	});	//fine next

    //azione slide avanti
    $('#next').click(function () {

        //controllo se è l'ultimo banner
        if (bn - maxL >= -1) {
            $('#next').css('visibility', 'hidden');
            $('#nextOff').css('visibility', 'visible');
            $('#prev').css('visibility', 'visible');
            $('#prevOff').css('visibility', 'hidden');

            bn++;
        } else {
            bn++;
        }

        $('#banners').animate({
            right: +bslide * bn,
        }, 'slow', function () {
            // Animation complete.
            if (bn == 1) {
				alert("ciao")
                $('#prev').css('visibility', 'visible');
                $('#prevOff').css('visibility', 'hidden');
            }
        });
    
	});

    //azione slide indietro
    $("#prev").click(function () {

        if (bn <= 1) {
            $('#prev').css('visibility', 'hidden');
            $('#prevOff').css('visibility', 'visible');
            bn = 0;
        } else {
            bn--;
        }
        $('#banners').animate({
            right: +(bslide * bn),
        }, 'slow', function () {
            // Animation complete.
            if (bn < (myBox - 3)) {
                $('#next').css('visibility', 'visible');
                $('#nextOff').css('visibility', 'hidden');
                bn = 0;
            }
        });
    });


};
