var circleMove = {
        Degrees: 0,
        Radius: 100,
        Rads: 0,
        timeId: 0,
        
        init: function(elementId, theCenterPointX, theCenterPointY, delayTime) {
                //first, check to see if the element exists:
                var theElement = null;
                if (!document.getElementById(elementId)) {
                        //if not, create it and give it some properties
                        theElement = document.createElement("div");
                        theElement.id = elementId;
                        theElement.style.height = "1em";
                        theElement.style.width = "1em";
                        theElement.style.border = "1px solid red";
                        document.body.appendChild(theElement);
                } else {
                        theElement = document.getElementById(elementId);
                }
                //removes the looping on the element if it's already been set:
                clearInterval(circleMove.timeID);
                
                //starts the repetition.
                circleMove.timeID = setInterval( function() {
                        circleMove.circleElement(theElement, theCenterPointX, theCenterPointY, delayTime);
                }, delayTime);
                
                
        
        },
        
        convertDegreesToRadians: function(degrees) {
        var pi = Math.PI;
        var radians = (degrees * (pi/180));
        return radians;

        },

        circleElement: function(element, theCenterPointX, theCenterPointY, delayTime) {
                var newCoordinates = circleMove.calculateCoordinates(theCenterPointX, theCenterPointY);
                circleMove.moveElement(element, newCoordinates[0], newCoordinates[1]);
        },
        
        calculateCoordinates: function(theCenterPointX, theCenterPointY) {
                //if the degree variable is greater than 360, reset it
                if (circleMove.Degrees > 360) {
                        circleMove.Degrees = 1;
                
                }
                //increment the degree variable, then get the radians, and then calculate the coordinates
                circleMove.Degrees = circleMove.Degrees + 1;
                circleMove.Rads = circleMove.convertDegreesToRadians(circleMove.Degrees);
                
                var newLocX = (theCenterPointX - (circleMove.Radius * Math.cos(circleMove.Rads)) );
                var newLocY = (theCenterPointY - (circleMove.Radius * Math.sin(circleMove.Rads)) );
                //return the coordinates as a two-value array
                return [newLocX, newLocY];
        
        },
        
        moveElement: function(element, newLocX, newLocY) {
        //sets the top and left of the element style, thus moving it to its new location.
                element.style.position = "absolute";
                element.style.top = newLocX + "px";
                element.style.left = newLocY + "px";
        },
        
        initStart: function() {
                function callInit(e) {
                        var y = 300;
                        if (window.pageYOffset && parseInt(window.pageYOffset) != 0) {
                                y = window.pageYOffset;
                        }
                        circleMove.init("theMovingElement", y+200, 300, 10);
                }
                circleMove.addEvent(document.getElementById("theButton"), "click", callInit);
        
        },
        
        addEvent: function( obj, type, fn ) {
        //John Resig's function for adding event handlers to objects.
                if ( obj.attachEvent ) {
                        obj['e'+type+fn] = fn;
                        obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
                        obj.attachEvent( 'on'+type, obj[type+fn] );
                } else {
                obj.addEventListener( type, fn, false );
                }
        },
        
}
circleMove.addEvent(window, "load", circleMove.initStart);
