// JavaScript Document


function affiche(elmt)
{
   if(document.getElementById('ContentLeft'+elmt)){
   	elmtL = document.getElementById('ContentLeft'+elmt);
	
		if(elmtL.style.display == "none"){
			if(document.getElementById('ContentLeft1').style.display != "none"){ 
				$('ContentLeft1').fade({duration:0.3}); 
				$('ContentRight1').fade({duration:0.3, afterFinish: function(){transform(elmt)} });
			}
			else {	if(document.getElementById('ContentLeft2').style.display != "none") {$('ContentLeft2').fade();$('ContentRight2').fade({duration:0.6, afterFinish: function(){transform(elmt)} });}
					else{	if(document.getElementById('ContentLeft3').style.display != "none"){ 
								$('ContentLeft3').fade({duration:0.3});$('ContentRight3').fade({duration:0.3, afterFinish: function(){transform(elmt)} });}
							else {if(document.getElementById('ContentLeft4').style.display != "none"){ 
									$('ContentLeft4').fade({duration:0.3});$('ContentRight4').fade({duration:0.3, afterFinish: function(){transform(elmt)} });}
									else {if(document.getElementById('ContentLeft5').style.display != "none"){ 
										$('ContentLeft5').fade({duration:0.3});$('ContentRight5').fade({duration:0.3, afterFinish: function(){transform(elmt)} });}
											else if(document.getElementById('ContentLeft6').style.display != "none"){
												$('ContentLeft6').fade({duration:0.3});$('ContentRight6').fade({duration:0.3, afterFinish: function(){transform(elmt)} });}
													else if(document.getElementById('ContentLeft61').style.display != "none"){
														$('ContentLeft61').fade({duration:0.3});$('ContentRight61').fade({duration:0.3, afterFinish: function(){transform(elmt)} });}
														else if(document.getElementById('ContentLeft51').style.display != "none"){
															$('ContentLeft51').fade({duration:0.3});$('ContentRight51').fade({duration:0.3, afterFinish: function(){transform(elmt)} });}
											else if(document.getElementById('ContentLeft7').style.display != "none"){
												$('ContentLeft7').fade({duration:0.3});$('ContentRight7').fade({duration:0.3, afterFinish: function(){transform(elmt)} });}
			}		}		}		}
			
			clearItem(elmt);
			var btn = document.getElementById("item"+elmt);
			btn.className = 'Active';
			
			return true;
		}else{   
			return true;
		}
	}
}

function transform(elmt){
switch (elmt){
			case '1': $('Content').morph('width:870px;height:410px;margin:110px 10px 0 100px;',{afterFinish: function(){Affichage(elmt)} });break;
			case '2': $('Content').morph('width:730px;height:450px;margin:70px 10px 0 40px;',	{afterFinish: function(){Affichage(elmt)} });break;
			case '3': $('Content').morph('width:500px;height:500px;margin:20px 300px 0 0px;',	{afterFinish: function(){Affichage(elmt)} });break;
			case '4': $('Content').morph('width:870px;height:500px;margin:15px 10px 0 40px;',	{afterFinish: function(){Affichage(elmt)} });break;
			case '5': $('Content').morph('width:740px;height:440px;margin:80px 10px 0 40px;',	{afterFinish: function(){Affichage(elmt)} });break;
			case '51': $('Content').morph('width:740px;height:440px;margin:80px 10px 0 40px;',{duration:0.1,afterFinish: function(){Affichage(elmt)} });break;
			case '6': $('Content').morph('width:740px;height:440px;margin:80px 10px 0 40px;',	{afterFinish: function(){Affichage(elmt)} });break;
			case '61': $('Content').morph('width:740px;height:440px;margin:80px 10px 0 40px;',{duration:0.1,afterFinish: function(){Affichage(elmt)} });break;
			case '7': $('Content').morph('width:760px;height:440px;margin:80px 10px 0 40px;',	{afterFinish: function(){Affichage(elmt)} });break;
		}
		return true;
}
function Affichage(elmt){
	if(elmt==51 || elmt == 61){
		
		$('ContentLeft'+elmt).appear({duration:0.3});
		$('ContentRight'+elmt).appear({duration:0.3});
		
	}
	
	if(elmt == 5 || elmt == 6){
		if($('ContentLeft'+elmt).innerHTML==''){
			afficheGalerie(1,elmt-4);
		}else{
			if($('ContentLeft'+elmt+'1').innerHTML!=''){
				$('ContentLeft'+elmt+'1').appear({duration:0.3});
				$('ContentRight'+elmt+'1').appear({duration:0.3});
			}else{
				$('ContentLeft'+elmt).appear({duration:0.3});
				$('ContentRight'+elmt).appear({duration:0.3});
			}
		}
	}else{
		if(elmt == 1){
			news(0);
			
		}else{
			$('ContentLeft'+elmt).appear();
			$('ContentRight'+elmt).appear();
		}
	}
	Remote(elmt);
	return true;
}

function Remote(elmt){
	if(elmt == 5 || elmt == 6){
		//$('RemoteBleu').innerHTML='<h4>Type</h4>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" onclick="searchGalerie(1,'+(elmt-4)+',7);">Moteur</a><br/>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" onclick="searchGalerie(1,'+(elmt-4)+',8);">Voile</a><form name="formSearch" action="javascript:void();" onsubmit="searchGalerie(1,'+(elmt-4)+',5;)" method="post"><h4>Recherche</h4>&nbsp;&nbsp;<input type="text" name="search" id="champRecherche" onKeyUp="searchGalerie(1,'+(elmt-4)+',5);"/></form><br/><br/><a href="javascript:void(0);" onclick="searchGalerie(1,'+(elmt-4)+',6)"><strong>Tous</strong></a>';
		//<!-- <h4>Longueur</h4><ul><li onclick="searchGalerie(1,'+(elmt-4)+',1)">Moins de 10m</li><li onclick="searchGalerie(1,'+(elmt-4)+',2)">De 10 &agrave; 25m</li><li onclick="searchGalerie(1,'+(elmt-4)+',3)">De 25 &agrave; 40m</li><li onclick="searchGalerie(1,'+(elmt-4)+',4)">Plus de 40</li></ul> -->
		$('cathiddenresearch').value=(elmt-4);
		$('Remote').appear();
	}else {
		if(document.getElementById('Remote').style.display != "none")
			$('Remote').fade();
	}
	return true;
}

function clearItem(elmt){
	for(i=1;i<8;i++){
			if(i!=elmt){
				//alert(i);
				var btn = document.getElementById("item"+i);
				btn.className = 'noActive';
			}
		}
	return true;
}

function preload(){
   if (document.images)
   {
     preload_image_object = new Image();
     // set image url
     image_url = new Array();
     image_url[0] = "back-Yacht/yacht-addict1.jpg";
     image_url[1] = "back-Yacht/yacht-addict2.jpg";
     image_url[2] = "back-Yacht/yacht-addict3.jpg";
     image_url[3] = "back-Yacht/yacht-addict4.jpg";
	 image_url[4] = "back-Yacht/yacht-addict5.jpg";
     image_url[5] = "back-Yacht/yacht-addict6.jpg";
     image_url[6] = "back-Yacht/yacht-addict7.jpg";
     image_url[7] = "back-Yacht/yacht-addict8.jpg";

      var i = 0;
      for(i=0; i<=7; i++) 
        preload_image_object.src = image_url[i];
   }
	VerifResolution();
	determineTaille();
  	
	return true;
}

function determineTaille(){
	for(i=1;i<8;i++){
			if($('Content'+i)){ content = $('Content'+i);break;}
	}
	if(getWindowHeight()<623){
		if(getWindowWidth()<1244){
			$('fondImg').width = 1204;
			//$('fondImg2').width = 1204;
			$('fondImg').height = 580;
			//$('fondImg2').height = 580;
			
			content.style.position = 'relative';
			content.style.right.value = '';
			content.style.bottom.value = '';
			
			$('Footer').style.top.value = 602;
			$('Footer').style.width = 1204;
			$('Footer').style.right.value = 20;
	
		}else{
			$('fondImg').width = getWindowWidth();
			//$('fondImg2').width = getWindowWidth();
			
			$('Footer').style.width = getWindowWidth();
			$('Footer').style.right = "20px";
			
			content.style.position = 'absolute';
			content.style.right = "20px";
			
			
			$('fondImg').height = 580;
			//$('fondImg2').height = 580;
			
			content.style.bottom = '';
			$('Footer').style.top = '602px';
		}
	}else{
		if(getWindowWidth()<1244){
			$('fondImg').width = 1204;
			//$('fondImg2').width = 1204;
			content.style.position = 'relative';
			content.style.right = '';
			$('Footer').width = 1204;
			$('Footer').style.right = '20px';
	
			$('fondImg').height = 580;
			//$('fondImg2').height = 580;
			
			content.style.bottom = '';
			$('Footer').style.top = '602px';
		}else{
			$('fondImg').width = getWindowWidth();
			//$('fondImg2').width = getWindowWidth();
			
			$('Footer').style.width = getWindowWidth();
			$('Footer').style.right = '20px';
			
			content.style.position = 'absolute';
			content.style.right = '20px';
		
			
			$('fondImg').height = getWindowHeight() - 43;
			//$('fondImg2').height = getWindowHeight() - 43;
			
			content.style.bottom = '32px';
			$('Footer').style.top = getWindowHeight() - 22 +"px";
			
		}
	}
	return true;
}

var current=0;
var next=0;


function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number')
	windowHeight = window.innerHeight;
	else
	if (document.documentElement && document.documentElement.clientHeight)
		windowHeight = document.documentElement.clientHeight;
	else
		if (document.body && document.body.clientHeight)
			windowHeight = document.body.clientHeight;
	return windowHeight;
}
function getWindowWidth() {
	var windowWidth = 0;
	if (typeof(window.innerWidth) == 'number')
		windowWidth = window.innerWidth;
	else
		if (document.documentElement && document.documentElement.clientWidth)
			windowWidth = document.documentElement.clientWidth;
		else
			if (document.body && document.body.clientWidth)
				windowWidth = document.body.clientWidth;
	return windowWidth;
}

function VerifResolution() {
	if(screen.width <= 800)
		alert('Une résolution de 1280 x 800 est conseillée pour consulter le site');
	return true;
}


function redimensionne(){
	determineTaille();
	return true;
}

function lienNews(id){
	$(id).style.color = '#ff9900';
	return true;
}

function lienNewsOut(id){
	$(id).style.color = '#7f6e4d';
	return true;
}



// Fonction por afficher la page contact
function afficherContactP(){
		$('placesPorts').fade({afterFinish: function(){$('placesPortsContact').appear({duration:0.3});}});
		$('lienContactPDP').fade({afterFinish: function(){$('lienNonContactPDP').appear({duration:0.3});}});
		return true;
}

function desafficherContactP(){
	$('placesPortsContact').fade({duration:0.3, afterFinish: function(){$('placesPorts').appear({duration:0.3});}});
	$('lienNonContactPDP').fade(	{duration:0.3, afterFinish: function(){$('lienContactPDP').appear({duration:0.3});}});
	return true;
}

function apparition(elmt){
	//if(elmt==51 || elmt == 61){
	switch (elmt){
			case 1 : $('Content').morph('width:870px;height:410px;margin:110px 10px 0 100px;',	{afterFinish: function(){$('ContentLeft'+elmt).appear({duration:0.3});$('ContentRight'+elmt).appear({duration:0.3});} });break;
			case 2 : $('Content').morph('width:730px;height:450px;margin:70px 10px 0 40px;',	{afterFinish: function(){$('ContentLeft'+elmt).appear({duration:0.3});$('ContentRight'+elmt).appear({duration:0.3});} });break;
			case 3 : $('Content').morph('width:500px;height:500px;margin:20px 300px 0 0px;',	{afterFinish: function(){$('ContentLeft'+elmt).appear({duration:0.3});$('ContentRight'+elmt).appear({duration:0.3});} });break;
			case 4 : $('Content').morph('width:870px;height:500px;margin:15px 10px 0 40px;',	{afterFinish: function(){$('ContentLeft'+elmt).appear({duration:0.3});$('ContentRight'+elmt).appear({duration:0.3});} });break;
			case 5 : $('Content').morph('width:740px;height:440px;margin:80px 10px 0 40px;',	{afterFinish: function(){$('ContentLeft'+elmt).appear({duration:0.3});$('ContentRight'+elmt).appear({duration:0.3});} });break;
			case 51: $('Content').morph('width:740px;height:440px;margin:80px 10px 0 40px;',	{afterFinish: function(){$('ContentLeft'+elmt).appear({duration:0.3});$('ContentRight'+elmt).appear({duration:0.3});} });break;
			case 6 : $('Content').morph('width:740px;height:440px;margin:80px 10px 0 40px;',	{afterFinish: function(){$('ContentLeft'+elmt).appear({duration:0.3});$('ContentRight'+elmt).appear({duration:0.3});} });break;
			case 61: $('Content').morph('width:740px;height:440px;margin:80px 10px 0 40px;',	{afterFinish: function(){$('ContentLeft'+elmt).appear({duration:0.3});$('ContentRight'+elmt).appear({duration:0.3});} });break;
			case 7 : $('Content').morph('width:760px;height:440px;margin:80px 10px 0 40px;',	{afterFinish: function(){$('ContentLeft'+elmt).appear({duration:0.3});$('ContentRight'+elmt).appear({duration:0.3});} });break;
		}	
	
	Remote(elmt);
	return true;
}

function reducer(elmt){
	$('ContentLeft'+elmt).fade({duration:0.3}); 
	$('ContentRight'+elmt).fade({duration:0.3, afterFinish: function(){$('Content').morph('width:500px;height:500px;margin:20px 300px 0 0px;');} });
	
}