function oninit1(){
  defActionOngletsFiche();
  afficheOngletsPresents();
  defActionOngletsFichePhotoVideo();
}

function defActionOngletsFiche(){
  $$(".li_ongletFiche").each(function(obj){
    obj.onclick=function(evt){
      ongletAff = obj.getAttribute("onglet");
      affOngletFiche(ongletAff);
      $$(".li_ongletFiche").each(function(obj2){
        if(obj2.hasClassName("li_ongletFicheOn")) obj2.removeClassName("li_ongletFicheOn");
      });
      obj.addClassName("li_ongletFicheOn");
    };
  });
}

function defActionOngletsFichePhotoVideo(){
  $$(".li_ongletFichePhoto").each(function(obj){
    obj.onclick=function(evt){
      ongletAff = obj.getAttribute("onglet");
      affOngletFichePhoto(ongletAff);
      $$(".li_ongletFichePhoto").each(function(obj2){
        if(obj2.hasClassName("li_ongletFichePhotoOn")) obj2.removeClassName("li_ongletFichePhotoOn");
      });
      obj.addClassName("li_ongletFichePhotoOn");
    };
  });
}

function affOngletFiche(onglet){
  $$(".div_unOnglet").each(function(obj){
    if(obj.hasClassName("div_unOngletActif")) obj.removeClassName("div_unOngletActif");
  });
  $(onglet).addClassName("div_unOngletActif");
}
function affOngletFichePhoto(onglet){
  $$(".div_fichePhotoVideo").each(function(obj){
    obj.style.display="none";
  });
  $(onglet).style.display="block";
}

function afficheOngletsPresents(){
  if($("div_ficheDistances")) $("bt_ongletLoisirs").style.display="inline";
  if($("div_fiche_tarif_v2")) $("bt_ongletTarifs").style.display="inline";
  if($("div_fiche_detailPromo")) $("bt_ongletPromo").style.display="inline";
  if($("div_fiche_contacts_v3")) $("bt_ongletContact").style.display="inline";
  if($("rub_thema")) $("bt_ongletThemes").style.display="inline";
  if($("rub_lacs")) $("bt_ongletLacs").style.display="inline";
  if($("rub_massif")) $("bt_ongletLacs").style.display="inline";
  if($("rub_stations")) $("bt_ongletSki").style.display="inline";
  if($("div_fiche_acces_plan")) $("bt_ongletItineraire").style.display="inline";
  if($("div_fiche_planInterieur")) $("bt_ongletPlan").style.display="inline";
  if($("div_fiche_youtube") || $("div_fiche_dailymotion")) $("div_fiche_ongletPhotoVideo").style.display="block";
}

/************** **************/
var map;
var gdir;
 function loadItineraire() {
     if (GBrowserIsCompatible()) {      
         map = new GMap2($("div_map_directions"));
         gdir = new GDirections(map,$("div_fiche_directions"));
         GEvent.addListener(gdir, "error", handleErrors);
     }
}
    
function setDirections(fromAddress, toAddress, locale) {
    gdir.load("from: " + fromAddress + " to: " + toAddress,{ "locale": locale,"preserveViewport":false });
    map.setZoom(9);
    map.checkResize();
}

function handleErrors(){
    if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS ||  gdir.getStatus().code == G_GEO_BAD_REQUEST)$("div_fiche_directions").update("Aucune correspondance g&eacute;ographique trouv&eacute;e");
	else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)$("div_fiche_directions").update("Serveur de g&eacute;olocalisation non disponible");
	     else $("div_fiche_directions").update("Une erreur est survenue");
}

function affDetailItineraire(){
  if(($("fromAddress").value)&&($("fromAddress").value!="Votre adresse de départ")){
    $("div_fiche_directions").style.display="block";
    $("div_map_directions").style.display="block";
    loadItineraire();
    if (map) setDirections($('fromAddress').value, $('toAddress').value);
  }
  else alertAMalibu("Vous devez saisir une adresse de départ pour calculer votre itinéraire !");
}
