/* = fonctions = */
var obj = null;

function checkHover() {
	if (obj) {
		obj.find('ul').fadeOut('fast');	
	} //if
} //checkHover

$(document).ready(function(){
    
    //MENUS
    $("ul#MenuGlobal li ul").hide();
	$('ul#MenuGlobal li').hover(function() {
		if (obj) {
			obj.find('ul.niv2').fadeOut('fast');
			obj = null;
		} //if
		
		$(this).find('ul.niv2').fadeIn('fast');
	}, function() {
		obj = $(this);
		setTimeout(
			"checkHover()",
			600);
	});
    
    // gestion des arrondis de boc K
    $('.rounded').prepend('<div class="tl"></div><div class="tr"></div><div class="bl"></div><div class="br"></div>');
    
    
    /***************************************
     *
     *  Gestion formulaires hébergement
     *
     **************************************/
    //on cache tous les formulaires et on affiche celui pour les hotels
    $(".formu").hide();
    //$(".hotel").show();
    
	$("#navRecherche h2").each(function(){
		if($(this).hasClass("current")){
			
			var id = $(this).attr("id");
			$("#modeRecherche").removeClass();
			$("#modeRecherche").addClass(id);
			//on affiche le formulaire voulu
			$("."+id).show();
			
			//on met à jour la valeur du champ caché type_heb
			$("#type_heb").val(""+id+"");
		}
	});
	
    //gestion clic onglets
    $("#navRecherche h2").click(function(){
        //récupération id de l'onglet cliqué
        var id = $(this).attr("id");
        var type_heb = '';
        
        //on met la classe current sur onglet sélectionné
        $(".ongRech").each(function(){
            $(this).removeClass("current");
        });
        $(this).addClass("current");
        
        //on modifie classe formulaire
        $("#modeRecherche").removeClass();
        $("#modeRecherche").addClass(id);
        
        //on affiche le formulaire voulu
        $(".formu").hide();
        $("."+id).show();
        
        //on met à jour la valeur du champ caché type_heb
        $("#type_heb").val(""+id+"");
		
		
             
    });
	
	/***********************************************page plan d'acces **********************************************/
	if ($('#arrivee').length) {load();}
	$('#btItineraire').click(function(){
		if ($('#depart').val() != '') {
			$('#presentation').hide();
			$('#itineraire').show();
			$('.printPopup').show();
			$('#btRetour').show();
			initialize($('#depart').val(),$('#arrivee').val());
		}
	});
	/***********************************************fin page plan d'acces **********************************************/
});

$(document).unload(function(){
	/***********************************************page plan d'acces **********************************************/
	GUnload();
	/***********************************************fin page plan d'acces **********************************************/
});

// fonction google maps
function load() {
      if (GBrowserIsCompatible()) {
	  	if ($('#lattitude').val()!="" && $('#longitude').val()!="") {
			var map = new GMap2(document.getElementById("map"));
			map.addControl(new GSmallMapControl());
			var position = new GLatLng($("#lattitude").val(),$("#longitude").val());
			var marker = new GMarker(position);
			map.addOverlay(marker);
			map.setCenter(position, 13);
			//marker.openInfoWindowHtml("Emplacement de votre magasin");
		} else {
			var map = new GMap2(document.getElementById("map"));
			map.addControl(new GSmallMapControl());
			map.setCenter(new GLatLng(47.856667,  2.350987), 6);			
		}
		
		
      }
}

function initialize(depart,arrivee) {
  map2 = new GMap2(document.getElementById("map"));
  directionsPanel = document.getElementById("itineraire");
  map2.setCenter(new GLatLng($("#lattitude").val(),$("#longitude").val()), 10);
  directions = new GDirections(map2, directionsPanel);
  directions.load('from: '+depart+' to: '+arrivee, {"locale": "fr"});

}

function createPlayer(thePlaceholder, thePlayerId, theFile, theImage) {
	var flashvars = {
		file : theFile,
		image : theImage
	}
	var params = {
		allowfullscreen : "false",
		wmode : "transparent"
	}
	var attributes = {
		id : thePlayerId,
		name : thePlayerId
	}
	swfobject.embedSWF("/global/swf/flvplayer.swf", thePlaceholder, "500",
			"302", "9.0.115", false, flashvars, params, attributes);
}

