var OverlayFix = new Class({
	initialize: function(el)
	{
		this.element = $(el);
		
		if (window.ie)
		{
			this.element.addEvent('trash', this.destroy.bind(this));
			
			this.fix = new Element('iframe', {
				properties: {
					frameborder: '0',
					scrolling: 'no',
					src: 'javascript:false;'
				},
				styles: {
					position: 'absolute',
					border: 'none',
					display: 'none',
					filter: 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)'
				}
			}).injectInside(document.body);
		}
	},

	show: function()
	{
		if(this.fix)
		{
			this.fix.setStyles($extend(
		
			this.element.getCoordinates(), {
				display: '',
				zIndex: (this.element.getStyle('zIndex') || 1) - 1
			}));
		}
		
		return this;
	},

	hide: function()
	{
		if(this.fix)
		{
			this.fix.setStyle('display', 'none');
		}
	
		return this;
	},

	destroy: function()
	{
		this.fix.remove();
	}

});

/**
 * adds hover-function to all given elements
 * by adding and removing the css class 'iehoverconpat'
 */
function ieHoverCompat(selectors)
{
	selectors.each(function(selector)
	{
		$$(selector).each(function(el)
		{
			el.addEvent('mouseover', function()
			{
				this.addClass('iehovercompat');
			});
			
			el.addEvent('mouseout', function()
			{
				this.removeClass('iehovercompat');
			});
		});
	});
}

/**
 * aus irgendeinem Grund funktioniert 'load' hier besser als 'domready'
 * 'domready' ist aber die bessere wahl - also einfach mal probieren
 */
if(window.ie6)
{
	window.addEvent('load', function()
	{
		ieHoverCompat(
			['.Highlightbox', '.teaserbody', '#nav_start', '#nav_lifeguides', '#nav_bildergalerien', '#nav_psychotests',
			'#nav_forum', '#nav_community', '#nav_ich', '#cloud', '.galerieliste_item', '.fragenliste_item',
			'.newuserpicture a', '.alluserpicture a', '.postbox_list a', 'input.ajaxpopup_abschicken']
		);
	});

	window.addEvent('domready', function()
	{
		$$('.subnavi li').each(function(element)
		{
			var ul = element.getElement('ul');

			if($chk(ul))
			{
				element.addEvent('mouseover', function(e)
				{
					this.addClass('iehovercompat');
					var fix = new OverlayFix(this.getElement('ul'));
					fix.show();
				});

				element.addEvent('mouseout', function(e)
				{
					this.removeClass('iehovercompat');
				});
			}
		});
	});
}
