Yourchance.namespace('Yourchance.Tags');

Yourchance.Tags.Button = Class.create({
	
	domElement: null,
	
	tagControl: null,
	
	disabled: false,
	
	initialize: function(element, config) {
		this.domElement = $(element);
		this.disabled = config.disabled || false;
		this.domElement.tagControl = this;

		if(config.alert == true) {
			this.domElement.observe('click', function (event) {
				event.stop();
				if ((typeof lib.Overlay.showAlert) == 'function') {
					lib.Overlay.showAlert($$("input[name='buttonMessage["+event.target.id+"]']").first().value);
				} else {
					alert($$("input[name='buttonMessage["+event.target.id+"]']").first().value);
				}
			});
		}
	},
	
	enable: function() {
		this.setDisabled(false);
	},
	
	disable: function() {
		this.setDisabled(true);
	},
	
	setDisabled: function (value) {
		if (this.disabled == value) return;
		
		this.domElement.className = this.domElement.className.replace(/(button(-\w+)+(-inactive)?)$/, function() {
			if (arguments[2] == "-inactive") {
				this.disabled = false;
				return arguments[1].replace("-inactive", "");
			} else {
				this.disabled = true;
				return arguments[1] + "-inactive";
			}
		}.bind(this));
	}
});