window.onload = init;

// Image Replacement by Peter-Paul Koch - quirksmode.org
// http://www.quirksmode.org/dom/fir.html

function init()
{
	var W3CDOM = (document.createElement && document.getElementsByTagName);
	if (!W3CDOM) return;
	var test = new Image();
	var tmp = new Date();
	var suffix = tmp.getTime();
	test.src = 'img/title.gif?'+suffix;
	test.onload = imageReplacement;
}

function imageReplacement()
{
	replaceThem(document.getElementsByTagName('h2'));
}

function replaceThem(x)
{
	var replace = document.createElement('img');
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id)
		{
			var y = replace.cloneNode(true);
			y.src = 'img/title-' + x[i].id + '.gif';
			y.alt = x[i].firstChild.nodeValue;
			x[i].replaceChild(y,x[i].firstChild);
		}
	}
}

// Navigation mouseover subnav

function menuHandle(){
	$('#menu .sel').parent().find('UL').css('display','block');
	$('#menu .sel').attr('id','actual');
	
	$('#menu .main-item').parent().hover(function(){
		$('#menu .sel').removeClass('sel');
		
		if ($(this).find('.main-item').attr('id') != 'actual') {
			$('#actual').parent().find('UL').css('display','none');
		}
		
		$(this).find('.main-item').addClass('sel');
	}, function(){
		if ($(this).find('.main-item').attr('id') != 'actual') {
			$('#actual').parent().find('UL').css('display','block');
			$('#actual').addClass('sel');
			$(this).find('.main-item').removeClass('sel');
		}
	});
}


$(function() {
 	// gestione menu principale (effetto over) 
	menuHandle();

});
