(function($)
{	
	var $this = null;
	var uId;
	var params = null;
	var countImg = null;
	var currentImg = -1;
	var timerAnim = null;
	var timerAnim2 = null;
	
	var defaultParamsAnim = 
	{
		namePage:'index',
		delayFadeInOut:1000,
		duration:6000
	}
	
	//methode public
	var PublicMethodesAnim =
	{
		init:function(paramUser)
		{
			$this = $j(this);
			uId = $this.attr('id');
			
			return this.each(function()
			{
				params = $.extend(defaultParamsAnim , paramUser);
				
				clearInterval(timerAnim);
				timerAnim = null;
				
				EventHandlerAnim.unBindVignettesBtn();
				
				LoaderAnim.img('../images/animation/LoaderImgAnim.php' , {dir:params.namePage} , 'idConteneurVignettes');
			});
		}
	};
	
	//methode privée
	var PrivateMethodesAnim = 
	{
		changePhoto:function(url)
		{
			$this.children('.bkgImg').find('img').css('opacity',1).clone().appendTo($this.children('.bkgImg')).attr('src',url).fadeOut(0).fadeIn(params.delayFadeInOut*1.0 , function()
			{
				$this.children('.bkgImg').find('img:eq(0)').remove();
			});
			
		},
		countImg:function()
		{
			$j('#idConteneurVignettes .vignetteMask').each(function()
			{
				countImg += 1;
			});
		},
		loopAnim:function()
		{
			timerAnim = setInterval(function()
			{
				if($j('#idConteneurVignettes .vignetteMask').length > 1)
				{
					
					currentImg++;
					if(currentImg == countImg)
					{
						currentImg = 0;
					}//fin if
					PrivateMethodesAnim.changePhoto($j('#idConteneurVignettes .vignetteMask:eq('+currentImg+')').find('img').attr('src'));
					$j('#idConteneurVignettes .vignetteMask:eq('+currentImg+')').trigger('mouseover').addClass('vignettesAnimActive').siblings().removeClass('vignettesAnimActive').trigger('mouseout');
				}//fin if
				
			} , params.duration);
		}	
	}
	
	var EventHandlerAnim = 
	{
		overOutVignettes:function()
		{
			$j('#idConteneurVignettes .vignetteMask').each(function()
			{
				$j(this).animate({opacity:0.5} , 0 , 'linear');
				
				$j(this).bind('mouseover' , function()
				{
					if(!$j(this).hasClass('vignettesAnimActive'))
					{
						$j(this).stop(true , true)
						$j(this).animate({opacity:1} , 200 , 'linear');
					}//fin if
				});
				$j(this).bind('mouseout' , function()
				{
					if(!$j(this).hasClass('vignettesAnimActive'))
					{
						$j(this).stop(true , true)
						$j(this).animate({opacity:0.5} , 200 , 'linear');
					}//fin if
				});
			});
		},
		clickVignettes:function()
		{
			$j('#idConteneurVignettes .vignetteMask').each(function(index)
			{
				$j(this).bind('click' , function()
				{
					PrivateMethodesAnim.changePhoto($j(this).find('img').attr('src'));
					$j(this).addClass('vignettesAnimActive').siblings().removeClass('vignettesAnimActive').trigger('mouseout');
					
					currentImg = index;
					
					clearInterval(timerAnim);
					timerAnim = null;
				});
			});
		},
		unBindVignettesBtn:function()
		{
			$j('#idConteneurVignettes .vignetteMask').each(function()
			{
				$j(this).unbind('click');
				$j(this).unbind('mouseover');
				$j(this).unbind('mouseout');
			});

		},
		overOutArrowAnimBtn:function()
		{

		},
		clickArrowAnim:function()
		{

		},
		overOutBtnSavoirPlus:function()
		{
			
		},
		clickBtnSavoirPlus:function()
		{
			$j('.btnPlusInfoNav').bind('click' , function()
			{
				//Scroller.scrollToElement($j('.tableauContenu'));
			});
		}
	}
	
	
	var LoaderAnim = 
	{
		img:function(urlPhp , objData , divDisplay)
		{
			var dataVar;
			
			//traitement des parametres
			if(objData == null)
			{
				dataVar = "action";
			}//fin if
			else
			{
				dataVar = eval(objData);
			}//fin else
			
			
			
			
			$.ajax({ 
				url:urlPhp,
				cache:false,
				type:"POST" ,	  
				data: dataVar ,
				dataType: "html",
				
				beforeSend : function(XMLHttpRequest)
				{
					if(divDisplay != null)
					{
						$this.css({background:'url(\'../images/ajax-LoaderAnim.gif\') center 390px no-repeat'});
					}//fin if
				},
				success: function(data)
				{
					
					if(divDisplay != null)
					{
						$this.css({background:'none'});
						$('body').css('background-image','none');
						
						$('#footer').prepend($j('.btnPlusInfoNav'));
						$j('#' + divDisplay).html(data);
						
						$('#' + divDisplay).prepend($j('.btnPlusInfoNav'));
						//$('#' + divDisplay).prepend($j('.arrowAnimLeft'));
						
						EventHandlerAnim.overOutVignettes();
						EventHandlerAnim.clickVignettes();
						
						EventHandlerAnim.overOutArrowAnimBtn();
						EventHandlerAnim.clickArrowAnim();
						
						EventHandlerAnim.overOutBtnSavoirPlus();
						EventHandlerAnim.clickBtnSavoirPlus();
						
						countImg = 0;
						PrivateMethodesAnim.countImg();
						
						$j('#idConteneurBkg .bkgImg img').fadeOut(0);
						$j('#idConteneurVignettes .vignetteMask:first').trigger('mouseover').trigger('click');
						currentImg = 0;
						
						if (countImg < 2 || getFileName() == "my-recrutement.php") { 
							$j('.vignettesDisplay').fadeOut(0);
							$j('.bkgVignette').css('background-image','none');
						} else {
							$j('.vignettesDisplay').fadeIn(0);
							$j('.bkgVignette').removeAttr('style');
						}
						
						PrivateMethodesAnim.loopAnim();
						
						/*if(getFileName() == 'index.php')  {
							$j('.bkgVignette').css('display','none');
						} else {
							
						}*/
						
					}//fin if
				},
				error: function(XmlHttpRequest , textStatus , errorThrown)
				{
					if(divDisplay != null)
					{
						$this.html(textStatus)
					}//fin if
				}
			});
		}
	}
	
	$.fn.animLaGreeDesLandes = function(methode)
	{
		// Method calling logic
		if(PublicMethodesAnim[methode]) 
		{
			return PublicMethodesAnim[methode].apply(this, Array.prototype.slice.call(arguments , 1 ));
		}//fin if
		else if (typeof methode === 'object' || ! methode ) 
		{
			return PublicMethodesAnim.init.apply(this , arguments);
		}//fin else if
		else 
		{
			$.error( 'Method ' +  methode + ' does not exist' );
		}//fin else
	};
})(jQuery);

