function simple_tooltip(target_items, name){
 $(target_items).each(function(i){
		$("body").append("<div class='"+name+"' id='"+name+i+"'>"+$(this).attr('title')+"</div>");
		var my_tooltip = $("#"+name+i);

		if($(this).attr("title") != "" && $(this).attr("title") != "undefined" ){

		$(this).removeAttr("title").mouseover(function(){
					my_tooltip.css({display:"none"}).fadeIn(400);
		}).mousemove(function(kmouse){
				var border_top = $(window).scrollTop();
				var border_right = $(window).width();
				var left_pos;
				var top_pos;
				var offset = -8;
				if(border_right - (offset *2) >= my_tooltip.width() + kmouse.pageX){
					left_pos = kmouse.pageX+offset-25;
					} else{
					left_pos = border_right-my_tooltip.width()-offset-25;
					}

				if(border_top + (offset *2)>= kmouse.pageY - my_tooltip.height()){
					top_pos = border_top +offset;
					} else{
					top_pos = kmouse.pageY-my_tooltip.height()+(offset*2);
					}

				my_tooltip.css({left:left_pos, top:top_pos});
		}).mouseout(function(){
				my_tooltip.css({left:"-9999px"});
		});

		}

	});
}

$(document).ready(function () {

	
$(".list-services ul li:nth-child(3n)").addClass("removed");
$(".list-items ul li:nth-child(4n)").addClass("removed");
$(".sub-menu ul li ul li:last-child a").addClass("last-child");
$(".sub-menu ul li:last-child a").addClass("last-child");
$(".new ul li:last-child").addClass("last-child");
$(".list.bordered li:last-child").addClass("last-child");




simple_tooltip(".tooltip","tooltip-cloud");	

/* top menu */
$("#top-menu > .main > li").mouseenter(function() {
	$(this).addClass("current-dynamic");
	$(this).find(".sub").animate({
								 height: "show"
								 },100);
	return false;
}).mouseleave(function(){
	$(this).removeClass("current-dynamic");
	$(this).find(".sub").animate({
								 height: "hide"
								 },100);
	return false;
	});
/* -- */

/* sub menu */
$(".sub-menu > ul > li > a").click(function(){
$(this).parent().parent().find("ul").animate({
		height: "hide"
		},200);

		$(this).parent().parent().find("li").removeClass("current");
		
$(this).parent().find("ul").animate({
		height: "toggle"
		},200);

		$(this).parent().has("ul").addClass("current");
return false;
});
/* -- */

/* scroll menu */
$('.scrollmenu a').click(function() {
	var curList = $(".scrollmenu li a.current").attr("rel");
	var listID = $(this).attr("rel");
	if (listID != curList) {
		$("#"+curList).fadeOut(150, function() {
			$("#"+listID).fadeIn(150);
		});
	} 
	var ul = $(this).closest('ul'),
	len = ul.children().length,
	ix = $(this).parent().index(),
	c = 'selected',
	h = $(this).outerHeight();
	
	if ( $(".scrollmenu").hasClass("non-scrollable") )
	{	

	} else {
		ix = ix < 2 ? 2 : ix > len - 3 ? len - 3 : ix;
		ul.animate({'marginTop': (2 - ix) * h});	
	}

	$(this).addClass('selected current').parent().siblings().children('.' + c).removeClass();
							
								  
});
/* -- */

/* tabs */
$(".tabs .nav li a").click(function(){
	var curList = $(".tabs .nav li a.current").attr("rel");
	var curListHeight = $(".tabs .cnt").height();
	$(".tabs .nav li a").removeClass("current");
	$(this).addClass("current");
	var listID = $(this).attr("rel");
	if (listID != curList) {
		$("#"+curList).fadeOut(0, function() {
			$("#"+listID).fadeIn();
			var newHeight = $("#"+listID).height();
		});
	}        
	return false;
});


/* -- */

/* toggles */
$(".toggles > ul > li > a").click(function(){
	if($(this).hasClass("current")){
	$(this).parent().find("p").slideUp("normal");
	$(this).removeClass("current");
	}
	else {
	$(this).parent().find("p").slideDown("normal");
	$(this).addClass("current");
	}
	return false;
});


/* -- */

/* portfolio filtering & pagination usage, pagination plugin is also in js/jquery.paginate.js */
var activeFiltersList = $("#filters ul li a").text();
var filterDefault = document.location.hash.replace("#","");

// checking each element in filters list, and if they match then add class current so they can be highlighted on page load
if (filterDefault) {
	$("#filters ul li a").each(function() {
		if($(this).attr("rel") == filterDefault) {
						 $(this).addClass("current");
		}
	});
}

// checking each element in project list, and if they match with the filter, if yes then show them
if (filterDefault) {
$(".project-list .list-contents li").each(function() {
	if(!$(this).hasClass(filterDefault)) {
		$(this).hide();
	}
	else {
		$(this).show();
	}
});
}
else {
	var filterDefault = "all";
}

// filter choosen elements
$("#filters ul li a").click(function() {
	
	
	$("#filters ul li a.current").removeClass("current");
	$(this).addClass("current");
	
	var filterBy = $(this).attr("href").replace("#","");

	
	$(".project-list").hide().fadeIn(400);
	$(".project-list > ul > li").each(function() {
		if(!$(this).hasClass(filterBy)) {
			$(this).hide();
		}
		else {
			$(this).fadeIn(400);
		}
		
	});
	
	
	var items_size = $(".project-list ul li:visible").size();
	if(items_size < external_pajinate_items_number)
	{
		$(".page_navigation").hide();
	}
	else {
		$(".page_navigation").show();
	}
	
	$('.project-list').pajinate({items_per_page : external_pajinate_items_number});

return false;
});

$(".project-list ul li .image a.more").click(function(){
	$("#lightbox").css("filter", "alpha(opacity=90)");
	$("#lightbox").fadeIn(300);
	$(this).parent().parent().find(".lightbox-work").fadeIn(300);
	})
	$("#lightbox, .lightbox-close").click(function(){
	$("#lightbox, .lightbox-work").fadeOut(300);
});
/* -- */

$(".boxpuntata ul li .image a.more").click(function(){
	$("#lightbox").css("filter", "alpha(opacity=90)");
	$("#lightbox").fadeIn(300);
	$(this).parent().parent().find(".lightbox-work").fadeIn(300);
	})
	$("#lightbox, .lightbox-close").click(function(){
	$("#lightbox, .lightbox-work").fadeOut(300);
});

$(".boxpuntata ul li .image a.more").click(function(){
	$("#lightbox").css("filter", "alpha(opacity=90)");
	$("#lightbox").fadeIn(300);
	$(this).parent().parent().find(".lightbox-work-200").fadeIn(300);
	})
	$("#lightbox, .lightbox-close").click(function(){
	$("#lightbox, .lightbox-work-200").fadeOut(300);
});

$(".boxpuntata ul li .image a.more").click(function(){
	$("#lightbox").css("filter", "alpha(opacity=90)");
	$("#lightbox").fadeIn(300);
	$(this).parent().parent().find(".lightbox-work-vv").fadeIn(300);
	})
	$("#lightbox, .lightbox-close").click(function(){
	$("#lightbox, .lightbox-work-vv").fadeOut(300);
});

$(".boxpuntata ul li .image a.more").click(function(){
	$("#lightbox").css("filter", "alpha(opacity=90)");
	$("#lightbox").fadeIn(300);
	$(this).parent().parent().find(".lightbox-work-re").fadeIn(300);
	})
	$("#lightbox, .lightbox-close").click(function(){
	$("#lightbox, .lightbox-work-re").fadeOut(300);
});
/* -- */

/* Wizard */

$(".wizard ul li a.more").click(function(){
	$("#lightbox").css("filter", "alpha(opacity=90)");
	$("#lightbox").fadeIn(300);
	$(this).parent().parent().find(".lightbox-work-w").fadeIn(300);
	})
	$("#lightbox, .lightbox-close").click(function(){
	$("#lightbox, .lightbox-work-w").fadeOut(300);
});

/* end wizard */


/* login box */
$("#login-box").click(function(){
	$("#lightbox").css("filter", "alpha(opacity=90)");
	$("#lightbox, #loginbox-panel").fadeIn(300);
	})
	$("#lightbox, #lightbox-close").click(function(){
	$("#lightbox, #loginbox-panel").fadeOut(300);
});
/* -- */

/* autoclear function for inputs */
$('.autoclear').click(function() {
if (this.value == this.defaultValue) {
this.value = '';
}
});
$('.autoclear').blur(function() {
if (this.value == '') {
this.value = this.defaultValue;
}
});

$('.gotop').click(function(){
	$('html, body').animate({scrollTop:0}, 'slow');
	return false;
});

});


// Funzioni varie

function ApriDoc (url) {

	window.open(url);
	return false;

}

function ApriSillaba (sillaba) {

	$("#sillaba").html('<div style="width: 100%; text-align: center; padding: 150px 0 0 0;"><img src="immagini/ajax-loader-grigio.gif" width="31" height="31" /><br />Sto caricando la lettera <strong>'+sillaba+'</strong>.</div>');
	$("#sillaba").load("template/sillabe/"+sillaba+".asp");

}

function ApriRete (rete,descrizionerete) {

	$("#reteprinc").remove();
	$("#subcontenitorerete").html('<div style="width: 100%; text-align: center; padding: 150px 0 0 0;"><img src="immagini/ajax-loader-grigio.gif" width="31" height="31" /><br />Sto caricando la rete: <strong>'+descrizionerete+'</strong>.</div>');
	
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		document.getElementById("subcontenitorerete").innerHTML=xmlhttp.responseText;
		}
	  }
	xmlhttp.open("POST","template/reti/"+rete+".asp?sid=" + Math.random(),true);
	xmlhttp.send();

	
}


// Newsletter

function TestEmail (Ctrl)
 {if (Ctrl.value == "Inserisci la tua e-mail...")
   {alert ("Inserire la E-Mail !");
	Ctrl.value="";
    Ctrl.focus();
    return (false);
   }
    
  //deve esserci una sola @
  pos=Ctrl.value.indexOf('@', 0)
  if (pos == 0)
   {alert ("Inserisci correttamente l'e-mail!");
    Ctrl.focus();
    return (false);
   }

  if (pos == -1) 
   {alert ("Inserisci correttamente l'e-mail!");
    Ctrl.focus();
    return (false);
   }
  else
   {if (Ctrl.value.indexOf('@', pos+1) != -1)
    {alert ("Inserisci correttamente l'e-mail!");
     Ctrl.focus();
     return (false);
    }
   }

  //devono esserci almeno 4 caratteri dopo @
  if (Ctrl.value.substring(pos+1,Ctrl.value.length).length < 4)
   {alert ("Inserisci correttamente l'e-mail!");
    Ctrl.focus();
    return (false);
   }
  //deve esserci almeno un . dopo @
  if (Ctrl.value.indexOf('.', pos+1) == -1)      
   {alert ("Inserisci correttamente l'e-mail!");
    Ctrl.focus();
    return (false);
   }

  //caratteri ammessi
  stremail=Ctrl.value.toUpperCase()
  for (var i = 0; i < stremail.length; i++)
   {if (".-_0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(stremail.charAt(i)) == -1) 
    {alert ("Inserisci correttamente l'e-mail!");
     Ctrl.focus();
     return (false);
    }
   }
  //Tutto OK
  return (true);   
 } 


function InviaNewsletter (nl,controllo) {
	if (!TestEmail(controllo)) return;
	window.location = "newsletter.asp?email="+nl

}

function SelezionaLingua (lingua) {
	window.location.href="?Lingua="+lingua;
}

function PartenzaMDD()
{

$("#via").css("display","none")
$("#viaopaco").css("display","block")
$("#mododidire").html('<div style="width: 100%; text-align: center; padding: 20px 0 0 0;"><img src="immagini/ajax-loader-grigio.gif" width="31" height="31" /><br />Sto caricando Il gioco !</div>');

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("mododidire").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("POST","template/mdd/mododidire.asp?sid=" + Math.random(),true);
xmlhttp.send();

$("#countdown").css("display","block")

countdown_init();
}

function controlla (numero) {
	if (numero == document.getElementById("soluzione").value)
	{
		$("#bravo").css("display","block")
		$("#but1").css("display","none")
		$("#but2").css("display","none")
		//$("#viaopaco").css("display","none")
	} else {
		$("#cilecca").css("display","block")
		$("#but1").css("display","none")
		$("#but2").css("display","none")
		//$("#viaopaco").css("display","none")
	}
}


/* REGOLE */

function Controllo(nome,risultato,risposta,esercizio)
	{

		risultato = risultato.replace(/"à"/g,"&agrave;");
		risultato = risultato.replace(/"è"/g,"&egrave;");
		risultato = risultato.replace(/"ì"/g,"&igrave;");
		risultato = risultato.replace(/"ò"/g,"&ograve;");
		risultato = risultato.replace(/"ù"/g,"&ugrave;");



		document.getElementById("conta"+esercizio).value = ((document.getElementById("conta"+esercizio).value*1)-1).toFixed(0);
		document.getElementById(nome).readOnly = "readonly";

		if (risultato == risposta) 
			{
			  document.getElementById("totalone"+esercizio).value = ((document.getElementById("totalone"+esercizio).value*1)+1).toFixed(0);
			  document.getElementById(nome).style.background = "#A8EA7D";
			  document.getElementById(nome).style.color = "#000000";
			  
			} else {
			  document.getElementById(nome).style.background = "#FF0000";
			  document.getElementById(nome).style.color = "#ffffff";
			}
	
		if (document.getElementById("conta"+esercizio).value == 0)
		{

				  
				  if (document.getElementById("totalone"+esercizio).value*1 == 10)
				  {
					 document.getElementById("totale10").style.display = "block"; 
				  }

				  if (document.getElementById("totalone"+esercizio).value*1 > 6 && document.getElementById("totalone"+esercizio).value*1 < 10)
				  {
					 document.getElementById("totale9-7").style.display = "block"; 
				  }

				  if (document.getElementById("totalone"+esercizio).value*1 == 5)
				  {
					 document.getElementById("totale5").style.display = "block"; 
				  }

				  if (document.getElementById("totalone"+esercizio).value*1 >= 0 && document.getElementById("totalone"+esercizio).value*1 < 5)
				  {
					 document.getElementById("totale4-0").style.display = "block"; 
				  }
				  return (false);


		}

	}

function Controllo20(nome,risultato,risposta,esercizio)
	{
		risultato = risultato.replace(/"à"/g,"&agrave;");
		risultato = risultato.replace(/"è"/g,"&egrave;");
		risultato = risultato.replace(/"ì"/g,"&igrave;");
		risultato = risultato.replace(/"ò"/g,"&ograve;");
		risultato = risultato.replace(/"ù"/g,"&ugrave;");

		document.getElementById("conta"+esercizio).value = ((document.getElementById("conta"+esercizio).value*1)-1).toFixed(0);
		document.getElementById(nome).readOnly = "readonly";

		if (risultato == risposta) 
			{
			  document.getElementById("totalone"+esercizio).value = ((document.getElementById("totalone"+esercizio).value*1)+1).toFixed(0);
			  document.getElementById(nome).style.background = "#A8EA7D";
			  document.getElementById(nome).style.color = "#000000";
			  
			} else {
			  document.getElementById(nome).style.background = "#FF0000";
			  document.getElementById(nome).style.color = "#ffffff";
			}
	
		if (document.getElementById("conta"+esercizio).value == 0)
		{

				  
				  if (document.getElementById("totalone"+esercizio).value*1 == 20)
				  {
					 document.getElementById("totale10").style.display = "block"; 
				  }

				  if (document.getElementById("totalone"+esercizio).value*1 > 14 && document.getElementById("totalone"+esercizio).value*1 < 20)
				  {
					 document.getElementById("totale9-7").style.display = "block"; 
				  }

				  if (document.getElementById("totalone"+esercizio).value*1 == 14)
				  {
					 document.getElementById("totale5").style.display = "block"; 
				  }

				  if (document.getElementById("totalone"+esercizio).value*1 >= 0 && document.getElementById("totalone"+esercizio).value*1 < 14)
				  {
					 document.getElementById("totale4-0").style.display = "block"; 
				  }
				  return (false);


		}

	}

function Azzera(nome)
	{
		
		if (document.getElementById(nome).readOnly == false)
		{
			document.getElementById(nome).value = "";
		}

	}

function Riattiva(nome,tipo)
	{
		
		if (document.getElementById(nome).value == "")
		{
			document.getElementById(nome).value = tipo;
		}

	}

function Nascondi (divdanascondere)
	{
		document.getElementById(divdanascondere).style.display = "none"; 
	}



function Sottolinea (nome,confronto,esercizio)

	{
		document.getElementById("conta"+esercizio).value = ((document.getElementById("conta"+esercizio).value*1)-1).toFixed(0);
		document.getElementById(nome).readOnly = "readonly";

		if (document.getElementById(nome).value == confronto) 
			{
			  document.getElementById("totalone"+esercizio).value = ((document.getElementById("totalone"+esercizio).value*1)+1).toFixed(0);
			  //document.getElementById(nome).style.background = "#A8EA7D";
			  document.getElementById(nome).style.borderBottom = "1px solid #ffffff";
			  
			} else {
			  document.getElementById(nome).style.background = "#FF0000";
			  document.getElementById(nome).style.color = "#ffffff";
			}
	
		if (document.getElementById("conta"+esercizio).value == 0)
		{

				  
				  if (document.getElementById("totalone"+esercizio).value*1 == 10)
				  {
					 document.getElementById("totale10").style.display = "block"; 
				  }

				  if (document.getElementById("totalone"+esercizio).value*1 > 6 && document.getElementById("totalone"+esercizio).value*1 < 10)
				  {
					 document.getElementById("totale9-7").style.display = "block"; 
				  }

				  if (document.getElementById("totalone"+esercizio).value*1 == 5)
				  {
					 document.getElementById("totale5").style.display = "block"; 
				  }

				  if (document.getElementById("totalone"+esercizio).value*1 >= 0 && document.getElementById("totalone"+esercizio).value*1 < 5)
				  {
					 document.getElementById("totale4-0").style.display = "block"; 
				  }
				  return (false);


		}

	}

function Chekka (nome,giusto,questo,esercizio)

	{
		var objdis = "ha_"+nome+"_"+questo

		document.getElementById("conta"+esercizio).value = ((document.getElementById("conta"+esercizio).value*1)-1).toFixed(0);
		
		//alert("#ha_"+nome+"_"+questo);

		if (questo == giusto) 
			{
			  for (var i=1;i<6;i++)
				{
					if (i == questo)
					{
						document.getElementById(nome+"_"+i).src = "immagini/Icone/spuntaverde.png";
					} else {
						document.getElementById(nome+"_"+i).style.display = "none";
					}
				}
			  document.getElementById("totalone"+esercizio).value = ((document.getElementById("totalone"+esercizio).value*1)+1).toFixed(0);		  
			} else {
				for (var i=1;i<6;i++)
				{
					if (i == questo)
					{
						document.getElementById(nome+"_"+i).src = "immagini/Icone/spuntarossa.png";
					} else {
						document.getElementById(nome+"_"+i).style.display = "none";
					}
				}
			}
	
		if (document.getElementById("conta"+esercizio).value == 0)
		{

				  
				  if (document.getElementById("totalone"+esercizio).value*1 == 10)
				  {
					 document.getElementById("totale10").style.display = "block"; 
				  }

				  if (document.getElementById("totalone"+esercizio).value*1 > 6 && document.getElementById("totalone"+esercizio).value*1 < 10)
				  {
					 document.getElementById("totale9-7").style.display = "block"; 
				  }

				  if (document.getElementById("totalone"+esercizio).value*1 == 5)
				  {
					 document.getElementById("totale5").style.display = "block"; 
				  }

				  if (document.getElementById("totalone"+esercizio).value*1 >= 0 && document.getElementById("totalone"+esercizio).value*1 < 5)
				  {
					 document.getElementById("totale4-0").style.display = "block"; 
				  }
				  return (false);


		}

		document.getElementById(objdis).disabled = true;

	}


function OpenURL (url)
	{
		window.open(url,'mywindow','');
	}
