/****************************************************************
*   Funzioni di visualizzazione modal popup
****************************************************************/
function showModal(pagina, larghezza, altezza, classe, stile, scrollabile, youtube) {
	var clientWidth = $(window).width();
	var clientHeight = $(window).height();
	var scrolla = scrollabile = '' ? 'auto' : scrollabile;
	var w = larghezza >= clientWidth ? clientWidth - 40 : larghezza;
	var h = altezza >= clientHeight ? clientHeight - 40 : altezza;
	var destinazione = pagina.indexOf("http://") == -1 ? baseURI + pagina : pagina;

	//sfondo
	var sfondo = $('<div id="popUpBackGround" />');
	sfondo.height((document.documentElement.scrollHeight ? document.documentElement.scrollHeight : document.body.scrollHeight) + 'px');
	sfondo.width((document.documentElement.scrollWidth ? document.documentElement.scrollWidth : document.body.scrollWidth) + 'px');
	sfondo.appendTo(document.body);

	//finestra
	var modal = $('<iframe id="popUp" frameborder="0" scrolling="' + scrolla + '" src="' + destinazione + '" style="' + stile + '" class="' + classe + '" width="' + w + '" height="' + h + '" />');
	if (youtube == 'si') {
		modal = $('<iframe id="popUp" title="YouTube video player" width="' + w + '" height="' + h + '" src="' + destinazione + '" frameborder="0" style="' + stile + '" class="' + classe + '" allowfullscreen="no"></iframe>');
	}
	modal.appendTo(document.body);
	modal.addClass("popUpBody");
	modal.css("left", ((clientWidth / 2) - (w / 2) + 'px'));
	modal.css("top", ((clientHeight / 2) - (h / 2) + 'px'));
	modal.show();

	//pulsante chiusura
	var close = $('<a id="closeModalButton" href="javascript:hideModal();"><img width="30" height="30" src="' + baseURI + 'images/close.png" /></a>');
	close.appendTo(document.body);
	close.addClass("close-modal-button");
	close.css("left", ((clientWidth / 2) - (w / 2) + w - 15) + 'px');
	close.css("top", ((clientHeight / 2) - (h / 2) - 15) + 'px');
	close.show();

	window.onresize = function () {
		sfondo.height((document.documentElement.scrollHeight ? document.documentElement.scrollHeight : document.body.scrollHeight) + 'px');
		sfondo.width((document.documentElement.scrollWidth ? document.documentElement.scrollWidth : document.body.scrollWidth) + 'px');
		var clientWidth = $(window).width();
		var clientHeight = $(window).height();
		modal.css("left", ((clientWidth / 2) - (w / 2) + 'px'));
		modal.css("top", ((clientHeight / 2) - (h / 2) + 'px'));
		close.css("left", ((clientWidth / 2) - (w / 2) + w - 15) + 'px');
		close.css("top", ((clientHeight / 2) - (h / 2) - 15) + 'px');
	}
}

function hideModal(control) {
	$('#popUpBackGround').remove();
	$('#popUp').remove();
	$('#closeModalButton').remove();
	window.onresize = null;
}

/****************************************************************
*   Funzioni di utility
****************************************************************/
//porta le 3 colonne della home alla stessa altezza
function homeParCol() {
	var max = Math.max($('.col1').height(), $('.col2').height(), $('.col3').height());
	$('.col1').height(max);
	$('.col2').height(max);
	$('.col3').height(max);
}

// funzioni per l'apertura di popUp
function privacy() {
	w = 580;
	h = screen.height - 50;
	LeftPosition = 0; //(screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = 0; //(screen.height) ? (screen.height-h)/2 : 0;
	settings = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=' + w + ',height=' + h + ',left=' + LeftPosition + ', top=' + TopPosition + ',screenX=' + LeftPosition + ',screenY=' + TopPosition + '';
	privacy = window.open(baseURI + 'modules/privacy.html', 'privacy', settings)
}
// funzioni per l'apertura di popUp
function anagrammi(n) {
	w = 600;
	h = 694;
	LeftPosition = (screen.width) ? (screen.width - w) / 2 : 0;
	TopPosition = (screen.height) ? (screen.height - h) / 2 : 0;
	settings = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=' + w + ',height=' + h + ',left=' + LeftPosition + ', top=' + TopPosition + ',screenX=' + LeftPosition + ',screenY=' + TopPosition + '';
	anagramma = window.open('../images/anagramma' + n + 'big.gif', 'anagramma', settings)
}
function anagrammiEN(n) {
	w = 600;
	h = 694;
	LeftPosition = (screen.width) ? (screen.width - w) / 2 : 0;
	TopPosition = (screen.height) ? (screen.height - h) / 2 : 0;
	settings = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=' + w + ',height=' + h + ',left=' + LeftPosition + ', top=' + TopPosition + ',screenX=' + LeftPosition + ',screenY=' + TopPosition + '';
	anagramma = window.open('../images/anagramma' + n + 'bigEN.gif', 'anagramma', settings)
}
