// JavaScript Document
// Author Christophe Iaïchouchen AKA saturnino pour Imag'in Productions
// Copyright : AQUA LOISIR

// prévention des frames
if (top.frames.length!=0) top.location=self.document.location; 

jQuery.noConflict();

// gestion des liens externes
function initExternalLinks()
{
	jQuery('a[class=external]').attr('target', '_blank');
}


function initAnchors()
{

	jQuery('.anchorTop a').bind('click', function(e){			
					
			e.preventDefault();					
			
			var link = jQuery(this).attr('href');			
			
			if (link.indexOf('#') > -1)
			{
				var s 		= link.split('#');
				if(s.length==2 && document.getElementById(s[1]) )
				{
					jQuery.scrollTo( '#'+s[1], 800, {easing:'easeout'} );
				}	
			}
	});		
}



function popupCredit(theURL,winName,largeur,features)
{ 
	if(! window.focus){  return; }
	var left = 'left='+(screen.width-largeur-100);
	var credit = window.open(theURL,winName,left+','+features);
	credit.focus();
	theURL.target = winName;		
}


function initSlideShow()
{

	var prevPosition 			= -1;
	var currentPosition 		= -1;
	var slides_array			= Array();
	var slides 					= jQuery('.slide');
	var numberOfSlides 			= slides.length;
	var repeat 					= 4000;
	var isPlaying 				= false;
	

	// Supprime la scrollbar en JS
	jQuery('#slides-container').css('overflow', 'hidden');

	slides
	.each(function(i){							
		jQuery(this).css({	'position'  : 'absolute',
						   	'z-index'  	: numberOfSlides -i

						 });
		slides_array[i]	=	jQuery(this);
		slides_array[i].hide();
		
		var caption		=	jQuery('<p class="caption">'+jQuery(this).find('img').attr('alt')+'</p>').prependTo(jQuery(this));
		var bg			=	jQuery('<p class="bg"></p>').prependTo(jQuery(this));
		
		
		
		bg.css({		'opacity'  			: 	.65,
			   			'top'				:   326//-100				
			   
			   });
		
		caption.css({	'top'				:   326//-100				
			   
			   });
		
		jQuery(this).mouseover(function() {
			pauseSlideShow(true)						
		});
		jQuery(this).mouseout(function() {
			pauseSlideShow(false)						
		});326
	});	
	
	jQuery('.slideshow-nav li')
	.each(function(i){							
		
		if(i == 0)
			jQuery(this).addClass('current');
			
		jQuery(this).find('img').stop().animate({opacity:.5}, 'fast');
		
		jQuery(this).attr('id','page-'+i).bind('click', function(e){			
																 
			e.preventDefault();
			
			var index = Number(jQuery(this).attr('id').split('-')[1]);
			
			if(currentPosition != index )
			{
				pauseSlideShow(true);
				showSlide(index);			
				startSlideShow();
			}
			
		});
		
		
		jQuery(this).mouseover(function() {
				
			var index = Number(jQuery(this).attr('id').split('-')[1]);
			
			if(currentPosition != index )
			{
				jQuery(this).stop().animate({backgroundColor: "#0065ad"}, 'fast');
				jQuery(this).find('img').stop().animate({opacity:1}, 'fast');
			}
				
		});
		
		jQuery(this).mouseout(function() {
			
			var index = Number(jQuery(this).attr('id').split('-')[1]);
			
			if(currentPosition != index )
			{
				jQuery(this).stop().animate({backgroundColor: "#000"}, 'fast');
				jQuery(this).find('img').stop().animate({opacity:.5}, 'fast');
				
			}
		});	
		
		
	});	

	showSlide(0)
	startSlideShow();
	
	function startSlideShow()
	{
		if(isPlaying == false && numberOfSlides > 1 )
		{
			isPlaying	= true;
			jQuery('.slides-container').everyTime(repeat, function(i) {
			 	doSlideShow();
			});
		}
	}
	
	function manageControls()
	{
		jQuery('#page-'+currentPosition).addClass('current');
		jQuery('#page-'+currentPosition).stop().animate({backgroundColor:'#0065ad'}, 'fast');
		jQuery('#page-'+currentPosition).find('img').stop().animate({opacity:1}, 'fast');
		
		if( prevPosition >= 0)
		{
			jQuery('#page-'+prevPosition).removeClass('current');
			jQuery('#page-'+prevPosition).stop().animate({backgroundColor: "#000"}, 'fast');
			jQuery('#page-'+prevPosition).find('img').stop().animate({opacity:.5}, 'fast');
		}
	}
	
	function doSlideShow()
	{			
		var n = ( Number(currentPosition + 1) < numberOfSlides )? Number(currentPosition + 1) : 0;
		showSlide(n);		
	}
	
	function pauseSlideShow(bool)
	{
		if(bool)
		{
			jQuery('.slides-container').stopTime();
			isPlaying = false;		
		}else
		{
			jQuery('.slides-container').oneTime(1000, function(i) {
			  startSlideShow();
			});
		}
	}
	
	function showSlide(n)
	{		
		prevPosition	=	currentPosition;			
		currentPosition =   n;		

		manageControls();
		
		slides_array[currentPosition].fadeIn("slow");
		
		if( prevPosition >= 0)
			slides_array[prevPosition].fadeOut("slow");
			
		slides_array[currentPosition].find('p').animate({
				top: 295//0,
			  }, 800  );
		
		if( prevPosition >= 0)
			slides_array[prevPosition].find('p').animate({
				top: 326//-100,
			  }, 1200  );
	}
}

function initNavigation()
{
	jQuery("#top-nav").lavaLamp({ fx: "backout", speed: 700});
	
	jQuery('#top-nav li[class!=current] ul').hide();
	
	jQuery('#top-nav li[class=current] ul').addClass("active");
	
	jQuery('#top-nav > li').addClass("firstlevel");
	
	jQuery('#top-nav li.firstlevel > a').mouseover(function() {

		jQuery('#top-nav').stopTime();
		
		var li = jQuery(this).parent();
		jQuery('#top-nav li.firstlevel').find('ul').fadeOut(100);
		jQuery('#top-nav li.firstlevel ul').removeClass('over');
	    li.find('ul').addClass('over');
		li.find('ul').fadeIn('slow');	  
		
	});
	
	jQuery('#top-nav li').mouseover(function() {
		jQuery('#top-nav').stopTime();
		jQuery('#top-nav').addClass('isOver');
	});
	
	jQuery('#top-nav li').mouseout(function() {
		jQuery('#top-nav').removeClass('isOver');
	});
	
	jQuery('#top-nav').mouseout(function() {
	
		jQuery('#top-nav').stopTime();
		
		jQuery(this).oneTime(3000, function(i) {	

			var nb_sub_over = jQuery('#top-nav li.firstlevel').find('ul.over').length;
			if(!jQuery('#top-nav').hasClass('isOver') )
			{
				jQuery('#top-nav li.firstlevel').find('ul.over').fadeOut(100);	
				jQuery('#top-nav li.current ul').fadeIn('slow');	
			}
/*				
			if( jQuery('#top-nav li.firstlevel').find('ul.over').length == 0)
				jQuery('#top-nav li.current ul').fadeIn('slow');
*/				
		});
	});
	
	jQuery('#top-nav a').mouseout(function() {	
		
		if( jQuery(this).parent().hasClass('sub-current') || jQuery(this).parent().hasClass('current'))
		{
		
		}else{
			jQuery(this).stop().animate({color: '#bebfbf'}, 700);
		}
	});
	jQuery('#top-nav a').mouseover(function() {
		
		if( jQuery(this).parent().hasClass('sub-current') || jQuery(this).parent().hasClass('current'))
		{
		
		}else{
			jQuery(this).stop().animate({color: "#33ccff"}, 700);	
		}
											   
	});

}

jQuery(document).ready(function(){
	
	initNavigation();
	
	initAnchors();	
	
	initExternalLinks();
	
	if(document.getElementById('contactForm') )
	{
		var myForm = jQuery("#contactForm");    
		myForm.validation();
	}
	
	jQuery('a[class=mentions]').bind('click', function(e){			
					
			e.preventDefault();					
			
			var link = jQuery(this).attr('href');	
			popupCredit(link,'credits','350','height=650,width=350,top=10,scrollbars=no,status=no,menubar=no,resizable=no');
	});	
	
	if(document.getElementById('slideshow') )
	{
		initSlideShow();
	}
 
});

