$(document).ready(function() {
  $("#previa").load(function() {
    $(this).fadeTo("normal", 1.0);
  });
  
  moverSlide();
  
  $('#barra a').each(function(index, element){
    $(element).mouseover(function() {
      id = $(this).attr('id');
      if (id && id != '') cambiarPrevia('pre-'+id+'.jpg');
    });
    
    $(element).mouseout(function() {
      cambiarPrevia('');
    });
  });
  
  if ($(this).attr('title') == 'TecMoLiq.com.ar') {
    //Intro
    setTimeout(function(){
      $("#avion #imagen img").animate({
        height: "400px"
      }, 3000, function(){
        $("#avion #imagen img").animate({
          height: "850px"
        }, 3000);
      });
    },300);
  }
  
  if ($(this).attr('title').search('Contáctenos') != -1 || $(this).attr('title').search('Contact Us') != -1) {
    geocoder = new google.maps.Geocoder();
    init_gmap();
  }
})

function moverSlide(){
  $('#img1').animate({top: '-=528px'}, 5000, function() {
    $('#img1').css({top:'0px'});
    moverSlide();}
  );
}

function cambiarPrevia(archivo){
  pre = $('#previa');
  $("#previa").stop()
  if (this.location.href.match(/\/eng\//) != null) {
    archivo = "../img/"+archivo;
  } else {
    archivo = "./img/"+archivo;
  }
  if (pre){
    if (archivo != "") {
      if ($('#previa').attr("src") != archivo) {
        var imagen = new Image();
        imagen.src = archivo;
        $("#previa").stop().fadeTo("fast", 0.0, function() {
          $("#previa").attr("src", archivo);}
        );
      };
    } else {
      $("#previa").stop().fadeTo("fast", 0.0);
    }
  }
}

var startZoom = 9;
var map;
var markers = [];

//Crea el mapa vacio
function init_gmap() {
  var options = {
    zoom: startZoom,
    center: new google.maps.LatLng(-34.71714803840951, -58.30205535624998),
    zoomControl: true,
    panControl: true,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };

  map = new google.maps.Map(document.getElementById("mapa"), options);
  var infoWindow = new google.maps.InfoWindow({ maxWidth: 100 });

  //tec
  var marker1 = new google.maps.Marker({
     map: map,
     position: new google.maps.LatLng(-34.71714803840951, -58.30205535624998)
  })

  map.setCenter(marker1.position);
  map.setZoom(14);
}

function centerMarker(id){
  map.setCenter(markers[id].position);
  map.setZoom(14);
}

