$(document).ready(function(){

    var deg=0;
    var dif=-1;

    /* Assigning the buttons to a variable for speed: */
    var arr = $('.btn2');
	
    /* Storing the length of the array in a variable: */
    var len = arr.length;
	
    /* Finding the centers of the animation container: */
    var centerX = $('#stage2').width()/2 - 85;
    var centerY = $('#stage2').height()/2 - 60;

    /* Applying relative positioning to the buttons: */
    arr.css('position','absolute');
	
    /* The function inside the interval is run 25 times a second */
    setInterval(function(){
	
        /* This forms an area with no activity in the middle of the stage */
        if(Math.abs(dif)<0.5) return false;
	
        /* Increment the degrees: */
        deg+=dif;
	
        /* Loop through all the buttons: */
        $.each(arr,function(i){
		
            /* Calcoliamo il seno ed il coseno */
            var eSin = Math.sin(((360/len)*i+deg)*Math.PI/180);
            var eCos = Math.cos(((360/len)*i+deg)*Math.PI/180);
		
            /* distanza orizzontale e verticale degli elementi */
            $(this).css({
                top:centerY+25*eSin,
                left:centerX+150*eCos,
                opacity:0.8+eSin*0.7, //la moltiplicazione di eSin rende maggiore o minore la trasparenza delle foto posteriori
                zIndex:Math.round(80+eSin*20)
            });

        })
	
    },40);
	
    /* Gesture del mouse e velocit� incrementale associata */
	
    var over=false;
    $("#stage2").mousemove(function(e){

        if(!this.leftOffset)
        {
            /* Questa funzione viene eseguita solo alla prima esecuzione dello script */
            this.leftOffset = $(this).offset().left;
            this.width = $(this).width();
        }
	
        /* Se il mouse passa sopra un'immagine, la velocit� di rotazione diventa zero */
        if(over) dif=0;
        else
            dif = -5+(10*((e.pageX-this.leftOffset)/this.width));
		
    /* Se il mouse non � sulle immagini, calcolo la velocit� in base al posizionament odel mouse stesso */
    });
	

    /* Detecting whether the mouse is positioned above a share button: */
    $(".bcontent2").hover(
        function(){
            over=true;
            dif=0;
        },
        function(){
            over=false;
        }
        );
});