/**
 * aheadWorks Co.
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the EULA
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://ecommerce.aheadworks.com/LICENSE-M1.txt
 *
 * @category   AW
 * @package    AW_Seacrhautocomplete
 * @copyright  Copyright (c) 2003-2010 aheadWorks Co. (http://www.aheadworks.com)
 * @license    http://ecommerce.aheadworks.com/LICENSE-M1.txt
 */

var Searchcomplete = Class.create();
Searchcomplete.prototype = {
    field: "",
    initialize : function(){
        this.field = $('myInput');
    },
    initAutocomplete : function(url, destinationElement){
        var SACautocompleter = new Ajax.Autocompleter(
            this.field,
            destinationElement,
            url,
            {
                paramName: this.field.name,
                method: 'get',
                minChars: 3,
                frequency: queryDelay,
                onShow : function(element, update) {
//                    var posSC = $('myInput').cumulativeOffset();
//                    posSC.top = posSC.top + parseInt($('myInput').getHeight()) + 3;
//                    if (!Prototype.Browser.IE)
//                        posSC.left -= (parseInt($('myInput').getStyle('padding-left')) + 3);

                    //$('myContainer').setStyle({
                    //    top: posSC.top+"px",
                    //    left: posSC.left+"px"
                    //});

                    update.show();
                    $('myContainer').show();
                    $('myContainer').setStyle({left: '-1px'});

                },
                onHide : function(element, update)
                {
                    $('myContainer').hide();
                    $('myContainer').setStyle({left: '-9999px'});

                    update.hide();

                },
                updateElement : function(element)
                {
                    return false;
                }
            }
        );
        SACautocompleter.onHover = function(event) {
            var element = Event.findElement(event, 'DIV');
            if(this.index != element.autocompleteIndex)
            {
                this.index = element.autocompleteIndex;
                this.render();
            }
            Event.stop(event);
        };
        SACautocompleter.startIndicator = function(){
            this.element.setStyle({
                backgroundImage: 'url("'+preloaderImage+'")',
                backgroundRepeat: 'no-repeat',
                backgroundPosition: 'right'
            });
        };
        SACautocompleter.stopIndicator = function(){
            this.element.style.backgroundImage = 'none';
        }
    }
};

