/**
------------
MagicButtons.js
------------
	Written by: Greg Militello <gmilitello@dyrectmedia.com>
				thinkof.net

------------
License information (BSD lisence based):
------------
		Copyright (c) 2006, Greg Militello
		All rights reserved.

		Redistribution and use in source and binary forms, with or without modification, 
		are permitted provided that the following conditions are met:

		    * Redistributions of source code must retain the above copyright notice, 
				this list of conditions and the following disclaimer.
		    * Redistributions in binary form must reproduce the above copyright notice, 
				this list of conditions and the following disclaimer in the 
				documentation and/or other materials provided with the distribution.
		    * Neither the name of the thinkof.net nor the names of its contributors 
				may be used to endorse or promote products derived from this software 
				without specific prior written permission.

		THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
		ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
		WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
		IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
		INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
		BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
		OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
		WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
		ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
		POSSIBILITY OF SUCH DAMAGE.
*/
var MagicButtons = {}

MagicButtons.Base = function() {};
MagicButtons.Base.prototype = {
	//
	// PUBLIC METHOD Base.getVersion()
	// Returns the version of this object
	getVersion: function () {
		return ('v0.0.3');
		// CHANGE LOG
		//    v0.0.1 - Proof of concept (procedural)
		//    v0.0.2 - Making the code into an object
		//    v0.0.3 - The inner wrap object now has a customizable nodeName now
	},
	//
	// PRIVATE METHOD Base.setOptions()
	// Parse options into usable values
	setOptions: function(options) {
		this.options = Object.extend({
		}, options || {});
	},
	//
	// PRIVATE METHOD Base.start()
	// Actions to kickoff to once this has started
	start: function(options) {
		this.setOptions(options || {});
	},
	//
	// METHOD Base.wrapNode()
	// Wrap a node with a new node
	wrapNode: function (newEl, oldEl) {
		var parent = oldEl.parentNode;
		var newElPlaced = parent.insertBefore (newEl, oldEl);
		newEl.appendChild(this.element);
		return newElPlaced;
	}
};
//
// OBJECT MagicButtons.anchor
MagicButtons.anchor = Class.create();
MagicButtons.anchor.prototype = Object.extend(new MagicButtons.Base(), {
	//
	// PRIVATE METHOD anchor.initialize()
	// Class setup
	initialize: function(element) {
		this.element = element;
		var options = Object.extend({
			replaceClass: 'makeButton',
			buttonClass: 'button',
			wrapperClass: 'buttonWrap',
			wrapperNodeName: 'div',
			innerWrapperNodeName: 'span'
		}, arguments[1] || {});
		this.start(options);
		this.render();
	},
	//
	// PRIVATE METHOD anchor.render()
	// Do the work
	render: function() {
		Element.addClassName (this.element, this.options.buttonClass);
		Element.removeClassName (this.element, this.options.replaceClass);
		Element.update(this.element, '<'+this.options.innerWrapperNodeName+'>'+this.element.innerHTML+'</'+this.options.innerWrapperNodeName+'>');
		var newEl = document.createElement (this.options.wrapperNodeName);
		Element.addClassName (newEl, this.options.wrapperClass);
		this.wrapNode (newEl, this.element);
	}
});