var exp = /([0-9]*)(px|pt) ([0-9]*)(px|pt)/;
var directions;
var map;

function handleErrors(){
  if (directions.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
    alert("Impossible de trouver l'adresse indiqu\351e.\nR\351essayez en sp\351cifiant le num\351ro du d\351partment.\n\nExemple : La Baule, 44");
  else 
    alert("Erreur inconnue lors de la recherche de l'itin\351raire.");
}

$(function() {
  $("a.zoomable").fancybox({
    'overlayShow'    : false,
    'zoomSpeedIn'    : 600,
    'zoomSpeedOut'   : 500,
    'easingIn'       : 'easeOutBack',
    'easingOut'      : 'easeInBack',
    'callbackOnShow' : function() {
                         $(".pricing tbody.selected").removeClass('selected');
                         $("a[title='" + $('#fancy_title_main').text() + "']").parents("tbody").addClass('selected');
                         //$('html, body').animate({scrollTop:$(".pricing .prices tr.selected").offset().top}, 'slow');
                       },
    'callbackOnClose': function() {
                         $(".pricing tbody.selected").removeClass('selected');
                       }
  });
  /*
  var $tabs = $("ul.tabs");
  $("li a", $tabs).click(function(e) {
    $(".pricing .prices tbody").hide();
    $(".pricing .prices tbody." + $(this).attr('hash').substring(1)).show();
  });
  */
  $('#tabs').tabs();
  $('.prices tbody').hover(function() {$(this).addClass('over')}, function() {$(this).removeClass('over')});

  try { 
    if (GBrowserIsCompatible()) {
      var position = new GLatLng(47.279,-2.428);
      map = new GMap2(document.getElementById("gmap"));
      if(map) {
        map.setCenter(new GLatLng(47.279, -2.42), 14);
        map.setMapType(G_SATELLITE_MAP);
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        var marker = new GMarker(position);
        map.addOverlay(marker);
        GEvent.addListener(marker, "click", function() {
          map.openInfoWindowHtml(position, '<img width="200" height="127" src="/img/presquile.jpg"/>', {maxWidth:150});
        });
        //directions = new GDirections(map, document.getElementById("directions"));
        directions = new GDirections(map, document.getElementById("route"));
        GEvent.addListener(directions, "load", function() {});
        GEvent.addListener(directions, "error", handleErrors);
      }
    }
  }
  catch (e) {}
}); 

function showDirections(from) {
  if(from != '') directions.load("from: " + from + " to: 47.279,-2.428");
}

function sendMessage(form) {
  $("button", form).hide();

  var data = "";
  data += "from=" + encodeURIComponent(form.elements['from'].value);
  data += "&body=" + encodeURIComponent(form.elements['body'].value);

  $(form).fadeOut("def", function() {
    var request = GXmlHttp.create();
    request.open("POST", "send.php", true);
    request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    request.onreadystatechange = function() {
      if (request.readyState == 4) {
        if (request.status == 200) $(".statusok").fadeIn();
        else $(".statusko").fadeIn();
      }
    }
    request.send(data);
    try {
      pageTracker._trackEvent('Messages', 'Sent', encodeURIComponent(form.elements['from'].value));
    }
    catch(e) {}
  });
}

 
