Shadowbox.init({
  language: "it",
  players: ["img", "iframe", "html"],
  continuous: true,
  overlayOpacity: 0.5,
  overlayColor: "#000"
});


function doMail(name, domain) {
  document.write('<a href="mailto:'+name+'@'+domain+'">'+name+'@'+domain+'</a>');
}



function send(url, nomeVar, container) {
  var inputs = $("[name^='"+nomeVar+"']");
  var data = '';
  var error = false;
   
  jQuery.each(inputs, function(index, value) {
    if(value.value=='' && value.className=="obbli") {
      $(value).css("background","#ffcfcf");
      error = true;
    } else {
      $(value).css("background","#fff");
    }
    data += "&" + value.name + "=" + value.value;
  });
  
  if(error) { return; }
  
  $("#preloader").show();
  
  $.ajax({
     type: "POST",
     url: url,
     data: data,
     success: function(msg){
       $("#preloader").hide();
       //console.log(msg); //debug
       if(msg=="ok") {
          $("#"+container).fadeOut("normal", function () {
            $("#"+container+"_msgok").fadeIn("fast");
            setTimeout("hide('"+container+"_msgok')", 4000)
          });
        } else {
          $("#"+container+"_msgko").fadeIn("fast");
          setTimeout("hide('"+container+"_msgko')", 4000)
        }
     }
   });
}



function hide(objName) {
  $("#"+objName).fadeOut("normal");
}



// Indice per ticker
var i = 1;

function ticker(num) {
    $('#news_'+i).fadeOut('fast', function () {
        if(i >= num) {
          i=1;
        } else {
          i++;
        }
        $('#news_'+i).fadeIn('fast');
      });  
}



function mappa(address, lingua){
  Shadowbox.open({
    player: 'html',
    content: '',
    height: 500,
    width: 600,
    options: {
      onFinish: function(item){
      if(GBrowserIsCompatible()){
        map = new GMap2(document.getElementById('shadowbox_content'));
        geocoder = new GClientGeocoder();
        
  			map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        
  			geocoder.setBaseCountryCode(lingua);
  			showAddress(address);
        }
      }
    }
  });
};



function showAddress(address) {
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        alert("Indirizzo non trovato");
      } else {
        map.setCenter(point, 13);
        var marker = new GMarker(point);
        map.addOverlay(marker);
        marker.openInfoWindowHtml(address);
      }
    }
  );
}
