/* Lancer la fonction que lorsque la totalité de la page est chargée => évite les erreurs */
$(document).ready( function() 
{
	/* Animation HOME */
	animHom(1); /* Par défaut, on charge l'anim 1 */
	
	$('.onglet').mouseover( function(){
		animHom($(this).attr('value'));
	});
	
	/* Carousel Temoignages (home) */
	jQuery('#carousel-temoignage').jcarousel({
		auto: 10, // Specifies how many seconds to periodically autoscroll the content. If set to 0 (default) then autoscrolling is turned off.
		wrap: 'last',
		scroll: 1,  // The number of items to scroll by.
		initCallback: mycarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
	});
	/* Autre */
});

/* Animation Home */
function animHom( val )
{
	$.ajax({
		type: "POST",
		url: "includes/request.inc.php",
		data: {
			cmd: 'animHome',
			i: val
		},
		success: function(r){	
			$('#home-animation').html(r);
		}
	 });
}

/* Configuration Carousel Temoignages (home) */
function mycarousel_initCallback(carousel)
{
	// Disable autoscrolling if the user clicks the prev or next button.
	carousel.buttonNext.bind('click', function() {
		carousel.startAuto(0);
	});

	carousel.buttonPrev.bind('click', function() {
		carousel.startAuto(0);
	});

	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(
		function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});

    $('#carousel-temoignage-prev').click(function() {
        carousel.prev();
        return false;
    });
	
    $('#carousel-temoignage-next').click(function() {
        carousel.next();
        return false;
    });
}


/* GOOGLE MAPS */
var geocoder;
var map;

function LoadMapSearch(thisAdr, thisCity, thisCp, thisTitle) 
{		
	$(function()
	{
		$("#ggMap").dialog({
			bgiframe: true,
			autoOpen: false,
			minHeight: 430,
			width: 500,
			modal: true,
			resizable: false,
			show: 'blind'
		});
		
		$('#ggMap').dialog('open');

	    geocoder = new google.maps.Geocoder();
	    var latlng = new google.maps.LatLng(48.85667, 2.35099);
	    var myOptions = {
	      zoom: 15,
	      center: latlng,
	      mapTypeId: google.maps.MapTypeId.ROADMAP
	    }
	    map = new google.maps.Map(document.getElementById("ggMap"), myOptions);

	    codeAddress(thisAdr, thisCity, thisCp, thisTitle);
	})
}

function codeAddress(thisAdr, thisCity, thisCp, thisTitle)
{
   // var contentString = "<div style='font-size: 11px;'><b>"+thisTitle+'</b><br />'+thisAdr+'<br />'+thisCp+' - '+thisCity+"</div>";
    var contentString = "<div style='font-size: 11px;'><b>"+thisTitle+"</b></div>";

	var infowindow = new google.maps.InfoWindow({
	    content: contentString
	});
	
    var address = thisAdr+','+thisCp+','+thisCity;
    if (geocoder)
    {
    	geocoder.geocode( { 'address': address}, function(results, status)
    	{
	        if (status == google.maps.GeocoderStatus.OK)
	        {
	          map.setCenter(results[0].geometry.location);
	          var marker = new google.maps.Marker({
	              map: map, 
	              position: results[0].geometry.location,
	              title: thisTitle
	          });
	
	          //google.maps.event.addListener(marker, 'click', function() {
	          	  infowindow.open(map, marker);
	      		//});
	          
	        } else {
	          alert("Geocode was not successful for the following reason: " + status);
	        }
      });
    }
}
