var currentIndex = -1;

$(document).ready(function() {
	$('#navigation > ul > li').each(function(index, element) {
		$(this).hover(
			function() { showNavigationItem(index); },
			function() { hideNavigationItem(index); }
		);
	});

	if ($.browser.msie) {
		var browserVersion = $.browser.version;
		var internetExplorerVersion = browserVersion.substring(0, browserVersion.indexOf('.'));
		if (internetExplorerVersion < 7) {
			$('#navigation > ul > li > a').css({
				'width': '110px',
				'padding': '7px 0 7px 6px'
			});
		}
		if (internetExplorerVersion < 8) {
			$('#navigation > ul > li > ul li').css({'width': '220px' });
			$('#navigation > ul > li > ul a').css({'width': '210px' });
		}
	}
});

function showNavigationItem(parentIndex) {
	currentIndex = parentIndex;

	$('#navigation > ul > li ul').hide();
	$('#navigation > ul > li > a').removeClass('active_over');

	var activeElement = $('#navigation > ul > li:eq('+ parentIndex +')');
	$(activeElement).find('> a').addClass('active_over');

	var list = $(activeElement).find('> ul');
	if ($(list).width() < $(activeElement).width()) {
		$(list).width($(activeElement).width());
	}
	$(list).show();

}

function hideNavigationItem(parentIndex) {
	currentIndex = -1;
	window.setTimeout(function()  {
		if (parentIndex != currentIndex) {
			var activeElement = $('#navigation > ul > li:eq('+ parentIndex +')');
			$(activeElement).find('> a').removeClass('active_over');
			$(activeElement).find('> ul').hide();
		}
	}, 700);
}

function decodeMail(before, after, text) {
	var mailAddress = before +'@'+ after;
	if (text != null) {
		document.write('<a href="mailto:'+ mailAddress +'">'+ text +'</a>');
	}
	else {
		document.write('<a href="mailto:'+ mailAddress +'">'+ mailAddress +'</a>');
	}
}
