var menu_aperto = '';

function initLinkContenuti(pmClass) {

	$("."+pmClass).each(function (element) {
		if ($(this).attr('link')) {
			$("."+pmClass).bind("click",
				function(event) {
					location.href = $(this).attr('link');
				}
			);
		};
	});
}

function initMenu(leaveOpen) {
	$(".menu_sezione").each(function (element) {
		if ($('#voci_'+this.id).hasClass(leaveOpen.toLowerCase())){
			if (leaveOpen.toLowerCase()=='cul'){
				$('#culturali>span').show();$('#culturali').css('height','36px');
			}
			if (leaveOpen.toLowerCase()=='inf'){
				$('#tecnologie>span').show();$('#tecnologie').css('height','36px');
			}
			if (leaveOpen.toLowerCase()=='prb'){
				$('#problem>span').show();$('#problem').css('height','36px');
			}
		}
		else $('#voci_'+this.id).css('display', 'none');
	});
	$(".menu_sezione").bind("click",
		function(event) {
			if (menu_aperto != '') {
				$(menu_aperto).slideToggle('normal',
					function() {
					}
				);
			}
			if (menu_aperto != '#voci_'+event.target.id) {
			menu_aperto = '#voci_'+event.target.id;
				$(menu_aperto).slideToggle('normal',
					function() {

					}
				);
				if (leaveOpen.toLowerCase()!='prb'){
					$('#problem>span').hide(); $('#problem').css('height','8px');
				}
				if (leaveOpen.toLowerCase()!='inf'){
					$('#tecnologie>span').hide(); $('#tecnologie').css('height','8px');
				}
				if (leaveOpen.toLowerCase()!='cul'){
					$('#culturali>span').hide(); $('#culturali').css('height','8px');
				}
				if (event.target.id=='problem' || event.target.id=='tecnologie' || event.target.id=='culturali'){
					$('#'+event.target.id+'>span').show();$('#'+event.target.id+'').css('height','36px');
				}
			} else {
				menu_aperto = '';
					//$('#problem>span').hide();$('#problem').css('height','8px');
					//$('#tecnologie>span').hide();$('#tecnologie').css('height','8px');
			}
		}
	);

	//initLinkContenuti("link_sottomenu");
	initLinkContenuti("menu_top");

}


function caricaContenuto(pmContainer, pmURL) {


	var tmp = pmURL.split('?',2 );

	var oldContent = $("#"+pmContainer).html();
	$.ajax({
		type: "POST",
		url: tmp[0],
		data: tmp[1],
		async: true,
		success: function(content) {
			$("#"+pmContainer).html(content);
			return true;
		},
		error: function () {
			$("#"+pmContainer).html(oldContent);
		}
	});
}