function fixPng()
{
	document.getElementsByClassName('png').each( function (el) {
		
		if (el.tagName == 'IMG' && /\.png$/i.test(el.src))
		{
			el.setStyle({
				filter : 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + el.src + '", sizingMethod = "image")'
			});
			el.src = "/resources/images/blank.gif";
		}
		else if (el.getStyle('background-image').match(/^url([("'])+(.*\.png)$1$/i))
		{
			el.setStyle({
				backgroundImage : 'none',
				filter          : 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + RegExp.$2 + ', sizingMethod=crop)'
			});
		}
	});
}

function closeAll()
{ 
	$('menu').getElementsByClassName('top').each( function (el) {
		el.setInactive();
		sub = el.next('div');
		sub && sub.hasClassName('sub') && sub.hide();
	} );
}

Event.observe(window, 'load', function () {

	$('main').show();
	$('gradient').show();
	$('preloader-container').remove();
	
	new Effect.Opacity('main', { from : 0, to : 1, duration : 0.5 });
	
	var _currentPath = window.location.pathname.replace(/^\/(?:[a-z]{2}\/)?/, "");
	
	var currentPath = new RegExp("/([a-z]{2}/)?" + _currentPath + "/?$");
	
	document.getElementsByClassName('top').each( function (el) {
		
		sub = el.next('div');
		
		if (el.down('a').href.match(currentPath))
		{
			style = Prototype.Browser.IE 
					? {	backgroundImage : "none", filter : "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=/resources/images/active.png,sizingMethod=crop)" }
					: { backgroundImage : "url(/resources/images/active.png)" };
			
			el.setStyle(style);
			sub && sub.show();
		}
		else
		{
			var found = false;
			if (sub && sub.hasClassName('sub'))
			{
				sub.immediateDescendants().each( function (subel) {
					if (subel.down('a').href.match(currentPath))
					{
						subel.setStyle({fontWeight : 'bold'});
						style = Prototype.Browser.IE 
								? {	backgroundImage : "none", filter : "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=/resources/images/active.png,sizingMethod=crop)" }
								: { backgroundImage : "url(/resources/images/active.png)" };
						
						el.setStyle(style);
						found = true;
						throw $break;
					}
				});
				!found && sub.hide();
			}	
		}
	});
});
