

var Rotation = new Class(
{
    Implements: [Options,Events],
    options:
    {
        axis        : null, 
        magnatude   : 250,
        effect      : false,
        angle       : -90,
        autoAdjust  : true
    },
    
    initialize: function(satellites,options)
    {
        this.setOptions(options);
        this.setAxis($$(satellites));
        this.setSatellites($$(satellites));
        
        return true;
    },
    
    setAxis: function( sats )
    {
        if (this.options.axis == null)
        {
            this.options.axis = sats[0].getParent();
        }
        
        var coor = this.options.axis.getCoordinates();        
        this.axis = {top: (coor.top + coor.height/2),left: (coor.left + coor.width/2)};
    },
    
    setSatellites: function(els)
    {
        var inc = 360/els.length;
        var o   = {};
        var ang = this.options.angle;
        
        els.each(function(el,i)
        {
            var w = this.options.axis.getSize();
            var s = el.getSize();
            
            var m = ((this.options.magnatude * 2 + s.y) > w.y && this.options.autoAdjust) ? w.y / 2 - s.y / 2 - 3 : this.options.magnatude;
           
            var x = (m * Math.cos(ang * Math.PI/180));
            var y = (m * Math.sin(ang * Math.PI/180));
            
            o[i] = {element: el, position: {top: y, left: x}, angle: ang};
            ang += inc;
        },this);
        
        this.satellites = o;
    },
    
    start: function()
    {
        var o = {};
        for (var i in this.satellites)
        {
            var coor = this.options.axis.getSize();
            var x = this.satellites[i].position.left + ( coor.x/ 2 ) - ( this.satellites[i].element.getSize().x / 2 );
            var y = this.satellites[i].position.top + ( coor.y / 2 ) - ( this.satellites[i].element.getSize().y / 2 );
            
            o[i] = {left: x,top: y};
            
            if (!this.options.effect)
            {
                this.satellites[i].element.setStyles(o[i]);
            }
        }
        
        if (this.options.effect)
        {
            this.options.effect.run(o);
        }
    }
});

