

jQuery.fn.animrotation = function(options){

    var options = jQuery.extend({
      frame:'body',
      delay: 4,
      nsteps: 1500,
      ElementWidth: 250,
      width:600,
      height:200,
      zindex:100
    },options);

    var nelems=this.length;
    var robjects=this;

    var ellipseX=new Array();
    var ellipseY=new Array();
    var zindex=new Array();

    var x0=parseInt(options.width)/2-parseInt(options.ElementWidth)/2;
    var y0=parseInt(options.height)/2;
    var Sstep=Math.round(options.nsteps/nelems);
    var angle=2*3.14159265358979323846/options.nsteps;

    var step=0;
    var limitsteps=options.nsteps-1;
    var a=(parseInt(options.width)-parseInt(options.ElementWidth))/2;
    var b=parseInt(options.height)/2;
    var step4=options.nsteps/4;
    var tmp_y;
    var Yzindex=Math.round(parseInt(options.height)/nelems);
    for(;step<options.nsteps;step++)
    {
        ellipseX[step]=Math.round(a*Math.cos(angle*(step-step4))+x0);
        tmp_y=b*Math.sin(angle*(step-step4));
        ellipseY[step]=Math.round(y0-tmp_y);
        zindex[step]=options.zindex+Math.ceil((2*b-tmp_y)/Yzindex);
    }

    $(options.frame).append("<div id='AnimRotationLeft'></div>\n\
        <div id='AnimRotationRight'></div>");
    var intervalID =0;
    jQuery('#AnimRotationLeft').css({
                    position:   'absolute',
                    top:	0,
                    left:	-200,
                    width: Math.round($(options.frame).width()*0.7),
                    height: $(options.frame).height(),
                    'z-index':1

                });

    jQuery('#AnimRotationRight').css({
                    position:   'absolute',
                    top:	0,
                    right:	-200,
                    width: Math.round($(options.frame).width()*0.7),
                    height: $(options.frame).height(),
                    'z-index':1

                });

    jQuery('#AnimRotationRight').bind('mouseenter', function() {

        intervalID = self.setInterval(
            function ()
            {
                robjects.each(function() {
                    this.step++;
                    if(this.step>limitsteps)
                        this.step=0;
                    jQuery(this).css({
                                    top:	ellipseY[this.step],
                                    left:	ellipseX[this.step],
                                    'z-index': zindex[this.step]
                                });

                });
            }, options.delay)
    }).bind('mouseleave', function() {
        clearInterval(intervalID);
    });

    jQuery('#AnimRotationLeft').bind('mouseenter', function() {

        intervalID = self.setInterval(
            function ()
            {
                robjects.each(function() {
                    this.step--;
                    if(this.step<0)
                        this.step=limitsteps;
                    jQuery(this).css({
                                    top:	ellipseY[this.step],
                                    left:	ellipseX[this.step],
                                    'z-index': zindex[this.step]

                                });

                });
            }, options.delay)
    }).bind('mouseleave', function() {
        clearInterval(intervalID);
    });

    step=0;
    return this.each(function() {
        this.step=step;
        step+=Sstep;

      jQuery(this).css({
                            position:   'absolute',
                            top:	ellipseY[this.step],
                            left:	ellipseX[this.step],
                            'z-index': zindex[this.step]

			});

    });
 
};