/* Menu Orizzontale */
clickMenu = function(menu) {
	var getEls = document.getElementById(menu).getElementsByTagName("LI");
	var getAgn = getEls;

	for (var i=0; i<getEls.length; i++) {
			getEls[i].onclick=function() {
				for (var x=0; x<getAgn.length; x++) {
				getAgn[x].className=getAgn[x].className.replace("unclick", "");
				getAgn[x].className=getAgn[x].className.replace("click", "unclick");
				}
			if ((this.className.indexOf('unclick'))!=-1) {
				this.className=this.className.replace("unclick", "");;
				}
				else {
				this.className+=" click";
				}
			}
			getEls[i].onmouseover=function() {
				this.className+=" hover";
			}
			getEls[i].onmouseout=function() {
				this.className=this.className.replace("hover", "");
			}
		}
	}

$(document).ready
(
	function()
	{
//------show hide
//		if($(".hidden").length!="")
//		{
//			$(".hidden").hide();
//			/*$(".show b").html("Show");*/
//			$(".show b").html("");
//			
//			$(".show").click(function() {
//			if (this.className.indexOf('clicked') != -1 ) {
//					$(".hidden").hide();
//					$(this).removeClass('clicked')
//					/*$(this).children("b").html("Show");*/
//					$(this).children("b").html("");
//					}
//					else {
//					$(".hidden").hide();
//					$(".show").removeClass('clicked');
//					/*$(".show").children("b").html("Show");*/
//					$(".show").children("b").html("");
//					current = $(this).children("b").attr("class");
//					$("#"+current).show();
//					$(this).addClass('clicked')
//					/*$(this).children("b").html("Nascndi");*/
//					$(this).children("b").html("");
//					}
//			});
//		}
//		
//------show hide con amimazione
		if($(".hidden2").length!="")
		{
			$(".hidden2").hide();
			$(".show2").html("Continua qui...");
			
			$(".show2").click(function() {
			if (this.className.indexOf('clicked') != -1 ) {
				//aggiunto per avere una anteprima del messaggio
				$(".anteprima").show();
				//fine
				$(this).prev().slideUp(500);
				$(this).removeClass('clicked')
				$(this).html("Continua qui...");
				}
				else {
				//aggiunto per avere una anteprima del messaggio
				$(".anteprima").hide();
				//fine
				$(this).addClass('clicked')
				$(this).prev().slideDown(500);
				$(this).html("...Nascondi");
				}
			});
		}
		
//------tableSorter
		if($("#myTable").length!="")
		{
			$("#myTable").tablesorter();
		}
		
//------LightBox
	
			//$('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
			// This, or...
			//$('#gallery a').lightBox(); // Select all links in object with gallery ID
			// This, or...
			$('a.lightbox').lightBox(); // Select all links with lightbox class
			$('a.lightbox1').lightBox(); // Select all links with lightbox class
			$('a.lightbox2').lightBox(); // Select all links with lightbox class
			$('a.lightbox3').lightBox(); // Select all links with lightbox class
			$('a.lightbox4').lightBox(); // Select all links with lightbox class
			// This, or...
			//$('a').lightBox(); // Select all links in the page
			// ... The possibility are many. Use your creative or choose one in the examples above
		
//------Validazione di un form		
		if($("#posta").length!="")
		{
			$("#posta").validate();
		}
		
		if($("#friend").length!="")
		{
			$("#friend").validate();
		}
		
		if($("#abbonati").length!="")
		{
			$("#abbonati").validate({
				rules: {
					password: {
						required: true,
						minlength: 8
					},
					password2: {
						required: true,
						minlength: 8,
						equalTo: "#password"
					},
					email: {
						required: true,
						email: true
					},
					autorizza: "required"
				},
				messages: {
					password: {
						//required: "Please provide a password",
						required: "Questo campo è richiesto",						
						//minlength: "Your password must be at least 5 characters long"
						minlength: "La password deve essere di almeno 8 caratteri"

					},
					password2: {
						//required: "Please provide a password",
						required: "Questo campo è richiesto",
						//minlength: "Your password must be at least 5 characters long",
						minlength: "La password deve essere di almeno 8 caratteri",
						//equalTo: "Please enter the same password as above"
						equalTo: "Le password non corrispondono"
					},
					autorizza: "Manca il consenso"
				}
			});
		}

		if($("#testo").length!="")
		{
			$('#testo').wysiwyg();		
		}
	}	
);

/* Menu Verticale */
function sugo(altezza)
{
	fY=altezza; 
};

$(document).ready(function pippo()
{
	/* CONFIG */
	/* set start (sY) and finish (fY) heights for the list items */

	sY = 24; /* height of li.sub */
	/*fY = 150;*/ /* height of maximum sub lines * sub line height */
	/* end CONFIG */

	/* open first list item */
	animate (fY)

	$(".slide .sub").click(function() 
	{
		if (this.className.indexOf('clicked') != -1 ) 
		{
			animate(sY)
			$(this)			.removeClass('clicked')
							.css("background", "#eee url(images/out.gif) no-repeat 5px 8px")
							.css("color", "#000");
		}
		else 
		{
			animate(sY)
			$('.clicked')	.removeClass('clicked')
							.css("background", "#eee url(images/out.gif) no-repeat 5px 8px")
							.css("color", "#000");
			$(this)				.addClass('clicked');
			animate(fY)
		}
	});

	function animate(pY) 
	{
		$('.clicked').animate({"height": pY + "px"}, 500);
	}

	$(".slide .sub")		.hover(function()
	{
		$(this)				.css("background", "#ddd url(images/down.gif) no-repeat 5px 8px")
							.css("color", "#c00");
	},
	function()
	{
		if (this.className.indexOf('clicked') == -1) 
		{
			$(this)					.css("background", "#eee url(images/out.gif) no-repeat 5px 8px")
									.css("color", "#000");
		}
	});
});


function onKeyNumeric(e) 
{
	// Accetto solo numeri e backspace <-
	if ( ((e.keyCode >= 48) && (e.keyCode <= 57)) || (e.keyCode == 8) || (e.keyCode == 9) || ((e.keyCode >= 96) && (e.keyCode <= 105)) ) {
		return true;
	} else {
		return false;
	}
}
