// JavaScript Document

function coord()
{
	 function file(fichier)
	 {
		 if(window.XMLHttpRequest) // FIREFOX
			  xhr_object = new XMLHttpRequest();
		 else if(window.ActiveXObject) // IE
			  xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		 else
			  return(false);
		 xhr_object.open("GET", fichier, false);
		 xhr_object.send(null);
		 if(xhr_object.readyState == 4) return(xhr_object.responseText);
		 else return(false);
	 }
	 param=window.location.href;
	 
	 get=param.split("!");
	 get=get[1].split("$");
	
	 posCoord=file('http://sandbox2.einden.com/coord_google.php?id='+get[0]);
	 
	 result=posCoord.split("|");
	 init_map();	 
}

//initialisation des google maps
function init_map()
{	
	if ($('#map2').length==0) {
		return false;
	}
	
	if ($('#coord_lat,#coord_lng').length==2) {
		var lat = $('#coord_lat').val();
		var lng = $('#coord_lng').val();
	}
	else {
		var lat = result[0];//document.getElementById('lat').innerHTML;
		var lng = result[1];//document.getElementById('lng').innerHTML;
	}

	//Creation d'un objet coordonnees
	var maCarte = new google.maps.LatLng(lat,lng);
	/*<!-- Les options de notre carte -->
	<!--   - zoom : coÃ©fficient du zoom -->
	<!--   - center : centrage de la carte -->
	<!--   - mapTypeId : type de carte -->
	<!--   - disableDefaultUI: true, pour dÃ©sactiver les boutons de la cart -->*/
	var myOptions =	{
		zoom: 12,
		center: maCarte,
		disableDefaultUI: true,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	
	//creation de la carte
	var map = new google.maps.Map(document.getElementById('map2'), myOptions);
	
	//creation du marqueur
	var imageMarker= new google.maps.MarkerImage('http://sandbox2.einden.com/images/home.png', new google.maps.Size(32,32), new google.maps.Point(0,0), new google.maps.Point(32,16)); 
	var optionMarker = {
		map:map,
		position:maCarte,
		icon:imageMarker
	};
	var marker=new google.maps.Marker(optionMarker);
}

function formatText(index, panel) {
	  return index + "";
};

//initialisation des diaporamas des annonces
function init_slider() {
	$('.anythingSlider').anythingSlider({
		easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
		autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
		delay: 3000,                    // How long between slide transitions in AutoPlay mode
		startStopped: false,            // If autoPlay is on, this can force it to start stopped
		animationTime: 600,             // How long the slide transition takes
		hashTags: true,                 // Should links change the hashtag in the URL?
		buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
		pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
		startText: "Go",                // Start text
		stopText: "Stop",               // Stop text
		navigationFormatter: formatText // Details at the top of the file on this use (advanced use)
	});
}

//initialisation du déroulements pour les listes d'acualités
function init_foldActu() {
	var $titres = $('.titre_page[idarticle]');
	if ($titres.length > 1)	{
		for (var i=0; i<$titres.length; i++) {
			var $titre = $titres.eq(i);
			
			//récupération du h1 présent dans le titre
			var $h1 = $titre.find('h1');
			//création d'un écouteur sur le h1 présent dans le titre
			$h1.click(function() {
				var idarticle = $(this).parent().attr('idarticle');
				var $contenu = $('div.contenu[idarticle='+idarticle+']');
				if ($contenu.css('display') == 'none') {
					$contenu.slideDown(100);
				}
				else {
					$contenu.slideUp(100);
				}
			});
			$h1.css('cursor', 'pointer');
			
			//récupération du contenu correspondant
			var $contenu = $('div.contenu[idarticle='+$titre.attr('idarticle')+']');
			$contenu.hide();
		}
	}
}
