function init_behaviors() {
	init_menu();
	init_image_slideshow();
	init_language_slideshow();
	init_search_form();
}

function init_search_form() {
	if ($('searchfor')) {
		$('searchfor').addEvent('keypress', function(evt) {
			var evt = new Event(evt);
			if (evt.key == 'enter') {
				evt.target.form.submit();
			}
			
		});
		$('searchfor').addEvent('click', function(evt) {
			var evt = new Event(evt);
			if (evt.target.value == 'search') {
				evt.target.value = '';
			}
		});
	}
}


function init_menu() {
	
	$$('#nav ul li.sub').each(function(element)
	{
		element.addEvent('mouseover', function(evt) {
			element.addClass('sfhover');
			//var slider = new Fx.Slide($E('ul', element));
			//slider.slideIn();
		});
	 
		element.addEvent('mouseout', function(evt) {
			element.removeClass('sfhover');
			//var slider = new Fx.Slide($E('ul', element));
		}); 
	 
	});
}

function init_language_slideshow(element) {
	// Fetch image count
	var slideshow = new Slideshow('language_select_holder', 5000, 1000);
}

function init_image_slideshow(element) {
	// Fetch image count
	var slideshow = new Slideshow('header', 4000);
}

/**
 * Create a slideshow using the subelements of the passed element
 */
var Slideshow = new Class({
	initialize: function (element, timeout, speed) {
		this.element = $(element);
		this.elements = $ES('div', element);
		this.count = this.current = this.elements.length;
		this.timeout = timeout;
		this.trigger.delay(this.timeout, this);
		if (speed)
		{
			this.speed = speed;
		}
		else
		{
			this.speed = this.timeout / 2;
		}
	},
	trigger: function() {
		if (this.current == 1) {
			this.current = this.count;
			var fx = new Fx.Styles(this.elements[this.current - 1], {duration: this.speed, wait:true});
			fx.start({
				'opacity':'1'
			});
		} else {
			// Set previous invisible
			if (this.current > 1)
			{
				this.elements[this.current - 2].setStyle('opacity', '1');
			}
			var fx = new Fx.Styles(this.elements[this.current - 1], {duration: this.speed, wait:true});
			fx.start({
				'opacity':'0'
			});	
			this.current--;
		}	
		this.trigger.delay(this.timeout, this);
	}
});

