window.addEvent('domready',function()
{
	init_menu();
});

function init_menu()
{	
	$$('#nav ul li').each(function(element)
	{
		element.addEvent('mouseover', function(evt)
		{
			element.addClass('sfhover');
		});
	 
		element.addEvent('mouseout', function(evt)
		{
			element.removeClass('sfhover');
		});	 
	});
}

window.addEvent('domready',function()
{
	var blocks			= $$('#mid .block');
	var prev_product	= null;
			
	blocks.each(function(block)
	{
		if(block.hasClass('productcategory'))
		{
			prev_product		= block;
		}else if(prev_product)
		{
			var clear			= new Element('div',{'class':'block',"style":"clear:both;"});
			clear.set('html',"<div class='end'></div>");
			clear.injectBefore(block);	
			prev_product		= false;
		}
	});
	
	var main_blocks		= $$('#main_content .block');
	try {
		main_blocks[main_blocks.length-1].getElement('.end').setStyle("background-image","none");
	}catch(e){}
	
	var menuitems		= $$('#nav A');
	menuitems.each(function(item)
	{
		item.removeAttribute("title");
	});
	
	// language chooser slideshow:
	
	var slideshow = new Slideshow('language_select', 4000, 1000);
});

/**
 * Create a slideshow using the subelements of the passed element
 */ 

var Slideshow = new Class(
{
	initialize: function (element, timeout, speed)
	{
		this.element = $(element);
		this.elements = $$('.' + 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;
			this.elements[this.current - 1].fade(0,1);
		}
		else
		{
			// Set previous invisible
			if (this.current > 1)
			{
				this.elements[this.current - 2].setStyle('opacity', '1');
			}
			this.elements[this.current - 1].fade(1,0);
			this.current--;
		}	
		this.trigger.delay(this.timeout, this);
	}
});
