function smart_resize() {
	viewport_width = document.documentElement.clientWidth;

	body_width = 764;
	MIN_WIDTH = 700;
	MAX_WIDTH = 1200;


	if (viewport_width >=MIN_WIDTH && viewport_width <= MAX_WIDTH) {
		body_width = viewport_width - 100;
	}
	else if (viewport_width <MIN_WIDTH) {
		body_width = viewport_width - 10;
	}
	else if (viewport_width > MAX_WIDTH) {
		body_width = MAX_WIDTH - 100;
	}


// Allargo il body
        //$('body').css('width', body_width);
        //alert($("body[class!='centro_2']").size());
        //alert ( document.body.className);
        $('body[class!=centro_2]').css('width', body_width);

	

// Allargo le sezioni Ateneo, Ricerca, Didattica
	margin_sezioni = parseInt($('#sezioni').css('margin-left'));
	if (isNaN(margin_sezioni)) {
		margin_sezioni = 12;
	}

	sezioni_width = (body_width - margin_sezioni * 2) / 5;

	$('#sezioni li').css('width', sezioni_width);


	ricerca_width = sezioni_width * 3 - parseInt($('#ricerca').css('padding-left')) - parseInt($('#ricerca').css('padding-right'));

	$('#utenti').css('width', sezioni_width * 3 - 2);
	$('.home #utenti').css({'width': sezioni_width * 2 - 2, 'left':sezioni_width * 3 +2});


// Aumentare l'altezza
	$('.home #utenti li').css({'height': sezioni_width / 6, 'font-size':sezioni_width / 13});



	$('.green #ricerca').css('width', ricerca_width);

	$('.home .green #ricerca').css('width', ricerca_width - sezioni_width);

	$('#foto-home-sezione').css('width', sezioni_width * 3);
	$('.home-sezione h1').css({'width': sezioni_width * 3});



// Se non restringo troppo la finestra ridimensiono la colonna principale e quella a destra in rapporto 3 a 2
	if (body_width >= 600) {
		$('#content[class!=large]').css({'width': sezioni_width * 3, 'float':''});

		$('#main.home #content').css({'width': sezioni_width * 3 - 20, 'float':''});

		$('.facolta #content[class!=large]').css({'width': '', 'float':''});

		$('.centro #content[class!=large]').css({'width': body_width - 520});

                $('.centro_2 #content[class!=large]').css({'width': body_width - 520});


//		$('#top-facolta').css({'width': sezioni_width * 3});
//		$('#navigation').css({'margin-left': sezioni_width * 3 + 12, 'width':sezioni_width * 2 - 20 * $.browser.msie});
		$('#navigation').css({'width':sezioni_width * 2 - 20});
		$('.home #navigation').css({'width': sezioni_width * 2 - 12 - 18 * $.browser.msie});

// Nei centri la colonna contenuto è larga come il body MENO la colonna dei menu e MENO la colonna destra di navigazione (uguali tra loro e pari a 250 px circa)		
//		$('.centro #navigation').css({'margin-left': body_width - 500, 'width': 240});
		$('.centro #navigation').css({'width': 240});

		$('.facolta #navigation').css({'margin-left': '', 'width':''});

// Devo impostare l'altezza del blocco fotohome perché funzioni il crossfade
		$('#fotohome').css('height', (sezioni_width * 3 - 2) * 61/154);
		$('#fotohome img').css('width', sezioni_width * 3 - 2);

		$('#porta').css('display', '');
		$('img.large').css({'width': sezioni_width * 3});
		$('h1').css('margin-right', '');
		$('body').css('font-size', '');
		$('#page-actions li').css({'width': sezioni_width * 2 / 3 - 5});
		
		if ($('#page-actions li img').width() >= sezioni_width * 2 / 3 - 20) {
			$('#page-actions li img').css({'width': sezioni_width * 2 / 3 - 20});	
		} else {
			$('#page-actions li img').css('width', '');
		}

		/* Allargo il campo di ricerca, ma NON nei dipartimenti */
		$('.green #query').css({'width': sezioni_width * 5/3 - 10});


		$('#accesso-rapido select').css({'width': sezioni_width * 4 / 3 - 10});
		$('#utenti select').css({'width': sezioni_width * 5 / 3 - 129});
		$('#navigation .news img').css({'width': sezioni_width * 2 / 3 - 5});
		$('#navigation .news .datePhoto p').css({'width': sezioni_width * 2 / 3 - 11});
		$('.news .description').css({'font-size': sezioni_width / 15, 'margin-left': sezioni_width * 2 / 3 + 20});
		
	// viene eliminata la scritta "apri-chiudi sezione" dal menu a sx
		if (body_width < 730) {
			$('.home-sezione h2 span').hide();
		} else {
			$('.home-sezione h2 span').show();	
		}
		
	} else {
// altrimenti espando la colonna contenuti e metto l'altra sotto
		$('#content').css({'width':'auto', 'float':'none'});
		$('#navigation').css('margin-left', 12);
		$('#porta').css('display', 'none');
		$('h1').css('margin-right', 0);
		$('body').css('font-size', '.7em');

		// Allargo le tre sezioni perch頳i prendano TUTTO lo spazio disponibile
		$('#sezioni li').css('width', (body_width - margin_sezioni * 2 - 3) / 3);
		$('img.large').css({'width': body_width - margin_sezioni * 2 - 3});

	}


//	viewport_width = self.innerHeight || jQuery.boxModel && document.documentElement.clientHeight || document.body.clientHeight;

}






function aprimenu(link, id) {
	$('#' + id).slideToggle('fast');

	html = $(link).html();
	text = $(link).text();

	if (text.indexOf('chiudi') != -1) {
		html = html.replace('chiudi', 'apri').replace('meno', 'piu');
	} else {
		html = html.replace('apri', 'chiudi').replace('piu', 'meno');
	}


	$(link).html(html);

	return false;
}


try {
$(document).ready(function() {

// Apre il menu facolta al click
	$("#menu-facolta > li:has(ul) > a").click( function() {
		$(this).next('ul').toggle();
		return false;
	} );
	
// Menu di accesso rapido, nasconde il tasto di submit ed esegue un redirect al link della <select> all'onchange
	$('#accesso-rapido input[@type=submit]').hide();
	$('#accesso-rapido').change( function() {
		this.submit();
	} );

// Apre i link con rel="external" in una nuova finestra (Xhtml strict compliant)
	$("a[rel=external]").click( function() {
		window.open(this.href)
		return false;
	} );


// Colora a righe alterne le tabelle
	$('table.alterne tr:even').addClass('pari');



}
)
} catch(e) {}






function toggleMenuCentro(link) {
	$(link).next('ul').toggle();
	linkText = $(link).text();
/*	if (linkText.indexOf('\u2193') != -1) {
		newText = linkText.replace('\u2193', '\u2191');
	} 
	else if (linkText.indexOf('\u2191') != -1) { // &darr;
		newText = linkText.replace('\u2191', '\u2193');
	}


	$(link).text(newText);
*/
	return false;
}


function addFixedToLinks() {
    links = $('a');
    jQuery.each(links, function() {
          $(this).attr('href', $(this).attr('href') + '?fixed');
    });
}


/*
 * Rilevazione del Browser con messaggio all'utente per informazione e proposta di aggiornamento
 * Necessario per http://www.unimc.it/af/master/10/masterest
 * Utilizzo consigliato, aggiungere: onload="detectBrowser();" nel tag HTML <body> 
*/ 
function detectBrowser() {
	var TheBrowser = navigator.appName;
	var TheVersion = parseFloat(navigator.appVersion);
	var TheMsg = new String(
		"Sorry,\nto navigate this web site, you must have a newer version of your browser " 
		+ TheBrowser 
		+ "\n(now you have version %1%" 
		+ ")!\n\n Do You want to update your " 
		+ TheBrowser + " version ?"
	);
	//XTEST//alert("You have a browser\n " + navigator.appName + "\n v." + navigator.appVersion + "\n\n code " + navigator.appCodeName + "\n\n useragent " + navigator.userAgent);
	if ((TheBrowser=="Netscape") && (TheVersion<5)) {
		TheMsg = TheMsg.replace("%1%", new String(TheVersion)); 
		if (confirm(TheMsg))
		{
			window.location = "http://browser.netscape.com/";
		}
	} else if ((TheBrowser=="Opera") && (TheVersion<9)) {
		TheMsg = TheMsg.replace("%1%", new String(TheVersion)); 
		if (confirm(TheMsg))
		{
			window.location = "http://www.opera.com/";
		}
	} else if ((TheBrowser=="Microsoft Internet Explorer")) {
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
			TheVersion = new Number(RegExp.$1); // capture x.x portion and store as a number
			if (TheVersion < 7) {
				TheMsg = TheMsg.replace("%1%", new String(TheVersion)); 
				if (confirm(TheMsg))
				{
					window.location = "http://www.microsoft.com/windows/internet-explorer/worldwide-sites.aspx";
				}
			}
		} else {
		}
	}
}


