var debutDiaporama=0;
var sauvValue='';

$(window).load(function()
{	
	//Défilement Page d'accueil
	$('#nvconcept').everyTime(5000, 'animation', function()
	{	
		$('#photoAccueil'+imgActu).fadeOut(1000);
		$('#photoAccueilDesc'+imgActu).fadeOut(1000);
		if(imgActu==nbImages)
		{
			imgActu=1;
		}
		else
		{
			imgActu++;
		}
		$('#photoAccueil'+imgActu).fadeIn('slow');
		$('#photoAccueilDesc'+imgActu).fadeIn('slow');
	});
	
	//Click Animation
	$('#playerAnim img').click(function()
	{
		if($(this).attr('src')=='LoreeSkel/images/ico-pause.jpg')
		{
			$('#nvconcept').stopTime('animation');
			$(this).attr('src', 'LoreeSkel/images/ico-play.jpg');
		}
		else if($(this).attr('src')=='LoreeSkel/images/ico-play.jpg')
		{
			$(this).attr('src', 'LoreeSkel/images/ico-pause.jpg');
			
			$('#nvconcept').everyTime(4000, 'animation', function()
			{	
				$('#photoAccueil'+imgActu).fadeOut(1000);
				$('#photoAccueilDesc'+imgActu).fadeOut(1000);
				if(imgActu==nbImages)
				{
					imgActu=1;
				}
				else
				{
					imgActu++;
				}
				$('#photoAccueil'+imgActu).fadeIn('slow');
				$('#photoAccueilDesc'+imgActu).fadeIn('slow');
			});
			
		}		
	});
	
	//Régler hauteur Bulle		
	hauteur=($('.contenuBulleCentre').height());
	$('.contenuBulleCentre').css('height', hauteur-20+'px');
	
	//Régler hauteur sous Rubrique
	hauteur2=($('.contenuBulleBas2Centre').height());	
	$('.contenuBulleBas2Centre').css('height', hauteur2-20+'px');
	
	if($.browser.msie && $.browser.version=='8.0')
	{
		$('#lesPieces').css('letter-spacing', '0.62em');
		$('#lesPieces').css('padding-left', '2px');		
	}
	
	if($.browser.msie && $.browser.version=='7.0')
	{		
		$('.blocRecherche input[type=text]').css('height', '11px');
		$('#menu A.menu').css('height', '20px');
		$('.annonceDescriptifInfos').css('line-height', '18px');
		$('.annonceRdz').css('line-height', '18px');
		$('.contenuBulleTitreAnnonce').css('margin-left', '-5px');
		$('.contenuBulleTitreIcone').css('margin-left', '-10px');
		$('.contenuBulleTitreCentre').css('padding-left', '30px');
		$('#lesPieces').css('letter-spacing', '6px');
		$('.ie60').css('width', '40px');
		$('.ie61').css('width', '110px');
		$('.ie62').css('width', '80px');
		$('.ie63').css('width', '80px');
		$('.ie64').css('width', '130px');
		$('.ie65').css('width', '75px');
	}
	
	if($.browser.msie && $.browser.version=='6.0')
	{
		$('.menu').css('text-align', 'center');
		$('.menu').css('line-height', '13px');
		$('.ie60').css('width', '40px');
		$('.ie61').css('width', '110px');
		$('.ie62').css('width', '80px');
		$('.ie63').css('width', '80px');
		$('.ie64').css('width', '130px');
		$('.ie65').css('width', '75px');
		$('.nvagueTexte').css('position', 'relative');
		$('.nvagueTexte').css('padding-top', '195px');
		$('.listeTitrePhoto').css('line-height', '9px');
		$('.listePhoto').css('margin-top', '-31px');
		$('#ie6Piscine').css('margin-left', '6px');
		$('#ie6Piscine').css('margin-top', '1px');
		$('#ie6Piscine').css('width', '94px');
	}
	
	if($.os.name='mac' && $.browser.safari)
	{
		$('#macCarre').css('text-indent', '5px');
	}
	
	//Contact
	$('#formContact').submit(function()
	{
	
		$.ajax({
			type:"POST",
			url:"/spip.php?page=ajax-contact&var_mode=recalcul",
			data:"nom="+$('#contactNom').val()+"&email="+$('#contactEmail').val()+"&telephone="+$('#contactTelephone').val()+"&cp="+$('#contactCp').val()+"&sujet="+$('#contactSujet').val()+"&message="+escape($('#contactTexte').val()),
			success: function(msg)
			{
				$.nyroModalManual({
					bgColor: '#E2E0E5',
					minHeight:0,
					content: msg,
					cssOpt: 
					{ 
						wrapper: 
						{							
							width:'900px',
							padding: '0px',
							marginTop: '-160px'
						}
					}
				});
			}
		});
		 
		return false;
	});
	
	//Contact
	$('#formParrainage').submit(function()
	{
	
		$.ajax({
			type:"POST",
			url:"/spip.php?page=ajax-partenaire&var_mode=recalcul",
			data:	"mr="+addslashes($('#partenaireMr').val())+
					"&mme="+addslashes($('#partenaireMme').val())+
					"&mlle="+addslashes($('#partenaireMlle').val())+
					"&nom="+addslashes($('#partenaireNom').val())+
					"&prenom="+addslashes($('#partenairePrenom').val())+
					"&adresse1="+addslashes($('#partenaireAdresse1').val())+
					"&cp="+addslashes($('#partenaireCp').val())+
					"&ville="+addslashes($('#partenaireVille').val())+
					"&email="+addslashes($('#partenaireEmail').val())+
					"&tel="+addslashes($('#partenaireTel').val())+
					"&fnom="+addslashes($('#partenaireFilleulNom').val())+
					"&fprenom="+addslashes($('#partenaireFilleulPrenom').val())+
					"&femail="+addslashes($('#partenaireFilleulEmail').val())+
					"&ftel="+addslashes($('#partenaireFilleulTel').val())+
					"&appartement="+addslashes($('#partenaireAppartement').val())+
					"&maison="+addslashes($('#partenaireMaison').val())+
					"&terrain="+addslashes($('#partenaireTerrain').val())+
					"&local="+addslashes($('#partenaireLocal').val())+
					"&terrasse="+addslashes($('#partenaireTerrasse').val())+
					"&garage="+addslashes($('#partenaireGarage').val())+
					"&jardin="+addslashes($('#partenaireJardin').val())+
					"&piscine="+addslashes($('#partenairePiscine').val())+
					"&garageM="+addslashes($('#partenaireGarageMaison').val())+
					"&p1="+addslashes($('#partenairePiece1').val())+
					"&p2="+addslashes($('#partenairePiece2').val())+
					"&p3="+addslashes($('#partenairePiece3').val())+
					"&p4="+addslashes($('#partenairePiece4').val())+
					"&p5="+addslashes($('#partenairePiece5').val())+
					"&surface="+addslashes($('#partenaireSurface').val())+
					"&adresse2="+addslashes($('#partenaireAdresse2').val())+
					"&localisation="+addslashes($('#partenaireLocalisation').val()),					
			success: function(msg)
			{
				$.nyroModalManual({
					bgColor: '#E2E0E5',
					minHeight:0,
					content: msg,
					cssOpt: 
					{ 
						wrapper: 
						{
							width:'900px',
							padding: '0px',
							marginTop: '-160px'
						}
					}
				});
			}
		});
		 
		return false;
	});
	
	//Vendre
	$('#formVendre').submit(function()
	{		
		if($('#vendreEmail').val()=='' || $('#vendreEmail').val()=='Email*' || $('#vendreAdresse').val()=='' || $('#vendreAdresse').val()=='Adresse postale' || $('#vendreCP').val()=='' || $('#vendreCP').val()=='Code postal*')
		{
			alert('Ces champs sont obligatoires :\n - Email\n - Adresse\n - Code postal\n ');
		}
		else
		{
			$.ajax({
				type:"POST",
				url:"/spip.php?page=ajax-vendre&var_mode=recalcul",
				data:
						"type="+$('#vendreVenteLocation').val()+
						"&appartement="+$('#vendreAppartement').attr('checked')+
						"&maison="+$('#vendreMaison').attr('checked')+
						"&terrain="+$('#vendreTerrain').attr('checked')+
						"&local="+$('#vendreLocal').attr('checked')+
						"&1p="+$('#vendrePiece1').attr('checked')+
						"&2p="+$('#vendrePiece2').attr('checked')+
						"&3p="+$('#vendrePiece3').attr('checked')+
						"&4p="+$('#vendrePiece4').attr('checked')+
						"&5p="+$('#vendrePiece5').attr('checked')+
						"&garageAppartement="+$('#vendreGarage').attr('checked')+
						"&garageMaison="+$('#vendreGarageMaison').attr('checked')+
						"&jardin="+$('#vendreJardin').attr('checked')+
						"&terrasse="+$('#vendreTerrasse').attr('checked')+
						"&piscine="+$('#vendrePiscine').attr('checked')+
						"&budgetMin="+$('#vendrePrixMin').val()+
						"&budgetMax="+$('#vendrePrixMax').val()+
						"&surfaceMin="+$('#vendreSurfaceMin').val()+
						"&surfaceMax="+$('#vendreSurfaceMax').val()+
						"&localisation="+$('#vendreLocalisation').val()+
						"&email="+$('#vendreEmail').val()+
						"&telephone="+$('#vendreTelephone').val()+
						"&cp="+$('#vendreCP').val()+
						"&ville="+$('#vendreVille').val()+
						"&adresse="+escape($('#vendreAdresse').val()),
				success: function(msg)
				{
					$.nyroModalManual({
						bgColor: '#E2E0E5',					
						content: msg,
						minHeight:0,
						cssOpt: 
						{ 
							wrapper: 
							{
								width:'900px',
								padding: '0px',
								marginTop: '-160px'
							}
						}
					});					
				}
			});
		}
		 
		return false;
	});			
	
	$('.input_text input').blur(function()
	{	
		if($(this).val()=='')
		{
			nomInput=$(this).attr('name');
			
			switch(nomInput)
			{
				case 'recherche_prixMin':
					$(this).val('Budget mini');
					break;
				case 'recherche_prixMax':
					$(this).val('Budget maxi');
					break;
				case 'recherche_cp':
					$(this).val('Code postal');
					break;
				case 'recherche_ville':
					$(this).val('Ville');
					break;
				case 'contact_sujet':
					$(this).val('Sujet');
					break;
				case 'contact_nom':
					$(this).val('Nom / Pr\351nom');
					break;
				case 'contact_email':
					$(this).val('Email');
					break;
				case 'contact_telephone':
					$(this).val('T\351l\351phone');
					break;
				case 'contact_cp':
					$(this).val('Code postal');
					break;
				case 'vendre_nom':
					$(this).val('Nom');
					break;
				case 'vendre_telephone':
					$(this).val('T\351l\351phone');
					break;
				case 'vendre_email':
					$(this).val('Email*');
					break;
				case 'vendre_cp':
					$(this).val('Code postal*');
					break;
				case 'vendre_adresse':
					$(this).val('Adresse postale*');
					break;
				case 'vendre_ville':
					$(this).val('Ville');
					break;
			}
		}
	});
	
	$('.blocRecherche label').click(function()
	{		
		imageActuelle=$('#'+$(this).attr('for')+'Img').attr('src');
		if(imageActuelle=='LoreeSkel/images/input-marron-off.jpg')
		{
			$('#'+$(this).attr('for')+'Img').attr('src', 'LoreeSkel/images/input-marron-on.jpg');
			$('#'+$(this).attr('for')).attr('value', 'on');
		}
		
		if(imageActuelle=='LoreeSkel/images/input-marron-on.jpg')
		{
			$('#'+$(this).attr('for')+'Img').attr('src', 'LoreeSkel/images/input-marron-off.jpg');
			$('#'+$(this).attr('for')).attr('value', '');
		}
		
		if(imageActuelle=='LoreeSkel/images/input-blanc-off.jpg')
		{
			$('#'+$(this).attr('for')+'Img').attr('src', 'LoreeSkel/images/input-blanc-on.jpg');
			$('#'+$(this).attr('for')).attr('value', 'on');
		}
		
		if(imageActuelle=='LoreeSkel/images/input-blanc-on.jpg')
		{
			$('#'+$(this).attr('for')+'Img').attr('src', 'LoreeSkel/images/input-blanc-off.jpg');
			$('#'+$(this).attr('for')).attr('value', '');
		}
	});
	
	
	//Les coups de coeur
	$('.itemCC:last-child').css('padding-right:0px;');
	
	$('#ccPrecedent').click(function()
	{
		if(parseInt($('#listeCC').css('margin-left'))+369==0)
		{
			$('#ccPrecedent').css('visibility', 'hidden');
		}
		
		if(parseInt($('#listeCC').css('margin-left'))!=0)
		{
			$('#ccSuivant').css('visibility', 'visible');
			$('#listeCC').animate({marginLeft:parseInt($('#listeCC').css('margin-left'))+369}, 'normal');
		}
	});
	
	$('#ccSuivant').click(function()
	{
		if(parseInt($('#listeCC').css('margin-left'))-369==maxPixel*-1)
		{
			$('#ccSuivant').css('visibility', 'hidden');
		}
		
		//alert(parseInt($('#listeCC').css('margin-left')) + ' : ' + maxPixel*-1);
		
		if(parseInt($('#listeCC').css('margin-left'))!=(maxPixel*-1))
		{
			$('#ccPrecedent').css('visibility', 'visible');
			debutDiaporama+=3;
			$.ajax({
				type:"POST",
				url:"/spip.php?page=ajax-cc&var_mode=recalcul",
				data:"deb="+debutDiaporama,
				success: function(msg)
				{
					$('#listeCC').html($('#listeCC').html()+msg);
					$('#listeCC').animate({marginLeft:parseInt($('#listeCC').css('margin-left'))-369}, 'normal');
				}
			});
		}
	});
	
	$('#ccPrecedentG').click(function()
	{
		if(parseInt($('#listeCC').css('margin-left'))+534==0)
		{
			$('#ccPrecedentG').css('visibility', 'hidden');
		}
		
		if(parseInt($('#listeCC').css('margin-left'))!=0)
		{
			$('#ccSuivantG').css('visibility', 'visible');
			$('#listeCC').animate({marginLeft:parseInt($('#listeCC').css('margin-left'))+534}, 'normal');
		}
	});
	
	$('#ccSuivantG').click(function()
	{
		
		if(parseInt($('#listeCC').css('margin-left'))-534==maxPixel*-1)
		{
			$('#ccSuivantG').css('visibility', 'hidden');
		}	
		
		if(parseInt($('#listeCC').css('margin-left'))!=(maxPixel*-1))
		{
			$('#ccPrecedentG').css('visibility', 'visible');
			//$('#listeCC').html($('#listeCC').html()+msg);
			$('#listeCC').animate({marginLeft:parseInt($('#listeCC').css('margin-left'))-534}, 'normal');
			//debutDiaporama+=5;			
			/*$.ajax({
				type:"POST",
				url:"/spip.php?page=ajax-cc&var_mode=recalcul",
				data:"deb="+debutDiaporama,
				success: function(msg)
				{
					
				}
			});*/
		}
	});
	
	$('.annoncePhotoListeItem:first-child').css('background-image', 'url(/LoreeSkel/images/fond-photo-on.jpg)');
	
	
	$('.annoncePhotoListeItem').mouseover(function()
	{
		$('.annoncePhotoListeItem').css('background-image', 'url(/LoreeSkel/images/fond-photo.jpg)');
		$('.photoCache').hide();
		
		$(this).css('background-image', 'url(/LoreeSkel/images/fond-photo-on.jpg)');
		$('.annoncePhotoPrincipale'+substr($(this).attr('id'), 12)).show();
	});
	
	
	//Liste des annonces
	$('.listeAnnonceItem:first-child').css('background-image', 'url(/LoreeSkel/images/fond-photo-on.jpg)');
	
	$('.listeAnnonceItem').click(function()
	{
		$('.listeAnnonceItem').css('background-image', 'url(/LoreeSkel/images/fond-photo.jpg)');		
		$(this).css('background-image', 'url(/LoreeSkel/images/fond-photo-on.jpg)');
		
		$.ajax({
			type:"POST",
			url:"/spip.php?page=ajax-annonce-liste&var_mode=recalcul",
			data:"id="+substr($(this).attr('id'), 7),
			success: function(msg)
			{
				$('#listeDescription').html(msg);
			}
		});
	});
	
	//Les news
	nNews=0;	
	$('#newsPrec').click(function()
	{	
		newsMaintenant=nNews-1;
		$.ajax({
			type:"POST",
			url:"/spip.php?page=ajax-news&var_mode=recalcul",
			data:"debut="+newsMaintenant,
			success: function(msg)
			{
				$('#blocNews').fadeOut(function()
				{
					$('#blocNews').html(msg);
					$('#blocNews').fadeIn();
					$('#newsSuiv').css('visibility', 'visible');
					nNews--;
					if(nNews==0)
					{
						$('#newsPrec').css('visibility', 'hidden');
					}
				});
			}
		});
	});	
	
	$('#newsSuiv').click(function()
	{			
		newsMaintenant=nNews+1;		
		$.ajax({
			type:"POST",
			url:"/spip.php?page=ajax-news&var_mode=recalcul",
			data:"debut="+newsMaintenant,
			success: function(msg)
			{				
				$('#blocNews').fadeOut(function()
				{
					$('#blocNews').html(msg);
					$('#blocNews').fadeIn();
					$('#newsPrec').css('visibility', 'visible');
					nNews++;					
					if(parseInt(maxNews)==(nNews+1))
					{
						$('#newsSuiv').css('visibility', 'hidden');
					}
				});
			}
		});
	});
	
	//Afficher googlemap
	$('#annonceLocaliser').click(function()
	{
		localisation=$(this).attr('hidden');
		$.ajax({
			type:"POST",
			url:"/spip.php?page=ajax-localisation&var_mode=recalcul",
			data:"param="+escape(localisation),
			success: function(msg)
			{
				$.nyroModalManual({
					bgColor:'#E2E0E5',				
					content:msg,
					width:620,
					height:340,
					cssOpt: 
					{ 
						wrapper: 
						{
							height:'400px',
							width:'900px',
							padding: '0px',
							marginTop: '-160px'
						}
					},										
					endShowContent: function(elts, settings) {
						localiserAnnonce(localisation);
					}
				});
			}
		});
	});
	
	
	//Régler la hauteur des infos dans la page annonce
	hauteur1=$('.annonceDescriptifInfos').height();
	hauteur2=$('.annonceDescriptifInfos2').height();
	hauteur3=$('.annonceDescriptifInfos3').height();
	
	if(hauteur1<hauteur2)
	{
		hauteurMax=hauteur2;
	}
	else
	{
		hauteurMax=hauteur1;
	}
	
	if(hauteurMax<hauteur3)
	{
		hauteurMax=hauteur3;
	}
	
	$('.annonceDescriptifInfos').css('height', hauteurMax+'px');
	$('.annonceDescriptifInfos2').css('height', hauteurMax+'px');
	$('.annonceDescriptifInfos3').css('height', hauteurMax+'px');
	
	//Rollover
	$('#savoirPlus').mouseover(function()
	{
		$('#savoirPlusInfos').show();
	});
	
	$('#savoirPlus').mouseout(function()
	{
		$('#savoirPlusInfos').hide();
	});
	
	$('#btnLocataire').click(function()
	{
		$('#btnProprietaire img').attr('src', '/LoreeSkel/images/btn-proprietaire-off.jpg');
		$('img', this).attr('src', '/LoreeSkel/images/btn-locataire-on.jpg');
		
		$('#proprietaire').fadeOut(function()
		{
			$('#locataire').fadeIn('normal');
		});	
	});
	
	$('#btnProprietaire').click(function()
	{
		$('#btnLocataire img').attr('src', '/LoreeSkel/images/btn-locataire-off.jpg');	
		$('img', this).attr('src', '/LoreeSkel/images/btn-proprietaire-on.jpg');
		
		$('#locataire').fadeOut(function()
		{
			$('#proprietaire').fadeIn('normal');
		});		
	});
	
});

function localiserAnnonce(address)
{		
	var map = new GMap2(document.getElementById("map"));
	var geocoder = new GClientGeocoder();

	if (geocoder)
	{
		geocoder.getLatLng(address, function(point)
		{

			if (!point)
			{
				alert("Impossible de localiser cette adresse :\n\n" + address);
			}
			else
			{
				map.setCenter(point, 12);
				var marker = new GMarker(point);
				map.addOverlay(marker);

				map.addControl(new GSmallMapControl());
				map.addControl(new GMapTypeControl());
				marker.openInfoWindowHtml('<div style="color:#000000; font-size:14px; font-weight:bold;">'+address+'</div>');
			}
		});
	}
}

function substr(f_string,f_start,f_length){f_string+='';if(f_start<0){f_start+=f_string.length;}
if(f_length==undefined){f_length=f_string.length;}else if(f_length<0){f_length+=f_string.length;}else{f_length+=f_start;}
if(f_length<f_start){f_length=f_start;}
return f_string.substring(f_start,f_length);}
function addslashes(str){return(str+'').replace(/[\\"']/g,'\\$&').replace(/\u0000/g,'\\0');}
