/****************************************************************
*   Funzione truncate per troncare le stringhe
****************************************************************/
jQuery.fn.truncate = function (max, settings) { settings = jQuery.extend({ chars: /\s/, trail: ["...", ""] }, settings); var myResults = {}; var ie = $.browser.msie; function fixIE(o) { if (ie) { o.style.removeAttribute("filter") } } return this.each(function () { var $this = jQuery(this); var myStrOrig = $this.html().replace(/\r\n/gim, ""); var myStr = myStrOrig; var myRegEx = /<\/?[^<>]*\/?>/gim; var myRegExArray; var myRegExHash = {}; var myResultsKey = $("*").index(this); while ((myRegExArray = myRegEx.exec(myStr)) != null) { myRegExHash[myRegExArray.index] = myRegExArray[0] } myStr = jQuery.trim(myStr.split(myRegEx).join("")); if (myStr.length > max) { var c; while (max < myStr.length) { c = myStr.charAt(max); if (c.match(settings.chars)) { myStr = myStr.substring(0, max); break } max-- } if (myStrOrig.search(myRegEx) != -1) { var endCap = 0; for (eachEl in myRegExHash) { myStr = [myStr.substring(0, eachEl), myRegExHash[eachEl], myStr.substring(eachEl, myStr.length)].join(""); if (eachEl < myStr.length) { endCap = myStr.length } } $this.html([myStr.substring(0, endCap), myStr.substring(endCap, myStr.length).replace(/<(\w+)[^>]*>.*<\/\1>/gim, "").replace(/<(br|hr|img|input)[^<>]*\/?>/gim, "")].join("")) } else { $this.html(myStr) } myResults[myResultsKey] = myStrOrig; $this.html(["<div class='truncate_less'>", $this.html(), settings.trail[0], "</div>"].join("")).find(".truncate_show", this).click(function () { if ($this.find(".truncate_more").length == 0) { $this.append(["<div class='truncate_more' style='display: none;'>", myResults[myResultsKey], settings.trail[1], "</div>"].join("")).find(".truncate_hide").click(function () { $this.find(".truncate_more").css("background", "#fff").fadeOut("normal", function () { $this.find(".truncate_less").css("background", "#fff").fadeIn("normal", function () { fixIE(this); $(this).css("background", "none") }); fixIE(this) }); return false }) } $this.find(".truncate_less").fadeOut("normal", function () { $this.find(".truncate_more").fadeIn("normal", function () { fixIE(this) }); fixIE(this) }); jQuery(".truncate_show", $this).click(function () { $this.find(".truncate_less").css("background", "#fff").fadeOut("normal", function () { $this.find(".truncate_more").css("background", "#fff").fadeIn("normal", function () { fixIE(this); $(this).css("background", "none") }); fixIE(this) }); return false }); return false }) } }) };

/****************************************************************
*   Ridimensionamento delle colonne
****************************************************************/
function setColumnHeight(){
	if ($('#colonna2').height() < $('#colonna3').height()){
		$('#colonna1').height($('#colonna3').height());
		$('#colonna2').height($('#colonna3').height());
	}else{
		$('#colonna1').height($('#colonna2').height());
		$('#colonna3').height($('#colonna2').height());
	}
}

/****************************************************************
*   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
****************************************************************/
// 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+'';
	window.open(baseURI + 'modules/privacy.html', 'privacy', settings)
}
