var MooCenter = new Class({
  Implements: [Options],

  options: {
    main_element: '', // This is the element we're going to be centering.
		parent_element: document.body // This is the element we're going to be centering our main element to. By default it's the main document's body.
  },
  
  initialize: function(main_el,options) {
		// Main element passed in from class call and any other options passed in get applied to the global options
		this.options.main_element = main_el;
    this.setOptions(options);

		// Lets Begin The Magic - This function will add all our window events and begin the positioning
		this.addEventsStart();
  },


	// This function will perform the positioning of the main element
  centerElement: function() {
		if(this.options.parent_element != document.body){ // Check to See If We're Positioning To The Default Parent Element Or A Custom One

			this.options.main_element.setStyle('position','absolute'); // If we're positioning within an element that isn't the default parent element, we can pretty much be sure that we want the positioning to be absolute rather than fixed
		}else{
			this.options.main_element.setStyle('position','absolute');
		}

		var scroll = $(document.body).getScroll();
		// Lets get our calculated values that we'll apply to our main_element
		var left = (this.options.parent_element.getSize().x / 2) - (this.options.main_element.getSize().x / 2) + scroll.x;

		
		// And apply them!
		this.options.main_element.setStyle('left', left);

  },
  
  addEventsStart: function(){
		// I'm not a Javascript King, so I've created the "main" variable to hold 'this'. I couldn't seem to use 'this' within the window.addEvent methods.
		var main = this;
		main.centerElement(); // Initial Positioning
		
		// Reposition on Resize
		window.addEvent('resize',function(){
			main.centerElement();
		});
		
		// Reposition on Scroll
		window.addEvent('scroll',function(){
			main.centerElement();
		});
  }
});

var my_centered_box = new MooCenter($('headerlogo'))
var my_centered_box2 = new MooCenter($('mainnav'))

