
    function load_page(fpage, tbanner)
    {
      hideallmenu();
      $("#main_content").load('/' + lang + '/' + fpage);
      $.scrollTo(0, 1000);
    }

    function select_gallery(gname, gtitle)
    {
      $("#main_content").load("/gallery/disp.php?dirname="+gname+"&title="+gtitle);
    }

    function gallery_hide() { $("#gallery").animate({width: "0px", height: "0px", opacity: 0.0}, 1000); }

    function whereweare()
    {
	$("#main_content").load('/' + lang + "/map.html", "",
	function()
	{
	  var map = new GMap2(document.getElementById("map_canvas"));
	  map.setCenter(new GLatLng(43.495403, 11.117010), 12);
	  map.setUIToDefault();
	  var point = new GLatLng(43.495403, 11.117010);
	  var marker = new GMarker(point);
	  marker.openInfoWindowHtml("<center><b>CT Elettronica s.r.l.</b><br />"+
				    "Via Caduti di Nassiriya, 5/B<br />"+
				    "50021 Barberino Val d'Elsa FI<br />"+
				    "Tel. +39 055 8078444, Fax +39 055 8078386</center>");
	  map.addOverlay(marker);
	}
      );
    }

    function showmenu(id)
    {
      var myid = "#menu_"+id+"_"+lang;
      hidemenu(myid);
      if($(myid).is(':hidden'))
      {
	$(myid).show();
	var p = $("#head_"+id).position();
	$(myid).css("top", p.top+$("#head_"+id).height()+5);
	$(myid).css("left", p.left);
	$(myid).css("opacity", 0.0);
	var h = menuh["menu_"+id+"_"+lang];
	$(myid).css("height", "0px");
	$(myid).stop().animate({height: h, opacity: 1.0}, 1000);
      }
      return false;
    }

    function opendialog_contact()
    {
      if(lang == 'it')
	$('#dialog_contact').dialog('option', 'title', "Contattaci");
      else if(lang == 'eng')
	$('#dialog_contact').dialog('option', 'title', "Contact us");
      else if(lang == 'fr')
	$('#dialog_contact').dialog('option', 'title', "Contact us");

      $('#dialog_contact').dialog('open');
    }
    
    function opendialog_register()
    {
      if(lang == 'it')
	$('#dialog_register').dialog('option', 'title', "Registrati");
      else if(lang == 'eng')
	$('#dialog_register').dialog('option', 'title', "Register");
      else if(lang == 'fr')
	$('#dialog_register').dialog('option', 'title', "Register");

      $('#dialog_register').dialog('open');
    }

    function hidemenu(filtro) { $("div.ctmenu").not(filtro).stop().hide(); }
    function hideallmenu() { $("div.ctmenu").stop().hide(); }

    $(document).ready(function() {
      
      $("div.ctmenu").each(function(){
	menuh[$(this).attr('id')] = $(this).height();
      });
      
      $("div.ctmenu_element")
	.mouseover(function(){
	  $(this).css('background-image', 'url(/images/bg/menu_hover.gif)');
	  $(this).css('color', 'yellow');
	})
	.mouseout(function(){
	  $(this).css('background-image', 'url(/images/bg/menu_bck.gif)');
	  $(this).css('color', 'white');
      });
    
      $("#dialog_contact").dialog({
	bgiframe: true,
	autoOpen: false,
	height: 500,
	width: 400,
	modal: true,
	buttons:
	{
	    'Invia richiesta': function()
	    {
	      $.post("script/mail.php",
	      {
		azienda: $("#dialog_contact input[name='azienda']").val(),
		object: $("#dialog_contact input[name='object']").val(),
		email: $("#dialog_contact input[name='email']").val(),
		tel: $("#dialog_contact input[name='tel']").val(),
		address: $("#dialog_contact input[name='address']").val(),
		city: $("#dialog_contact input[name='city']").val(),
		dest: $("#dialog_contact input[name='dest']").val(),
		desc: $("#dialog_contact textarea[name='desc']").val()
	      });
	      if(lang == 'it')
		alert("Grazie per averci contattato, sarete ricontattati al più presto.");
	      else if(lang == 'eng')
		alert("Thank you for contacting us. You will be contacted by one of our team members as soon as possible.");
	      else if(lang == 'fr')
		alert("Thank you for contacting us. You will be contacted by one of our team members as soon as possible.");
	      $("#dialog_contact :input").val("");
	      $(this).dialog('close');
	    },
	    'Cancella': function()
	    {
	      $("#dialog_contact:input").val("");
	      $(this).dialog('close');
	    }
	}
      });

      $("#dialog_register").dialog({
	bgiframe: true,
	autoOpen: false,
	height: 370,
	width: 450,
	modal: true,
	buttons:
	{
	    'Invia richiesta': function()
	    {
	      $.post("script/register.php",
		    {
		      azienda: $("#dialog_register input[name='azienda']").val(),
		      referente: $("#dialog_register input[name='referente']").val(),
		      email: $("#dialog_register input[name='email']").val(),
		      telefono: $("#dialog_register input[name='tel']").val(),
		      indirizzo: $("#dialog_register input[name='address']").val(),
		      citta: $("#dialog_register input[name='city']").val(),
		      nazione: $("#dialog_register input[name='nazione']").val(),
		      newsletter: $("#dialog_register input[name='newsletter']").attr('checked'),
		      pubblicita: $("#dialog_register input[name='pubblicita']").attr('checked')
		    },
		    function (data, textStatus)
		    {
		      //alert(data);
		    }
	      );

	      if(lang == 'it')
		alert("Grazie per averci contattato, sarete ricontattati al più presto.");
	      else if(lang == 'eng')
		alert("Thank you for contacting us. You will be contacted by one of our team members as soon as possible.");
	      else if(lang == 'fr')
		alert("Thank you for contacting us. You will be contacted by one of our team members as soon as possible.");
	      $("#dialog_register :input").val("");
	      $(this).dialog('close');
	    },
	    'Cancella': function()
	    {
	      $("#dialog_register:input").val("");
	      $(this).dialog('close');
	    }
	}
      });

      pageTracker = _gat._getTracker("UA-11303069-1");
      pageTracker._trackPageview();

      hideallmenu();
      change_language(lang);
    });
