/*

	Triggers

		This is for extending classes you make, with the fancy onclick triggers.

	Dependencies:
		MooTools 1.2.* core

	Usage:

		Make your class implement this one.

		When creating your class, create a hash of triggers. The key is the class
		of the thing that gets clicked, and the value is the function that gets run.

		Add a click event to the entire document (or iframe), with the figureTrigger function,
		like in the example below.

		Make sure there are functions for the things you run.

	Example:

		var myNewClass = new Class({

			Implements: [Triggers],

			options: {
				triggers: new Hash({
					mylinkclassone:        function(el, that) { that.doLinkClickOne(el); },
					mylinkclasstwo:        function(el, that) { that.doLinkClickTwo(el); },
					mylinkclassthree:      function(el, that) { that.doLinkClickThree(el); }
				})
			},

			initialize: function(){
				document.addEvent('click', this.figureTrigger.bindWithEvent(this, [this.options.triggers]));
			},

			doLinkClickOne: function(el) {
				alert('Link one was clicked');
			},

			doLinkClickTwo: function(el) {
				alert('Link two was clicked');
			},

			doLinkClickThree: function(el) {
				alert('Link three was clicked');
			}

		});

*/


var Triggers = new Class({

	figureTrigger: function(e, triggers){
		var target = $(e.target);
		var target_tag = target.get('tag');
		while((target_tag != 'a') && (target_tag != 'input') && (target_tag != 'html')){
			target = target.getParent();
			if (!target) return;
			target_tag = target.get('tag');
		}
		triggers.each( function(value, key) {
			if (target.hasClass(key)) {
				e.stop();
				value(target, this);
			}
		}, this);
	}

});


