var Ct_AjaxLink = Class.create(Ct_Component_Abstract, {

	_setNamespace: function() {
		this._namespace = 'ctAjaxLink';
	},

	__construct: function() {
		this.element.on('click', '.' + this._namespace + ' .' + this._namespace + '-button',
			this.onAjaxLinkClick.bindAsEventListener(this));
	},

	onAjaxLinkClick: function(event) {
		var button, element, config, request,
			data, href, method;

		Event.stop(event);

		button = Event.findElement(event, '.' + this._namespace +'-button');
		element = button.up('.' + this._namespace);

		config = this._makeConfig(button, true);

		if (config && 'data' in config) {
			data = config.data;
		} else {
			data = {};
		}

		href = button.readAttribute('href');
		method = button.hasClassName('GET') ? 'get' : 'post';

		if (!Object.isString(href)
			|| href == 'javascript:void(0)'
		) {
			href = data.href;
			delete data.href;
		}

		if (Object.isString(href)) {
			request = Ct_Page.getRequest(element.identify(), 'ajax');
			request.url = href;
			request.options.method = method;
			request.options.parameters = data;
			request.send();
		}
	},

	refresh: function(ident, response) {
		var element = $(ident);

		if (!Object.isElement(element)) {
			return;
		}

		if (response.html && response.html.length) {
			element.update(response.html);
		}
	}

});

Ct_Page.registerScript("Ct_AjaxLink");
