/*
	Copywright March 2010 - Bruno Torrinha (www.torrinha.com)
	script:		comm.js
*/


var Site = {
	initialize: function(){
		if (!window.ie) {
			$$('#menuBar li a').each(function(el){ Site.setLinkFx(el, '#000', '#C33'); });
			$$('#ftr a').each(function(el){ Site.setLinkFx(el, '#444', '#C33'); });
		}

		if (!window.ie6) {
			Autocompleter = Class.refactor(Autocompleter, {
				choiceSelect: function(choice) {
					this.previous(); //--- !!!!
					$('tagID').set('value', 1);
					$('frmSearch').submit();
				}
			});

			new Autocompleter.Local('search_field', tokens, {
				'autoSubmit': false,
				'minLength': 1,
				'selectMode': 'type-ahead',
				'relative': true,
				'filter': function() {
					var regex = new RegExp('^' + (this.queryValue || '').escapeRegExp(), 'i');
					return this.tokens.filter(function(token){
						return (regex.test(token[0]) || regex.test(token[1]) || regex.test(token[2]));
					});
				},

				'injectChoice': function(token) {
					var choice = new Element('li')
						.set('html', this.markQueryValue(token[1]))
						.adopt(new Element('span', {'class': 'example-info'}).set('html', this.markQueryValue(token[2])));
					choice.inputValue = token[1];
					this.addChoiceEvents(choice).inject(this.choices);
				}
			});
		}

	},
	
	setLinkFx: function(elLink, colorDef, colorHov){
		var fx = new Fx.Tween(elLink, {duration: 150, link: 'cancel'}).set('background-color', colorDef);
		elLink.addEvents({
			'mouseenter': function() {fx.start('background-color', colorHov);},
			'mouseleave': function() {fx.start('background-color', colorDef);}
		});
	},
	
	setFluidColumn: function() {
		var el = $('ftrCl_Large');
		if (window.getHeight() <= 700) {el.setStyle('height', 242);} else {el.setStyle('height', 290);}
	}
};
window.addEvent('domready', Site.initialize);
