$(document).ready(function(){
	setTimeout('afficherContenu()', 50);
	nbImage = $("#top .bg_img").size();
	setInterval("nextImage()",5000);
});


var current_img = 0;
var nbImage = 0;
function changerImage(id){
	$("#top .bg_img").eq(current_img).fadeOut(1000);
	current_img = id;
	$("#top .bg_img").eq(current_img).fadeIn(1000);
}

function nextImage(){
	next_img = current_img + 1;
	if(next_img>=nbImage){
		next_img = 0;
	}
	else if(next_img+1 < nbImage) {
		var next = 	$("#top .bg_img").eq(next_img+1);
		var src = next.attr("src_tmp");
		//alert(src+" "+next_img);
		if(src && src.length > 0)
			next.attr("src", src);
	}
	changerImage(next_img);
}

function manif_suivante(){
	
	if(current_manif == (nbManifs-2)){
		//$('#div_defilant').css('margin-left', '0px');
		current_manif=0;
	}
	else
	{
//		$('#div_defilant').css('margin-left', '-166px');
		current_manif++;
	}
	anime_manif(current_manif);
}
function manif_precedente(){
	
	if(current_manif == 0){
		current_manif=(nbManifs-2);
	}
	else
	{
		current_manif--;
	}
	anime_manif(current_manif);
}
function anime_manif(pos) {
	pos = -166*pos;
	$('#div_defilant').animate({marginLeft:pos}, {queue:false});
}

var latlng = null;
var latlng2 = null;
var myOptions = null;

var latitude = 48.651944;
var longitude = 7.698611;

var gmarkers = [];
var htmls = [];
var to_htmls = [];
var from_htmls = [];
var i=0;

var map=null;
var marker=null;

function createMarker(point,name,html) {

	html = html + '<div id="bulle_m'+i+'" class="bulleGM" ><a href="javascript:tohere('+i+')" title="Vers Lampertheim">Itin&eacute;raire vers Lampertheim</a><br/><br/><a href="javascript:fromhere('+i+')" title="Depuis Lampertheim">Itin&eacute;raire depuis Lampertheim</a></div><br /></div>' +
	
		'<div id="bulle_t'+i+'" class="bulleGM" style="display:none;overflow:visible;" ><span style="color:black">Lieu de d&eacute;part:</span><form action="http://maps.google.fr/maps" method="get" target="_blank" style="margin:0px;padding:0px;" >' +
	'<input type="text" SIZE=20 MAXLENGTH=40 name="saddr" id="saddr" value="" style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:12px;color:#000000;" />' +
	'<INPUT value="Envoyer" TYPE="SUBMIT" style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:12px;color:#000000;margin-left:3px;">' +
	'<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() +
	'"/>&nbsp;<a href="#" onclick="general_bulleGM();return false;" >&raquo; revenir</a></form></div>' +
	
	'<div id="bulle_f'+i+'" class="bulleGM" style="height:40px;display:none;overflow:visible;" ><span style"color:black">Lieu d\'arriv&eacute;e:</span><form action="http://maps.google.fr/maps" method="get"" target="_blank" style="margin:0px;padding:0px;">' +
	'<input type="text" SIZE=20 MAXLENGTH=40 name="daddr" id="daddr" value="" style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:12px;color:#000000;" />' +
	'<INPUT value="Envoyer" TYPE="SUBMIT" style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:12px;color:#000000;margin-left:3px;">' +
	'<input type="hidden" name="saddr" value="' + point.lat() + ',' + point.lng() +
	'"/>&nbsp;<a href="#" onclick="general_bulleGM();return false;" >&raquo; revenir</a></form></div>';

	html = "<div style='width:300px'>" + html +"</div>";
	var infowindow = new google.maps.InfoWindow({
		content: html
	});
	
	marker = new google.maps.Marker({
		position: latlng,
		map: map,
		title:""
	});
	infowindow.open(map,marker);
	
	google.maps.event.addListener(marker, 'click', function() {
		$(".bulleGM").each(function() {this.style.display = ((this.id.indexOf("bulle_m")==0)?"block":"none");});
		infowindow.open(map,marker);
	});

	gmarkers[i] = marker;
	htmls[i] = html;
	i++;
	return marker;
}

function general_bulleGM() {
	$(".bulleGM").each(function() {this.style.display = ((this.id.indexOf("bulle_m")==0)?"block":"none");});
}

function tohere(i) {
	$(".bulleGM").each(function() {this.style.display = ((this.id.indexOf("bulle_t")==0)?"block":"none");});
}

function fromhere(i) {
	$(".bulleGM").each(function() {this.style.display = ((this.id.indexOf("bulle_f")==0)?"block":"none");});
}


function base_url() {
	if(document.domain.indexOf("hdrsw11.com") != -1)
		return "";
	return "";
}

function afficherContenu(){
	
	document.getElementById("global").style.display = 'block';
	document.getElementById("text_fil_info").style.backgroundImage='url(/images/fond_fil_infos.gif)';
	document.getElementById("text_fil_info").style.color='#58585a';
	document.getElementById("text_fil_info").style.border.right="1px solid #b3b4b6";
	document.getElementById("titre_fil_info").style.backgroundImage='url(/images/titre_fil_info.png)';
	
	(function() {
		var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	  })();

	
	
	if(afficherMap){
		latlng = new google.maps.LatLng(latitude,longitude);
		latlng2 = new google.maps.LatLng((latitude+0.13),longitude);
		myOptions = {
		  zoom: 10,
		  center: latlng2,
		  mapTypeId: google.maps.MapTypeId.ROADMAP 
		}
		map = new google.maps.Map(document.getElementById("GoogleMap"), myOptions);
		createMarker(latlng,"hdr", contenuMarqueur);
	}
	
	egalize_column();
	
}

function egalize_column() {
	var left_hei = $("#left_page").height();
	$("#contenu_main").css("min-height", (left_hei - 50));
}

function zoom_moins(){
	//alert("diminuer la taille du texte ! A FAIRE !!!!");
	var reg = new RegExp("px", "g");
	var tailleActuelle = document.body.style.fontSize;
	tailleActuelle = Number(tailleActuelle.replace(reg, ""));
			
	if(tailleActuelle>9){
		var newTaille = tailleActuelle-1;
		document.body.style.fontSize = newTaille + 'px';
	}else{
		var newTaille = tailleActuelle;
	}
	cookieTaille(newTaille);
}

function zoom_plus(){
	//alert("agrandir la taille du texte ! A FAIRE !!!!");
	var reg = new RegExp("px", "g");
	var tailleActuelle = document.body.style.fontSize;
	tailleActuelle = Number(tailleActuelle.replace(reg, ""));
			
	if(tailleActuelle<16){
		var newTaille = tailleActuelle+1;
		document.body.style.fontSize = newTaille + 'px';
	}else{
		var newTaille = tailleActuelle;
	}
	cookieTaille(newTaille);
}


function cookieTaille(newTaille){	
	//Cufon.set('fontFamily', 'Eurostyle_Ext').replace('.eur_ext', {hover:true});
	Cufon.set('fontFamily', 'Eurostyle').replace('.eur, .fc', {hover:true});
	egalize_column();
	$.post('/cookieTaille.php',
		{
			taille:newTaille
		}
	);
}

function afficheGalerie(id){
	
	
	$('#liste_album').hide();
	var galerie_photos = new SWFObject('/flash/imagerotator.swf', 'GaleriePhotos', '580', '435', '9');
	galerie_photos.addParam("allowfullscreen","true");
	galerie_photos.addParam("wmode","transparent");
	galerie_photos.addVariable('showNavigation', 'true');
	galerie_photos.addVariable('file', '/flash/imageRotator.php?album='+id);
	galerie_photos.addVariable('width', '580');
	galerie_photos.addVariable('height', '435');
	galerie_photos.addVariable('displaywidth', '580');
	galerie_photos.addVariable('displayheight', '435');
	galerie_photos.addVariable('screencolor', '0xffffff');
	//galerie_photos.addVariable('bgcolor', '0xffffff');
	galerie_photos.addVariable('largecontrols', 'true');
	galerie_photos.addVariable('showdigits', 'true');
	galerie_photos.addVariable('showicons', 'true');
	galerie_photos.addVariable('shuffle', 'false');
	galerie_photos.addVariable('transition', 'none');
	galerie_photos.addVariable('rotatetime', '4');
	galerie_photos.write('Galerie_Photos');
	$.post('/ajax/galerie.php',{album:id}, function(data) {
		  $('#nom_album').html(data);
		  $('#Rotator').fadeIn(500);
	});
	
}

function retour_galerie() {
	$('#Rotator').hide();
	$('#nom_album').innerHTML = '';
	$('#liste_album').fadeIn(500);
}
