var toggled;
var speedOpen = 500;
var speedClose = 500;
var opening = false;
var checkToggle = true;
function init()
{
	toggleAll();
}
function toggleAll()
{
	$('.menuL').slideToggle(0,showMenu);
	$('#tell').slideToggle(0,showForm);
	toggled="";
}
function showForm()
{
	$("#tell").css("visibility", "visible");
	$("#formContainer").slideToggle(0);
	 $(document).ready(function() {
	 $("#tell").validationEngine({
       ajaxSubmit: true,
        ajaxSubmitFile: "common/emailFriend.php",
        ajaxSubmitMessage: "Your message has been sent successfully.",
       success : function () { callSuccessFunction();},
       failure : function() {	   
		$("#formContainer").html("There is a problem in the form, please verify the data."); }
      })
	});
	
}
function callSuccessFunction()
{
	$("#formContainer").html("Your message has been sent successfully.");
}
function clearForm()
{
	$("#formContainer").html("");
}
function showMenu()
{
	document.getElementById('menu').style.visibility='visible';
}
// checkToggle = false se è l'unico slide nella pagina
function slideOne(which,closeAlerts)
{
	if (checkToggle)
	{
		if (which == toggled)
		{return}
	}
	opening = true;
	slideIt(which);
	if (which == 'tell')
	{
		$('#formtell').css("backgroundColor", "#333333" );
	}
	if (closeAlerts)
	{
		if ($.validationEngine)
		{
			$.validationEngine.closePrompt('#your_name', false);
			$.validationEngine.closePrompt('#friend_email1', false);
			$.validationEngine.closePrompt('#message',false);
		}
	}
}
function unSlideToggled(which)
{
	t = 0;
	$('.menuL').each(function(i, o){
		if (o.id == toggled && checkToggle) {
			unSlideIt(o.id);
			t++;
		}
	});
	if (t == 0)
	{
		opening = false;
	}
	toggled=which;
}
function slideIt(what) {
	$('#'+what).slideToggle(speedOpen,unSlideToggled(what));
}
function unSlideIt(what) {
	$('#'+what).slideToggle(speedClose,closed);
}
function closed()
{
	opening = false;
}
