// Привязка функций к определенным событиям элементов
//
//

var fastenFunctions = Class.create();
fastenFunctions.prototype = {

    initialize: function(params) {
        // значения по умолчанию
        this.elementsClass = false; // класс по которому определяются элементы

        Object.extend(this, params);
        this.elements = document.getElementsByClassName(this.elementsClass);
        var that = this;
        this.elements.each(function(element){
            var params = '';
            var el = element.next('input');
                if (el && el.tagName && el.type && el.value)
                    if ((el.tagName.toUpperCase() == 'INPUT') && (el.type.toUpperCase() == 'HIDDEN'))
                        params = el.value;
            if (that.events.each)
                that.events.each(function(e){
                    Event.observe(element, e, that.execFunction.bindAsEventListener(that, element, params));
                });
            else
                Event.observe(element, that.events, that.execFunction.bindAsEventListener(that, element, params));
        });
    },

    execFunction: function(e, element, params) {
        if (params) {
            params = new String(params);
            params = params.evalJSON();
        }
        if (this.func.each)
            this.func.each(function(func){
                eval(func);
            });
        else
            eval(this.func);
    }
};