// JavaScript Document


// Permet d'afficher le bateau selectionne en fonction de son id et de la categorie vente=1 et location=2
function selectionYacht(id, vente){
	if(vente==1){
		$('ContentLeft5').fade({duration:0.3});$('ContentRight5').fade({duration:0.3, afterFinish: function(){afficherYacht(id,vente)} });
	}else{
		$('ContentLeft6').fade({duration:0.3});$('ContentRight6').fade({duration:0.3, afterFinish: function(){afficherYacht(id,vente)} });
	}
	return true;
}

function afficherYacht(id, vente)
{
		
	if(vente==1){
		// Creation de l'objet XMLHttpRequest
		get_Xhr();
		xhr.onreadystatechange = function()
		{
			//Code a Executer
			if(xhr.readyState == 4 && xhr.status == 200)
			{
				var chaine = xhr.responseText;
				document.getElementById('ContentRight51').innerHTML = chaine;
				document.getElementById('toPdfV').innerHTML = '<a href="php/toPdf.php?id='+id+'" target="_blank" title="Imprimer la fiche">Imprimer</a>';
				document.getElementById('AmiV').innerHTML = '<a href="php/sendAmi.php?id='+id+'&cat=5" title="Envoyer a un ami" onclick="Modalbox.show(this.href, {title: this.title, width: 400}); return false;">Envoyer &agrave; un ami</a>'; 
				transform('51');
				return true;
			}
		}
		//Envoie au script de traitement
		xhr.open("POST",'php/yachtUnique.php',true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xhr.send("yacht_id="+id+"&cat="+vente);
	}else{
		// Creation de l'objet XMLHttpRequest
		get_Xhr();
		xhr.onreadystatechange = function()
		{
			//Code a Executer
			if(xhr.readyState == 4 && xhr.status == 200)
			{
				var chaine = xhr.responseText;
				document.getElementById('ContentRight61').innerHTML = chaine;
				document.getElementById('toPdfL').innerHTML = '<a href="php/toPdf.php?id='+id+'" target="_blank" title="Imprimer la fiche">Imprimer</a>';
				document.getElementById('AmiL').innerHTML = '<a href="php/sendAmi.php?id='+id+'&cat=6" title="Envoyer a un ami" onclick="Modalbox.show(this.href, {title: this.title, width: 400}); return false;">Envoyer &agrave; un ami</a>';
				transform('61');
				return true;
			}
		}
		//Envoie au script de traitement
		xhr.open("POST",'php/yachtUnique.php',true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xhr.send("yacht_id="+id+"&cat="+vente);
	}
}


//Affiche la photo selectionnee en gros
function toBig(id, cat){
	
	$("big"+cat).fade({duration:0.5});
	$(cat+"sm"+id).fade({duration:0.5, afterFinish: function(){echanger(id,cat);return true;} });
	
	
}

function echanger(id,cat){
	
	var temp = $("big"+cat).src;
	var w_temp = $("big"+cat).width;
	var h_temp = $("big"+cat).height;
	var tempa = $(cat+"sm"+id).src;
	var w_tempa = $(cat+"sm"+id).width;
	var h_tempa = $(cat+"sm"+id).height;
	var temphref = $(cat+"smLien"+id).href;
	
	$(cat+"smLien"+id).href =  $("bigLien"+cat).href;
	$("bigLien"+cat).href = temphref;
	
	$("big"+cat).width = parseInt($(cat+"sm"+id).width*(3.2));
	$("big"+cat).height = parseInt($(cat+"sm"+id).height*(3.2));
	$(cat+"sm"+id).width = parseInt(w_temp/(3.2));
	$(cat+"sm"+id).height = parseInt(h_temp/(3.2));
		
	tempa = tempa.substring(0,tempa.lastIndexOf('/')+1)+'320_'+tempa.substring(tempa.lastIndexOf('/')+1, tempa.length);
	temp = temp.replace('320_','');
	$("big"+cat).src = tempa;
	$(cat+"sm"+id).src = temp;
	
	$(cat+"sm"+id).appear({duration: 0.3});
	$("big"+cat).appear({duration: 0.3});
	return true;
}


// Fonction por afficher la page contact
function afficherContact(vente){
	if(vente == 1){
		$('ficheBateauVente').fade({afterFinish: function(){$('ficheContactVente').appear({duration:0.3});}});
		$('lienContactYachtV').fade({afterFinish: function(){$('lienContactNonYachtV').appear({duration:0.3});}});
		return true;
	}
	else{
		$('ficheBateauLocation').fade({afterFinish: function(){$('ficheContactLocation').appear({duration:0.3});}});
		$('lienContactYachtL').fade({afterFinish: function(){$('lienContactNonYachtL').appear({duration:0.3});}});
		return true;
	}
}

function desafficherContact(vente){
	if(vente==1){
		$('ficheContactVente').fade({duration:0.3, afterFinish: function(){$('ficheBateauVente').appear({duration:0.3});}});
		$('lienContactNonYachtV').fade(	{duration:0.3, afterFinish: function(){$('lienContactYachtV').appear({duration:0.3});}});
		return true;
	}
	else{
		$('ficheContactLocation').fade({duration:0.3, afterFinish: function(){$('ficheBateauLocation').appear({duration:0.3});}});
		$('lienContactNonYachtL').fade(	{duration:0.3, afterFinish: function(){$('lienContactYachtL').appear({duration:0.3});}});
		return true;
	}
}

function retourVente(id,cat){
	if(cat==1){
		$('ContentLeft51').fade({duration:0.3});$('ContentRight51').fade({duration:0.3, afterFinish: function(){transformGalerie('5',id)} });
		$('ContentRight51').innerHTML = '';
	}else{
		$('ContentLeft61').fade({duration:0.3});$('ContentRight61').fade({duration:0.3, afterFinish: function(){transformGalerie('6',id)} });
		$('ContentRight61').innerHTML = '';
	}
	return true;
}

function transformGalerie(elmt,id){
	$('ContentLeft'+elmt).appear({duration:0.3});$('ContentRight'+elmt).appear({duration:0.3});
	$('Remote').appear();
	return true;
}
