/* Home Page Module Sort */
/**
 * Turns a URL into an argument for links which function
 * purely as event launchers.
 */
String.prototype.getUrlArgument = function() {
	// Parses a URL like "javascript:void(42);" and returns "42"
	if (val = this.match(/[Jj]avascript:void\(\'?(.*?)\'?\);?/i)) {
		if (val[1]) return val[1];
	}
	return this;
}

var ReportImproper = Class.create();
ReportImproper.prototype = {
	//Properties
	el: null,
	parent:null,
	ajax: null,
	ajaxUrl: null,
	
	//Constructor
	initialize: function(el, show) {
		this.el = el;
		this.ajaxUrl = '/path/to/ajax.php';
		this.id = this.el.href.getUrlArgument();
		this.observeLink();
	},
	
	//Methods
	observeLink: function () {
		this.removeFunc = this.addBookmark.bindAsEventListener(this);
		Event.observe(this.el, 'click', this.removeFunc);
	},
	addBookmark: function () {
		this.parent = this.el.parentNode;
		this.parent.innerHTML = 'Flagged as Improper';	
		this.AjaxOut();
		new Effect.Highlight(this.parent);
	},
	AjaxOut: function() {
		var vars = 'module=' + this.id + '&status=' + (this.show ? 'show' : 'hide');
		this.ajax = new Ajax.Request(this.ajaxUrl,
			{
				parameters: vars,
				onSuccess: this.AjaxIn.bind(this)
			}
		);
	},
	AjaxIn : function(req) {
		this.refindLink();
		this.observeHide(); 
	}
};


EventSelectors.register({
	'.report_improper a': function(el) {
		new ReportImproper(el,true);
	}
}, true);

/*var ReportImproper_Rules = {
	'.report_improper a' : function(el){
		new ReportImproper (el, true);
	}
};
Behaviour.register(ReportImproper_Rules);*/