$(document).ready(function(){
   
//Setup variables
var element = $('#div_cloud a'); // all the list elements
var offset = 0;             // angle offset for animation
var stepping = 0.01;        // how fast the list rotates
var list = $('#div_cloud');      // the list wrapper
var $list = $(list);

/* Handles mouse movement, the closer to the center
the faster the list will rotate */
$list.mousemove(function(e){
    var topOfList = $list.eq(0).offset().top
    var listHeight = $list.height()
   	/*trace(e.clientY);
   	return;*/
   
    // Sets variable that controls the speed of rotation.
    stepping = ((e.clientY + document.body.scrollTop + document.documentElement.scrollTop) - topOfList) /  listHeight * 0.2 - 0.1;
   
});
$list.mouseleave(function(e){
    stepping = (stepping > 0 ? 0.01 : -0.01);
});


/* Disperse elements evenly around the circle */
for (var i = element.length - 1; i >= 0; i--)
{
    element[i].elemAngle = i * Math.PI * 2 / element.length;
}

// call render function over and over
setInterval(render, 20);


// Handles how and where each element will be rendered.
function render(){
   
    //Steps through each element...
    for (var i = element.length - 1; i >= 0; i--){
       
        // offset adds degrees to where the element
        // is currently on the circle
        var angle = element[i].elemAngle + offset;
       
        // Trig to figure out the size and where the
        // text should go
        x = 120 + Math.sin(angle) * 30;
        y = 45 + Math.cos(angle) * 40;
        size = Math.round(5 - Math.sin(angle) * 5);
       
        // Centers the text, instead of being left aligned.
        var elementCenter = $(element[i]).width() / 2;
       
        // Figure out the x value of the element.
        var leftValue = (($list.width()/2) * x / 100 - elementCenter) + "px"
       
       
        // Apply the values to the text
        $(element[i]).css("fontSize", size + "pt");
        $(element[i]).css("opacity",size/25);
        $(element[i]).css("zIndex" ,size);
        $(element[i]).css("left" ,leftValue);
        $(element[i]).css("top", y + "%");
    }
   
    // Rotate the circle
    offset += stepping;
}
   
   
});
