jQuery.referenceCompleter = function(input, component, application) {
    
    var $input = $(input);
    
    $input.autocomplete(queryReference, {minChars:1,delay:300,width:230});

    function queryReference(callback) {
        name = $input.attr('name');
        nameArray = name.split('\.');
        SimpleEdpSelectService.selectByReference(
                $input.attr('value'),
                nameArray[nameArray.length - 2],
                name.match('.*rows.*') == null, component, application, callback);
    }
};

jQuery.fn.referenceCompleter = function(component, application) {
    this.each(function() {
        new jQuery.referenceCompleter(this, component, application);
    });
    
    return this;
};

jQuery.directInputCompleter = function(input, component, application) {
    var $input = $(input);
    
    $input.autocomplete(query, {minChars:1,delay:300});

    function query(callback) {
        SimpleEdpSelectService.select($input.attr('value'), component, application, callback);
    }
}

jQuery.fn.directInputCompleter = function(component, application) {
    this.each(function() {
        new jQuery.directInputCompleter(this, component, application);
    });
    
    return this;
};


var ReferenceAutocomplete = {
    init: function(component, application) {
        jQuery('input.rselect').referenceCompleter(component, application);
    }
};

var Autocomplete = {
    init: function(component, application) {
        jQuery('input.scriptDirectInput').directInputCompleter(component, application);
    }
};

var ToolTips = {
    init : function(){
        jQuery('input.rselect').cluetip({
            attribute: 'alt',
            showTitle: false,
            local:false,
            arrows:true,
            dropShadow:true,
            hoverIntent: {    
                  sensitivity:  1,
                  interval:     400
            }
            }),
         jQuery('.referenceLink').cluetip({
            attribute: 'title',
            showTitle: false,
            local:false,
            arrows:true,
            dropShadow:true,
            hoverIntent: {    
                  sensitivity:  1,
                  interval:     400
            }
            })
        }
    };

