$(document).ready(function() {
  
 /*  $('body').translate('english',{
              start:function(){
                var lang = this.getLanguages( false );
                    console.log( lang );
            }
         }); 

   $("ul#leng li a").click(function(){
      $('body').translate($(this).attr("rel"))
               return false;
      })*/

  /*******************
  MENU ACTIVO
*******************/
  
      $('#dinzey-animation').cycle({
        fx: 'fade',
        speed: 1100,
        timeout: 7000,
      });

  var paginaActual = $("div#Contenido").attr("rel")
      if(paginaActual){
        $("ul#Menu >  li > a").each(function(){
          if($(this).text() == paginaActual){
            $(this).parent().attr("class","active")
          }
        })

      } else {
      $("ul#Menu > li:eq(0)").attr("class","active")
      } 
//ANIMATION HOME
$( "#tabs-noticias" ).tabs();
$( "#tabs-eventos" ).tabs();   
$('#tabs').tabs({fx:{opacity: "show"}}).tabs("rotate", 5000, true);
  $('#myslides').tabs({fx:{opacity: "show"}}).tabs("rotate", 1000, true);
  
$('#Animation').tabs({fx:{opacity: "show"}}).tabs("rotate", 6000, true);
   
//ANIMATION END
  
//SUPERFISH
  $('ul.sf-menu').superfish();
//SUPERFISH
  
//FONT SIZE RESET
  
 // Reset Font Size
 var originalFontSize = $('div#Contenido').css('font-size');
   $(".resetFont").click(function(){
   $('div#Contenido').css('font-size', originalFontSize);
 });
  
 // Increase Font Size
 $(".increaseFont").click(function(){
   var currentFontSize = $('div#Contenido').css('font-size');
   var currentFontSizeNum = parseFloat(currentFontSize, 10);
   var newFontSize = currentFontSizeNum*1.2;
     $('div#Contenido').css('font-size', newFontSize);
     return false;
 });
  
 // Decrease Font Size
 $(".decreaseFont").click(function(){
   var currentFontSize = $('div#Contenido').css('font-size');
   var currentFontSizeNum = parseFloat(currentFontSize, 10);
   var newFontSize = currentFontSizeNum*0.8;
     $('div#Contenido').css('font-size', newFontSize);
     return false;
 });
  
//PIROBOX
$().piroBox_ext({
    piro_speed : 700,
    bg_alpha : 0.5,
    piro_scroll : true // pirobox always positioned at the center of the page
});

//GALERIA DE FOTOS
$("ul.thumb li").hover(function() {
    $(this).css({'z-index' : '10'});
    $(this).find('span.p').css({'z-index' : '11','visibility' : 'visible'}).stop().animate({
        left: '-30px',
        bottom: '-24px',
        width: '164px'
    }, 200);
    $(this).find('img.fl').addClass("hover").stop()
      .animate({
        marginTop: '-110px', 
        marginLeft: '-110px', 
        top: '50%', 
        left: '50%', 
        width: '174px', 
        height: '174px',
        padding: '20px' 
      }, 200);
    
    } , function() {
    $(this).css({'z-index' : '0'});
    $(this).find('span.p').css({'z-index' : '0','visibility' : 'hidden'}).stop().animate({
        left: '6px',
        bottom: '14px',
        width: '90px'
    });
    $(this).find('img.fl').removeClass("hover").stop()
      .animate({
        marginTop: '0', 
        marginLeft: '0',
        top: '0', 
        left: '0', 
        width: '100px', 
        height: '100px', 
        padding: '5px'
      }, 400);
});
   
});
  var directionDisplay;
  var directionsService = new google.maps.DirectionsService();
  var map ='satelite';
  var origin = null;
  var destination = 'ABQIAAAA4U6xmOg-CPNTiNi539W-_xRpC2VIsgzsaU2pTxjCWeU0bHJ5nxTvi71xfEJr1Pbw74VMHiDed7Xr-A';
  var waypoints = [];
  var markers = [];
  var directionsVisible = false;

  function initialize() {
    directionsDisplay = new google.maps.DirectionsRenderer();
    var chicago = new google.maps.LatLng(18.423054,-70.012034);
    var myOptions = {
      zoom: 18,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: chicago
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    directionsDisplay.setMap(map);
    directionsDisplay.setPanel(document.getElementById("directionsPanel"));
    
    google.maps.event.addListener(map, 'click', function(event) {
      if (origin == null) {
        origin = event.latLng;
        addMarker(origin);
      } else if (destination == null) {
        destination = event.latLng;
        addMarker(destination);
      } else {
        if (waypoints.length < 9) {
          waypoints.push({ location: destination, stopover: true });
          destination = event.latLng;
          addMarker(destination);
        } else {
          alert("Maximum number of waypoints reached");
        }
      }
    });
  }

  function addMarker(latlng) {
    markers.push(new google.maps.Marker({
      position: latlng, 
      map: map,
      icon: "http://maps.google.com/mapfiles/marker" + String.fromCharCode(markers.length + 65) + ".png"
    }));    
  }

  function calcRoute() {
    if (origin == null) {
      alert("Click on the map to add a start point");
      return;
    }
    
    if (destination == null) {
      alert("Click on the map to add an end point");
      return;
    }
    
    var mode;
    switch (document.getElementById("mode").value) {
      case "bicycling":
        mode = google.maps.DirectionsTravelMode.BICYCLING;
        break;
      case "driving":
        mode = google.maps.DirectionsTravelMode.DRIVING;
        break;
      case "walking":
        mode = google.maps.DirectionsTravelMode.WALKING;
        break;
    }
    
    var request = {
        origin: origin,
        destination: destination,
        waypoints: waypoints,
        travelMode: mode,
        optimizeWaypoints: document.getElementById('optimize').checked,
        avoidHighways: document.getElementById('highways').checked,
        avoidTolls: document.getElementById('tolls').checked
    };
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
      }
    });
    clearMarkers();
    directionsVisible = true;
  }
  
  function updateMode() {
    if (directionsVisible) {
      calcRoute();
    }
  }
  
  function clearMarkers() {
    for (var i = 0; i < markers.length; i++) {
      markers[i].setMap(null);
    }
  }
  
  function clearWaypoints() {
    markers = [];
    origin = null;
    destination = null;
    waypoints = [];
    directionsVisible = false;
  }
  function reset() {
    clearMarkers();
    clearWaypoints();
    directionsDisplay.setMap(null);
    directionsDisplay.setPanel(null);
    directionsDisplay = new google.maps.DirectionsRenderer();
    directionsDisplay.setMap(map);
    directionsDisplay.setPanel(document.getElementById("directionsPanel"));    
  }
  var directionDisplay;
  var directionsService = new google.maps.DirectionsService();
  var map ='satelite';
  var origin = null;
  var destination = 'ABQIAAAA4U6xmOg-CPNTiNi539W-_xRpC2VIsgzsaU2pTxjCWeU0bHJ5nxTvi71xfEJr1Pbw74VMHiDed7Xr-A';
  var waypoints = [];
  var markers = [];
  var directionsVisible = false;

  function initialize() {
    directionsDisplay = new google.maps.DirectionsRenderer();
    var chicago = new google.maps.LatLng(18.423054,-70.012034);
    var myOptions = {
      zoom: 18,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: chicago
    }
    map = new google.maps.Map(document.getElementById("map_canvas2"), myOptions);
    directionsDisplay.setMap(map);
    directionsDisplay.setPanel(document.getElementById("directionsPanel2"));
    
    google.maps.event.addListener(map, 'click', function(event) {
      if (origin == null) {
        origin = event.latLng;
        addMarker(origin);
      } else if (destination == null) {
        destination = event.latLng;
        addMarker(destination);
      } else {
        if (waypoints.length < 9) {
          waypoints.push({ location: destination, stopover: true });
          destination = event.latLng;
          addMarker(destination);
        } else {
          alert("Maximum number of waypoints reached");
        }
      }
    });
  }

  function addMarker(latlng) {
    markers.push(new google.maps.Marker({
      position: latlng, 
      map: map,
      icon: "http://maps.google.com/mapfiles/marker" + String.fromCharCode(markers.length + 65) + ".png"
    }));    
  }

  function calcRoute() {
    if (origin == null) {
      alert("Click on the map to add a start point");
      return;
    }
    
    if (destination == null) {
      alert("Click on the map to add an end point");
      return;
    }
    
    var mode;
    switch (document.getElementById("mode").value) {
      case "bicycling":
        mode = google.maps.DirectionsTravelMode.BICYCLING;
        break;
      case "driving":
        mode = google.maps.DirectionsTravelMode.DRIVING;
        break;
      case "walking":
        mode = google.maps.DirectionsTravelMode.WALKING;
        break;
    }
    
    var request = {
        origin: origin,
        destination: destination,
        waypoints: waypoints,
        travelMode: mode,
        optimizeWaypoints: document.getElementById('optimize').checked,
        avoidHighways: document.getElementById('highways').checked,
        avoidTolls: document.getElementById('tolls').checked
    };
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
      }
    });
    clearMarkers();
    directionsVisible = true;
  }
  
  function updateMode() {
    if (directionsVisible) {
      calcRoute();
    }
  }
  
  function clearMarkers() {
    for (var i = 0; i < markers.length; i++) {
      markers[i].setMap(null);
    }
  }
  
  function clearWaypoints() {
    markers = [];
    origin = null;
    destination = null;
    waypoints = [];
    directionsVisible = false;
  }
  function reset() {
    clearMarkers();
    clearWaypoints();
    directionsDisplay.setMap(null);
    directionsDisplay.setPanel(null);
    directionsDisplay = new google.maps.DirectionsRenderer();
    directionsDisplay.setMap(map);
    directionsDisplay.setPanel(document.getElementById("directionsPanel2"));    
  }
