/**
 * Autocompleter.Local
 *
 * http://digitarald.de/project/autocompleter/
 *
 * @version		1.1.2
 *
 * @license		MIT-style license
 * @author		Harald Kirschner <mail [at] digitarald.de>
 * @copyright	Author
 */

Autocompleter.Local = new Class({

	Extends: Autocompleter,

	options: {
		minLength: 0,
		delay: 200
	},

	initialize: function(element, tokens, options) {
		this.parent(element, options);
		this.tokens = tokens;
	},

	query: function() {
		this.update(this.filter());
	}

});


/*=====================================================================
						LOCAL SETTINGS & FUNCTIONS
  =====================================================================*/
document.addEvent('domready', function()
{
	titleList = new Array();
	
	// 1. pripravimo funkcijo
	new Autocompleter.Local('searchKey', titleList,
	{
		'minLength': 1,
		'overflow': true,
		'selectMode': 'type-ahead'
	});
	
	// 2. funkcija za branje arraya
	var requestArray = new Request.HTML(
	{
		url:'/ajax/autocompleter.php', 
		onSuccess: function(html)
		{
			// vstavimo vsebino obvestila
			$('searchKey').adopt(html);
		}
	});
	
	// 3. nafilamo array, ko klikne v polje
	$('searchKey').addEvent('focus', function(e)
	{
		if (titleList.length == 0)
		{
			requestArray.get();
		}
	});
});
