/**
 * Forms Framework Javascript Handling Object
 *	ffEvent' namespace
 */

ff.ffEvent = (function () {
//privates

var that = {
// publics
"BREAK_NEVER" 		: 0,
"BREAK_EQUAL" 		: 1,
"BREAK_NOT_EQUAL" 	: 2,
"BREAK_CALLBACK" 	: 3,
"BREAK_DEFAULT" 	: 0,

"PRIORITY_TOPLEVEL" : 0,
"PRIORITY_HIGH"		: 1,
"PRIORITY_NORMAL" 	: 2,
"PRIORITY_LOW"		: 3,
"PRIORITY_FINAL" 	: 4,
"PRIORITY_DEFAULT" 	: 2,

"factory" : function (params) {
	var instance = {
		"func_name"			: params.func_name || console.log("unnamed event"),
		"break_when"		: params.break_when,
		"break_value"		: params.break_value,
		"additional_data"	: params.additional_data || [],

		"checkBreak" : function (result) {
			switch (that.break_when) {
				case ff.ffEvent.BREAK_CALLBACK:
					return that.break_value.apply(this, result);

				case ff.ffEvent.BREAK_EQUAL:
					if (result === that.break_value)
						return true;
					break;

				case ff.ffEvent.BREAK_NOT_EQUAL:
					if (result !== that.break_value)
						return true;
					break;
			}
			return false;
		}
	};
	return instance;
},

"getLast" : function (results){
	if (results.length > 0)
		return results[results.length];
	else
		return undefined;
}

}; // publics' end

return that;

// code's end.
})();

