var imgLoad ="";

var gMaxGrandit = Array();
var gDivGrandit = Array();

var gMaxRetreci = Array();
var gDivRetreci = Array();

var min = 75;
var lastType = 'A';
var oldButtonValue = '';

function changeDefil(type, photos)
{
	var RecupValHTML = null;
	photos = document.getElementsByName('photos')[0].checked;
	
	lastType = type;
	div = document.getElementById('load');
	divListe = document.getElementById('defil_liste');
	
	div.style.display = 'block';
	div.style.visibility = 'visible';	
	divListe.style.display = 'none';
	divListe.style.visibility = 'hidden';

	var d = new Date();
	var antiBUG = d.getTime();
	
    if (window.XMLHttpRequest) 
	{ 
        RecupValHTML = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        RecupValHTML = new ActiveXObject("Microsoft.XMLHTTP");
    }

    //on définit l'appel de la fonction au retour serveur
    RecupValHTML.onreadystatechange = function() { AfficheNewDefil(RecupValHTML); };

    //on appelle le fichier de reponse
    RecupValHTML.open("POST", url_site + "ajax/defil.php?bug=" + antiBUG , true);
    
	RecupValHTML.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 

	if (photos)
		photos = 1;
	else
		photos = 0;
	
    RecupValHTML.send("type=" + type + "&photos=" + photos);
}

function AfficheNewDefil(ReponseHTML)
{
	if (ReponseHTML.readyState == 4)
	{
		div = document.getElementById('load');
		divListe = document.getElementById('defil_liste');		

		var retourJson = eval('(' + ReponseHTML.responseText + ')');

		for (i in retourJson)
		{
			userEnCours = retourJson[i];
			
			divImg = document.getElementById('img_' + userEnCours['iCount']);
			divHRef = document.getElementById('href_' + userEnCours['iCount']);
			divPseudo = document.getElementById('pseudo_' + userEnCours['iCount']);
			divAge = document.getElementById('age_' + userEnCours['iCount']);
			
			if (divImg != null)
			{
				divImg.src = userEnCours['photo'];
				divImg.title = 'Rencontrer ' + userEnCours['pseudo'];
				divImg.alt = 'Photo de ' +  userEnCours['pseudo'];
				divHRef.href =  userEnCours['url_details'];
				divPseudo.innerHTML =  userEnCours['pseudo'];
				divAge.innerHTML =  userEnCours['AGE'] + ' ans';
			}
		}
		
		div.style.display = 'none';
		div.style.visibility = 'hidden';
		divListe.style.display = 'block';
		divListe.style.visibility = 'visible';
	}
}

function afficheCacheDefil(button)
{
	var block_defil 	= document.getElementById('block_defil');
	var button_defil 	= document.getElementById('button_defil');
	
	if(block_defil.style.visibility == 'hidden')
	{
		block_defil.style.visibility = 'visible';
		block_defil.style.display = 'block';
		oldButtonValue = button.value;
		button.value = 'Cacher';
		button_defil.style.height = '5px';
	}
	else
	{
		block_defil.style.visibility = 'hidden';
		block_defil.style.display = 'none';
		button.value = oldButtonValue;
		button_defil.style.height = '30px';
	}
}

function grandir(i)
{
	if (gMaxGrandit[i] < 7)
	{
		if (gDivGrandit[i-1] != null)
		{
			gDivGrandit[i-1].style.height = parseInt(gDivGrandit[i-1].style.height) + Math.floor(gMaxGrandit[i]/3) + 'px';
			gDivGrandit[i-1].style.width = parseInt(gDivGrandit[i-1].style.width) + Math.floor(gMaxGrandit[i]/3) + 'px';
		}
		if (gDivGrandit[i+1] != null)
		{
			gDivGrandit[i+1].style.height = parseInt(gDivGrandit[i+1].style.height) + Math.floor(gMaxGrandit[i]/3) + 'px';
			gDivGrandit[i+1].style.width = parseInt(gDivGrandit[i+1].style.width) + Math.floor(gMaxGrandit[i]/3) + 'px';
		}
		gDivGrandit[i].style.height = parseInt(gDivGrandit[i].style.height) + gMaxGrandit[i] + 'px';
		gDivGrandit[i].style.width = parseInt(gDivGrandit[i].style.width) + gMaxGrandit[i] + 'px';
		gMaxGrandit[i] = gMaxGrandit[i]+1;

		window.setTimeout('grandir('+i+')', 20);
	}
	else
	{
		gMaxGrandit[i] = 0;
	}
}

function retrecir(i)
{
	if (gMaxRetreci[i] < 7)
	{
		
		if (gDivRetreci[i-1] != null)
		{
			gDivRetreci[i-1].style.height = parseInt(gDivRetreci[i-1].style.height) - Math.floor(gMaxRetreci[i]/3) + 'px';
			gDivRetreci[i-1].style.width = parseInt(gDivRetreci[i-1].style.width) - Math.floor(gMaxRetreci[i]/3) + 'px';
			secu(gDivRetreci[i-1]);
		}
		if (gDivRetreci[i+1] != null)
		{
			gDivRetreci[i+1].style.height = parseInt(gDivRetreci[i+1].style.height) - Math.floor(gMaxRetreci[i]/3) + 'px';
			gDivRetreci[i+1].style.width = parseInt(gDivRetreci[i+1].style.width) - Math.floor(gMaxRetreci[i]/3) + 'px';
			secu(gDivRetreci[i+1]);
		}
		
		gDivRetreci[i].style.height = parseInt(gDivRetreci[i].style.height) - gMaxRetreci[i] + 'px';
		gDivRetreci[i].style.width =parseInt( gDivRetreci[i].style.width) - gMaxRetreci[i] + 'px';
		gMaxRetreci[i] = gMaxRetreci[i]+1;


		window.setTimeout('retrecir('+i+')', 20);
	}
	else
	{
		secu(gDivRetreci[i]);
		gMaxRetreci[i] = 0;
	}
}

function otherRetrecir(actuel)
{
	for(i=1; i<=10; i++)
	{
		if (gDivRetreci[i] != null && (actuel-1 > i || actuel+1 < i))
		{
			gDivRetreci[i].style.height = gDivRetreci[i].style.height*1 - Math.floor(gMaxGrandit[actuel]/2.9);
			gDivRetreci[i].style.width = gDivRetreci[i].style.width*1 - Math.floor(gMaxGrandit[actuel]/2.9);
		}
	}
}

function otherGrandit(actuel)
{
	for(i=1; i<=10; i++)
	{
		if (gDivGrandit[i] != null && (actuel-1 > i || actuel+1 < i))
		{
			gDivGrandit[i].style.height = gDivGrandit[i].style.height*1 + Math.floor(gMaxRetreci[actuel]/2.9);
			gDivGrandit[i].style.width = gDivGrandit[i].style.width*1 + Math.floor(gMaxRetreci[actuel]/2.9);
		}
	}
}

function secu(div)
{
	if (parseInt(div.style.height) <= min)
		div.style.height = min + 'px';
	
	if (parseInt(div.style.width) <= min)
		div.style.width = min + 'px';
}