﻿/*********************************************************************************************************
Fn : 	-Insert les icones de 'slide' en bas à droite des images définies comme Galerie
*********************************************************************************************************/
$(document).ready(function() {
	
	$('img.galerie').each( function( ) {
		 
		if( $(this).attr( "content" ) != "1" )
		{
			var _this = this;
			var left = $(this).width( ) / 2;
			var top = $(this).height( ) / 2;
			
			//Icone zoom
			var oIconeSlide = $('<span class="SlideIconePlay" style="border:0px solid red;position:absolute;margin-top:'+top+'px;margin-left:'+left+'px;z-index:2;"><img src="/images/galerie/play.png" width="45" style="float:left;" alt="" title="Ouvrir la galerie" border="0" /></span>').insertBefore( $(this) );							
			var left = $(this).width( ) / 2 - $(oIconeSlide).width() / 2;
			var top = $(this).height( ) / 2 - $(oIconeSlide).height() / 2;
			$( oIconeSlide ).css( "margin-left", left ).css( "margin-top", top );
			
			$(oIconeSlide).css("cursor", "pointer").click( function( ) {
				
				$(_this).click();
			});
		}
		
	});
	
});



function DisableAllGalerie(  )
{
	$( 'span.SlideIconePlay' ).remove(  );
	$( "*.galerie" ).unbind( "click" );
}

/*
	IMPORTANT : Réinitialisation de l'image Preview pour revenir à l'état initial avant le chargement
	SAUVEGARDE de cette image
*/
function DisableGalerieBeforeSave(  )
{
	$('div.galerie').each( function( ){
	
		var iWidth = $( this ).width();
		var iHeight = Math.ceil( iWidth/2 );
		var iID = $(this).attr( "galerie_id" );
		var iTYPE = $(this).attr( "galerie_type" );
		
		var sHtmlImg = "<img src=\"/images/admin/mediatheque_slideshow.png\" class='galerie' galerie_id='" + iID + "' galerie_type = '" + iTYPE + "' width='" + iWidth + "' height='" + iHeight + "'  />"
		var oImg = $( sHtmlImg ).insertBefore( this );
		$( this ).remove();
	});	
}



function AMCMSGalerie( node, id )
{
	this.node = node;
	this.node.Galerie = this;		// Link node to this Galerie
	this.id = id;
	
	//Valeurs en format Galerie par défaut
	this.GalerieType = 1; //=2 : Galerie en contenu - =3 : Galerie en contenu avec 1 image
	this.Rows = 3;
	this.Columns = 5;
	this.Width = 726;
	this.Height = 402;
	this.Spacing = 14;
	
	//Valeurs en format Slide
	this.Slide = false;
	this.SlideRows = 1;
	this.SlideColumns = 8;
	this.SlideHeight = 110;
	this.SlideSpacing = 14;	
	
	
	//Valeurs en format galerie inséré dans CONTENU
	this.IsContent = false;
	this.ContentWidth = 530;
	this.ContentHeight = 340;
	
	
	// Create unique mask node
	this.init();
	
	this.Pages = [];
	this.Pages[ 0 ] = { ul: null, photos: [] };		// First page of array photos
}




AMCMSGalerie.prototype.zIndex = 100000000;
AMCMSGalerie.prototype.Rows = null;
AMCMSGalerie.prototype.Columns = null;


AMCMSGalerie.prototype.node = null;
AMCMSGalerie.prototype.nodeMasterRef = null; //par défaut : la page
AMCMSGalerie.prototype.nodeMask = null;
AMCMSGalerie.prototype.nodeGalerie = null;
AMCMSGalerie.prototype.nodeLoupe = null;

AMCMSGalerie.prototype.nodeClose = null;
AMCMSGalerie.prototype.nodeRight = null;
AMCMSGalerie.prototype.nodeLeft = null;
AMCMSGalerie.prototype.nodeSlideLeft = null;
AMCMSGalerie.prototype.nodeSlideRight = null;

//Slide
AMCMSGalerie.prototype.nodeSlideMask = null;
AMCMSGalerie.prototype.nodeSlideContainer = null;
AMCMSGalerie.prototype.nodeSlideText = null;
AMCMSGalerie.prototype.nodeSlideButtonPlay = null;
AMCMSGalerie.prototype.nodeSlideButtonClose = null;

AMCMSGalerie.prototype.Pages = null;
AMCMSGalerie.prototype.CurrentPage = 0;
AMCMSGalerie.prototype.CurrentPicto = null;

AMCMSGalerie.prototype.SlideDuration = 3;
AMCMSGalerie.prototype.SlideTransition = "fade";


AMCMSGalerie.prototype.ReverseNode = function( )
{
	if (! this.oldNode ) throw new Exception( "AMCMSGalerie::ReverseNode() - No oldNode defined" );
	$(this.oldNode).insertBefore( this.node );
	$(this.node).remove( );
	this.node = this.oldNode;
}

AMCMSGalerie.prototype.init = function( )
{
	var _this = this;
	
	if( typeof $(this.node).attr( "galerie_type" ) != "undefined" )		
	{
		this.GalerieType = $(this.node).attr( "galerie_type" );
	}
	
	//Si la galerie par dessus la page
	if( this.GalerieType == 1 )
	{
		$(this.node).unbind( 'click' );
		$(this.node).click( function() { if ( _this.nodeGalerie == null ) { _this.launch(); } } ).css('cursor','pointer');
		
		this.nodeMask = $('body').append( "<div style='display:none;position:absolute;z-index:" + _this.zIndex + ";background-color:#000000;'><img class='MaskRight' style='position:absolute;display:none;' src='/images/galerie/right.png' alt=''/><img class='MaskLeft' style='position:absolute;display:none;' src='/images/galerie/left.png' alt=''/><img class='MaskLeftSlide' style='position:absolute;display:none;' src='/images/galerie/left.png' alt=''/><img class='MaskRightSlide' style='position:absolute;display:none;' src='/images/galerie/right.png' alt=''/></div>" )[0].lastChild;
		this.nodeLeft = $(this.nodeMask).find( ".MaskLeft" ).hide();
		this.nodeRight = $(this.nodeMask).find( ".MaskRight" ).hide();
		
		this.nodeSlideLeft = $(this.nodeMask).find( ".MaskLeftSlide" ).hide();
		this.nodeSlideRight = $(this.nodeMask).find( ".MaskRightSlide" ).hide();	
		
	} //Galerie inséré dans un contenu
	else
	{
		var iWidth = $( this.node ).width();
		var iHeight = $( this.node ).height();
		
		// Set "admin_must_reverse" to "1" to reput old this.node during edition
		var sHTML = "<div class='galerie' admin_must_reverse='1' galerie_id='" + this.id + "' galerie_type='" + this.GalerieType + "' style='width:" + iWidth + "px;height:" + iHeight + "px;'></div>";
		var oContainer = $( sHTML ).insertBefore( this.node );
		
		// Alex : Disable Remove object for admin part
		this.oldNode = this.node;
		$( this.node ).remove();

		this.node = oContainer[0];
		this.node.Galerie = this;		// Link new node to current Galerie
		
		
		if( $( this.node ).width() > 0 )
		{
			this.ContentWidth = $( this.node ).width() - 100; //-100 : pour les buttons
			this.ContentHeight = $( this.node ).height();
		}
		
		this.nodeMask = $('body').append( "<div style='display:none;position:absolute;z-index:" + _this.zIndex + ";background-color:#000000;'><img class='MaskLeftSlide' style='position:absolute;display:none;' src='/images/galerie/left.png' alt=''/><img class='MaskRightSlide' style='position:absolute;display:none;' src='/images/galerie/right.png' alt=''/></div>" )[0].lastChild;
		this.nodeSlideLeft = $(this.nodeMask).find( ".MaskLeftSlide" ).hide();
		this.nodeSlideRight = $(this.nodeMask).find( ".MaskRightSlide" ).hide();		
		this.launchInContent(  );
	}
	
	//Resize de la page
	/*
	$(window).resize(function() {
		$(this.nodeMask).drawAllScreen( ).show( ).fadeTo( 0, 0.9 );
		if( _this.Slide )
		{
			_this.EnableSlideShow(  );
		}
		else
		{
			_this.Show(  );
		}
	});	
	*/	
}



AMCMSGalerie.prototype.destroy = function( )
{
	$(this.nodeMask ).remove();
	$(this.nodeGalerie ).remove();
	$(this.nodeClose ).remove();
	$(this.nodeRight ).remove();
	$(this.nodeLeft ).remove();
	$(this.nodeSlideLeft ).remove();
	$(this.nodeSlideRight ).remove();

	//Slide
	$(this.nodeSlideMask ).remove();
	$(this.nodeSlideContainer ).remove();
	$(this.nodeSlideText ).remove();
	$(this.nodeSlideButtonPlay ).remove();
	$(this.nodeSlideButtonClose ).remove();
}




AMCMSGalerie.prototype.launch = function( )
{
	var _this = this;
	
	this.CurrentPage = 0;
	this.CurrentPicto = null;
	
	//Première ouverture
	if ( this.nodeGalerie == null )
	{	
		//Bouton close
		this.nodeClose = $('body').append( "<img src=\"images/galerie/galerie-close.png\" style=\"display:none;cursor:pointer;position:absolute;z-index:" + ( _this.zIndex + 101 ) + ";top:0;left:0;width:26px;\" />" )[0].lastChild;

		// Patch PNG Close Gallery
		if ( $.browser.msie && parseInt($.browser.version) < 7 ) 
			this.nodeClose.outerHTML = "<span class='IEFauxBouttons' style=\"" + "width:26px;z-uindex:" + ( this.zIndex+1000000 ) + "; height:26px;display:inline-block;position:absolute;cursor:pointer;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/galerie/galerie-close.png\', sizingMethod='scale');\"></span>"
		this.nodeClose = $('body')[0].lastChild;

		
		$( this.nodeClose ).click( function(){ _this.Close(); } )
		
		
		this.nodeGalerie = $('body').append( "<div style='width:"+_this.Width+"px;height:"+_this.Height+"px;overflow:hidden; border:1px solid #FFFFFF;display:none;position:absolute;z-index:" + ( _this.zIndex + 2 ) + ";background-color:#000000;'></div>" )[0].lastChild;
		$(this.nodeGalerie).append( "<div style='width:100000px;height:10000px;'></div>" );
		
		// Galerie Buttons
		$(this.nodeRight).css('cursor','pointer').fadeTo( 0, 0.9 ).attr('title','Page suivante').click( function() {
			if ( _this.CurrentPage + 1 >= _this.Pages.length ) return;
			_this.ScrollPage( _this.CurrentPage+1 )
		}).hover( function( ) { $(this).attr('src','/images/galerie/right-roll.png'); }, function() { $(this).attr('src','/images/galerie/right.png'); } );
		$(this.nodeLeft).css('cursor','pointer').fadeTo( 0, 0.9 ).attr('title','Page précédente').click( function() {
			if ( _this.CurrentPage < 1 ) return;
			_this.ScrollPage( _this.CurrentPage-1 )
		}).hover( function( ) { $(this).attr('src','/images/galerie/left-roll.png'); }, function() { $(this).attr('src','/images/galerie/left.png'); } );		
			
		
	}
	
	//MASK
	$( this.nodeMask ).drawAllScreen(  { zIndex : _this.zIndex } ).show( ).fadeTo( 0, 0.9 );
	
	
	// Load galerie service (could return galerie or direct slideshow)
	this.Show(  );
	this.LoadGalerie();
	
}




AMCMSGalerie.prototype.launchInContent = function( )
{
	var _this = this;
	
	this.CurrentPage = 0;
	this.CurrentPicto = null;
	
	this.Width = this.ContentWidth;
	this.Height = this.ContentHeight;
	
	//Galerie en mode Slide dans contenu
	if( this.GalerieType == 3 )
	{
		this.Rows = 1;
		this.Columns = 1;
	}	
	
	//Première ouverture
	if ( this.nodeGalerie == null )
	{	
		
		var sHtmlNode = "";
		sHtmlNode += "<div style='background-color:#000000;border:1px solid #5798c6;width:" +(this.Width+100)+ "' ><center>";
		sHtmlNode += "<table cellspacing='0' cellpadding='0' width='" + (this.Width+100) + "'><tbody>";
		sHtmlNode += "	<tr>";
		sHtmlNode += "		<td valign='middle' width='50' align='right'><img class='MaskLeft' src='/images/galerie/left.png' alt='' width='35' style='cursor:pointer;'/></td>";
		sHtmlNode += "		<td valign='middle' width='" + this.Width + "' align='center'><center><div class='galerie_container' style='width:" +this.Width+ "px;height:" + this.Height + "px;overflow:hidden;border:0px solid red;'></div></center></td>";
		sHtmlNode += "		<td valign='middle' width='50' align='left'><img class='MaskRight' src='/images/galerie/right.png' alt='' width='35' style='cursor:pointer;'/></td>";
		sHtmlNode += "	</tr>";
		sHtmlNode += "</tbody></table></center></div>";
		$(this.node).append( sHtmlNode );
		
		
		//Container des Picto
		this.nodeGalerie = $(this.node).find( "*.galerie_container" )[ 0 ];
		//$( this.nodeGalerie ).css( "border", "1px solid green" );
		$(this.nodeGalerie).append( "<div style='width:100000px;height:10000px;'></div>" ); //Pour slide des pages
								
				
		// Galerie Buttons
		this.nodeRight = $(this.node).find( ".MaskRight" );
		this.nodeLeft = $(this.node).find( ".MaskLeft" );		
		
		$(this.nodeRight).css('cursor','pointer').fadeTo( 0, 0.9 ).attr('title','Page suivante').click( function() {
			if ( _this.CurrentPage + 1 >= _this.Pages.length ) return;
			_this.ScrollPage( _this.CurrentPage+1 )
		}).hover( function( ) { $(this).attr('src','/images/galerie/right-roll.png'); }, function() { $(this).attr('src','/images/galerie/right.png'); } );
		$(this.nodeLeft).css('cursor','pointer').fadeTo( 0, 0.9 ).attr('title','Page précédente').click( function() {
			if ( _this.CurrentPage < 1 ) return;
			_this.ScrollPage( _this.CurrentPage-1 )
		}).hover( function( ) { $(this).attr('src','/images/galerie/left-roll.png'); }, function() { $(this).attr('src','/images/galerie/left.png'); } );		

		//MASK
		$( this.nodeMask ).drawAllScreen(  { zIndex : _this.zIndex } ).fadeTo( 0, 0.9 ).hide( );		

	}
	this.LoadGalerie();
	
	
}

AMCMSGalerie.prototype.LoadGalerie = function( ) 
{
	var _this = this;
	var oLoading = null;
	oLoading = $( "body" ).append( "<div style='position:absolute;z-index:" + ( _this.zIndex + 1000 ) + ";'><table><tr><td>En cours de chargement</td></tr><tr><td align='center'><img src='images/icones/loading.gif' /></td></tr></table></div>" )[ 0 ].lastChild;
	$( oLoading ).drawCenter( this.nodeGalerie );


	$.ajax({ 
		url: "/web-services/Medias/getGalerie.aspx?id="+ this.id, 
		type: "GET",
		cache: false,
		data: "",
		success: function(data){
			var indexPages = 0;
			var indexPhotos = 0;
			
			$(data).find("galerie").each( function( ) {
				_this.SlideDuration = parseInt( $( this ).attr( "duration" ) );
				_this.SlideTransition = $( this ).attr( "transition" );
			} );
			
			$(data).find("slide").each( function( ) {
				var oPhoto = { name: $(this).find("title").text(), legend: $(this).find("legend").text(), thumb: $(this).find("path_small").text(), photo: $(this).find("path").text(), height: $(this).find("height").text(), width: $(this).find("width").text() };
				if ( indexPhotos >= _this.Rows * _this.Columns )
				{
					indexPhotos = 0;
					indexPages++;
					_this.Pages[indexPages] = { ul: null, photos: [] };
				}
				_this.Pages[indexPages].photos[indexPhotos] = oPhoto;
				indexPhotos++;
			} );
						
			$( oLoading ).remove();
			_this.BuildPages();
			_this.UpdateFleches();
			_this.Show();
			
			//Si 
			if( _this.GalerieType == 3 && !_this.Slide )	
			{
				_this.EnableIconeLoupe(  );
			}
			return false;
		}
	});
	

}


AMCMSGalerie.prototype.BuildPages = function( ) 
{
	var _this = this;
	
	//VIDE LE CONTENU
	$(this.nodeGalerie.firstChild).html( "" );
		
	this.CurrentPage = 0;
	
	//PARAMETRES d'affichage
	var iContainerWidth = $( _this.nodeGalerie ).width();
	var iContainerHeight = $( _this.nodeGalerie ).height();
	
	if( iContainerHeight == 0 && this.GalerieType != 1 )
	{
		iContainerWidth = this.ContentWidth;
		iContainerHeight = this.ContentHeight;
	}
	
	var iRows = _this.Rows;
	var iColumns = _this.Columns;
	var iSpacing = _this.Spacing;
	if( _this.Slide )
	{
		iRows 		= _this.SlideRows;
		iColumns 	= _this.SlideColumns;		
		iSpacing 	= _this.SlideSpacing;
	}
	
	
	//Si galerie ne contient qu'une page : on centre le contenu verticalement et horizontalement
	if( _this.Pages.length == 1 && !_this.Slide  )
	{
		
		var iRowHeigth = Math.floor( iContainerHeight / iRows ) + iSpacing;
		iRows =  Math.ceil( _this.Pages[ 0 ].photos.length / iColumns );
		iContainerHeight = Math.floor( $( _this.nodeGalerie ).height() * iRows / this.Rows );	
		$( _this.nodeGalerie ).height( iContainerHeight );
		
		
		if( this.GalerieType != 1 ) 	
			$( _this.node ).height( iContainerHeight );
	}
	
	
	var iLiWidth = Math.round( ( iContainerWidth - ( ( iColumns + 1 ) * iSpacing ) ) / iColumns ) ;
	var iLiHeight = Math.round( ( iContainerHeight - ( ( iRows + 1 ) * iSpacing ) ) / iRows ) ;
	
	var iImgWidthMax = iLiWidth;
	var iImgHeightMax = iLiHeight;
	
	var aHeight = new Array();
	if( !_this.Slide )
	{
		iImgHeightMax = iImgHeightMax - 17;
	}
	
	
	var iPhotoIndex = 0;
	//***PAGES***
	for ( var i = 0 ; i < _this.Pages.length ; i++ )
	{
		var oUL = document.createElement( "ul" );
		oUL.className = 'gallery';
		$( oUL ).css( "width" , iContainerWidth+"px" );
		
		//***PICTOS***
		_this.Pages[i].ul = oUL;
		for ( var ii = 0 ; ii < _this.Pages[i].photos.length ; ii++)
		{	
			var oDimension = GetImageDimensionRatioSlide( _this.Pages[i].photos[ii].width, _this.Pages[i].photos[ii].height, iImgWidthMax-1, iImgHeightMax-1 );
			var iImgHeight = oDimension.HEIGHT;
			var iImgWidth = oDimension.WIDTH;
			if( iImgHeight > iImgHeightMax )		
			{
				iImgHeight = iImgHeightMax;
			}
			aHeight[ aHeight.length ] = iImgHeight;
			
			//***Picto***
			var sClassBorder = "class='PictoBorder'";
			var sBorderOver = "	<div class='PictoBorderState' style='width:"+(iImgWidthMax)+"px;height:"+(iImgHeightMax)+"px;position:absolute;border:2px solid #5798c6;display:none;'></div>"; //Bidouille de Robert pour bien caler sur IE le border bleu
			var sImgLoupe = "";
			
			if( this.GalerieType == 3 && !this.Slide )	//Format Slide dans Contenu : cache les borders
			{
				sClassBorder = "";
				sBorderOver = "";
			}
			
			var sSrc = "";
			sSrc = _this.Pages[i].photos[ii].thumb;
			
			//Si Slide dans contenu MODE=3 alors on affiche dynamiquement les images d'origine
			if( this.GalerieType == 3 && !this.Slide )
			{
				if( i==0 || i==1 )	sSrc = _this.Pages[i].photos[ii].photo;
				else			sSrc = "images/blank.gif";
			}
			
			var sHtmlLi = "<li page='"+ i +"' + photo='"+ ii +"' index='"+iPhotoIndex+"'  style='width:"+ iLiWidth +"px ;height:" + iLiHeight + "px;margin-left:"+ _this.Spacing +";margin-top:" +_this.Spacing+ "px;'>";
			sHtmlLi 	+= sBorderOver;
			
			sHtmlLi 	+= "	<table cellspacing='0' cellpadding='0' height='100%' width='100%' style='margin-left:0px;margin-top:0px;'>";
			sHtmlLi 	+= "		<tr height='" + iImgHeightMax + "'>";
			sHtmlLi 	+= "			<td " + sClassBorder + " valign='middle' align='center' width='"+ iImgWidthMax+ "' height='" +iImgHeightMax+ "'>";
			sHtmlLi		+= sImgLoupe;
			sHtmlLi 	+= "				<img class='gallery_picto' src='/"+sSrc+"' photo='/"+_this.Pages[i].photos[ii].photo+"' photo_height='"+_this.Pages[i].photos[ii].height+"' photo_width='"+_this.Pages[i].photos[ii].width+"' title=\"" + _this.Pages[i].photos[ii].name + "\" alt=\"" + _this.Pages[i].photos[ii].legend + "\" border='0' height='"+ iImgHeight +"' />";
			sHtmlLi 	+= "			</td>";
			sHtmlLi 	+= "		</tr>";
			
			
			if( !_this.Slide )
			{
				var sText = _this.Pages[i].photos[ii].name;
				var sTextAlign = "";
				var iNbMaxChar = Math.floor( iImgWidthMax / 6 );
				
				if( sText.length > iNbMaxChar )
					sText = sText.substring( 0,iNbMaxChar ) + "...";
					
				if( this.GalerieType == 3 && !this.Slide )
				{
					sText = _this.Pages[i].photos[ii].name;
					sText += "<br/>" + _this.Pages[i].photos[ii].legend;
					sTextAlign = " align='center' ";
				}

				
				sHtmlLi 	+= "	<tr>";
				sHtmlLi 	+= "		<td class='Legend' valign='bottom' " + sTextAlign + ">" + sText + "</td>";
				sHtmlLi 	+= "	</tr>";
			}
			sHtmlLi 	+= "</table>";
			sHtmlLi 	+= "</li>";
			
			
			
			var oCurrentLi = $(oUL).append( sHtmlLi )[0].lastChild;
			
			//***Action sur Picto***
			$( oCurrentLi ).mouseover( function(){ _this.PictoOver( this  );}).mouseout( function(){ _this.PictoOut( this  ); });					
			if( !_this.Slide )
			{
				$( oCurrentLi ).click( function(){
					_this.EnableSlideShow( this );
					_this.PictoOut( this  );
				});
			}
			else
			{
				$( oCurrentLi ).click( function(){
					_this.ScrollPicto( this  );
					_this.PictoOut( this  );
				});			
			}
			
			iPhotoIndex++;
		}
		
		$(this.nodeGalerie.firstChild).append( oUL );
		
		
		//Si Slide a une seul page : on centre les pictos
		
		if( _this.Pages.length == 1  )
		{
			if( _this.Pages[0].photos.length < iColumns )
			{
				$( oUL ).width( (iLiWidth+iSpacing)*_this.Pages[0].photos.length + iSpacing );
				$( oUL ).css( "margin-left" , Math.floor( ( $( this.nodeGalerie ).width() - $( oUL ).width() ) / 2 ) );
				
			}	
			
		}	
	}
	
	//Bidouille By ROBOT : pour être sûr que le container des images est de la même taille pour tous
	var iHeightMaxPictoBorder = 0;
	var iWidthMaxPictoBorder = 0;
	$(this.nodeGalerie).find( "td.PictoBorder" ).each( function(){ 
	
		if( $(this).height() > iHeightMaxPictoBorder ) 
			iHeightMaxPictoBorder = $(this).height();
			
		if( $(this).width() > iWidthMaxPictoBorder ) 
			iWidthMaxPictoBorder = $(this).width();			
	} )
	$(this.nodeGalerie).find( "td.PictoBorder" ).height(iHeightMaxPictoBorder).width( iWidthMaxPictoBorder );
	$(this.nodeGalerie).find( "div.PictoBorderState" ).height(iHeightMaxPictoBorder).width( iWidthMaxPictoBorder );
		
	
}



AMCMSGalerie.prototype._getLeftIndexForPage = function( page )
{
	var index = 0;
	for ( var i = 0 ; i < page ; i++ )
	{
		index += $(this.Pages[i].ul).outerWidth();
	}
	return index;
}


//ACTIONS SUR PICTO
AMCMSGalerie.prototype.PictoOver = function( p_oLi ) 
{
	var iIndex = parseInt( $( p_oLi ).attr( "index" ) );
	if( this.CurrentPicto == null || iIndex != this.CurrentPicto )
	{
		$( p_oLi ).find( "div.PictoBorderState" ).css( "border-color", "#5798c6" ).show();
		$( p_oLi ).find( "*.PictoBorder" ).attr( "class", "PictoBorderHide" )	
	}
	else
	{
		$( p_oLi ).find( "div.PictoBorderState" ).css( "border-color", "#FFFFFF" ).show();
		$( p_oLi ).find( "*.PictoBorder" ).attr( "class", "PictoBorderHide" )		
	}
}
AMCMSGalerie.prototype.PictoOut = function( p_oLi ) 
{
	var iIndex = parseInt( $( p_oLi ).attr( "index" ) );
	if( this.CurrentPicto == null || iIndex != this.CurrentPicto )
	{	
		$( p_oLi ).find( "div.PictoBorderState" ).hide();
		$( p_oLi ).find( "*.PictoBorderHide" ).attr( "class", "PictoBorder" );
	}
	else
	{
		$( p_oLi ).find( "div.PictoBorderState" ).hide();
		$( p_oLi ).find( "*.PictoBorderHide" ).attr( "class", "PictoBorder" );
	}
}

//ACTIVATION DU MODE SLIDESHOW
AMCMSGalerie.prototype.EnableSlideShow = function( p_oLi ) 
{	
	var _this = this;
	this.Slide = true;
	
	//Suppression des anciens noeuds
	this.DestroySlideShow();

	
	var iCurrentPhoto = this.CurrentPicto;
	if(p_oLi)	iCurrentPhoto = parseInt( $(p_oLi).attr( "index" ) )
	
	
	//On active le zoom pour l'image courante
	this.DrawSlideShow( $( this.nodeGalerie ).find( "li[ index='" + iCurrentPhoto + "' ]" ) );
	
	//BOUTON RETOUR VERS GALERIE
	this.nodeSlideButtonClose = $( "body" ).append( "<img src=\"images/galerie/galerie-close.png\" width=\"26\" style='cursor:pointer;position:absolute;z-index:" + ( _this.zIndex + 1000 ) + ";left:0;top:0;display:none;'/>" )[ 0 ].lastChild;
	$( this.nodeSlideButtonClose ).click( function(){ _this.DisableSlideShow() } )
	
	
	//REDIMENSIONNEMENT DE LA GALERIE EN BAS DE PAGE
	//Si la galerie est dans un contenu ==> Il le fait passer en position absolute
	if( this.GalerieType != 1 )
	{
		$(this.nodeGalerie).css( "position", "absolute" ).css( "z-index", this.zIndex + 100 );
		$(this.nodeLeft).css( "position", "absolute" ).css( "z-index", this.zIndex + 100 );
		$(this.nodeRight).css( "position", "absolute" ).css( "z-index", this.zIndex + 100 );
	}
	$(this.nodeGalerie).height( this.SlideHeight );
	$(this.nodeGalerie).width( $( "body" ).width() - $(this.nodeLeft).width() - $(this.nodeRight).width() - 50 );
	$(this.nodeGalerie).css( "background-color", "" );
	$(this.nodeGalerie).css( "border", "0" );
	
	
	//Construction des pages du Slide
	//1°)On recalcule les positions pour les pages et photos
	var tmp = new Array();
	tmp[0] = { ul: null, photos: [] };
	
	var indexPhotos = 0;
	var indexPages = 0;
	for( var i=0; i< this.Pages.length; i++ )
	{
		for( var ii=0; ii< this.Pages[ i ].photos.length; ii++ )
		{
			var oPhoto = this.Pages[ i ].photos[ ii ];
			
			if ( indexPhotos >= _this.SlideRows * _this.SlideColumns )
			{
				indexPhotos = 0;
				indexPages++;
				tmp[indexPages] = { ul: null, photos: [] };
			}
			tmp[indexPages].photos[indexPhotos] = oPhoto;
			indexPhotos++;			
		}
	}
	this.Pages = tmp;
	this.BuildPages(  );
	
	var iCurrentPage = Math.floor( iCurrentPhoto / (this.SlideRows * this.SlideColumns) );
	this.ScrollPage( iCurrentPage );
	this.Show();
		
}




AMCMSGalerie.prototype.DrawSlideShow = function( p_oLi )
{
	var _this = this;
	
	
	//$( this.nodeGalerie ).find( "*.PictoBorderOn" ).each( function(){ $(this).attr( "class", "PictoBorder" ); } )
	$( this.nodeGalerie ).find( "div.PictoBorderState" ).hide();
	$( this.nodeGalerie ).find( "*.PictoBorderHide" ).attr( "class", "PictoBorder" )
	
	//ACTIVATION DU PICTO DE NAVIGATION
	$( p_oLi ).find( "div.PictoBorderState" ).show().css( "border-color", "#FFFFFF" );
	$( p_oLi ).find( "*.PictoBorder" ).attr( "class", "PictoBorderHide" );
	this.CurrentPicto = parseInt( $( p_oLi ).attr( "index" ) );
	
	
	//DRAW CONTAINER SLIDE
	var iContainerWidth = $.clientCoords().w - 250;
	var iContainerHeight = $.clientCoords().h - this.SlideHeight - 120;
	
	var iContainerLeft = Math.floor( ( $.clientCoords().w - iContainerWidth ) / 2 );
	var iContainerTop = Math.floor( ( $.clientCoords().h - iContainerHeight -  this.SlideHeight ) / 2 );
	iContainerTop += $(window).scrollTop();
	
	
	var sHTMLSlideContainer = "<div class='gallery slidecontainer' style='border:0px solid red;position:absolute;z-index:" + ( _this.zIndex + 10 ) + ";width:" +iContainerWidth+ "px;height:" +iContainerHeight+ "px;left:" + iContainerLeft + ";top:" + iContainerTop + "'></div>";
	this.nodeSlideContainer = $( "body" ).append( sHTMLSlideContainer )[ 0 ].lastChild;
	
	
	//DRAW FLECHES SLIDE
	var iNodeSlideMoveWidth = 58;
	var iNodeSlideMoveHeight = 117;
	var topMove = iContainerTop + iContainerHeight / 2 - iNodeSlideMoveHeight/2 ;
	//***-->Précédent
	var leftMoveLeft = iContainerLeft - iNodeSlideMoveWidth - 20;
	$( this.nodeSlideLeft  ).css( "top", topMove ).css( "left", leftMoveLeft );	
	if( this.CurrentPicto > 0 )		$( this.nodeSlideLeft ).show();
	else					$( this.nodeSlideLeft ).hide();
	//***-->Suivant
	var rightMoveRight = iContainerLeft  + iContainerWidth  + 20;
	$( this.nodeSlideRight ).css( "top", topMove ).css( "left", rightMoveRight );	
	var iLastIndex = $(this.nodeGalerie).find( "li" ).length;
	if( this.CurrentPicto < iLastIndex-1 )		$( this.nodeSlideRight ).show();
	else						$( this.nodeSlideRight ).hide();
	//***--> Events
	$(this.nodeSlideRight).css('cursor','pointer').fadeTo( 0, 0.9 ).attr('title','Photo suivante').hover( function( ) { $(this).attr('src','/images/galerie/right-roll.png'); }, function() { $(this).attr('src','/images/galerie/right.png'); } );
	$(this.nodeSlideLeft).css('cursor','pointer').fadeTo( 0, 0.9 ).attr('title','Photo précédente').hover( function( ) { $(this).attr('src','/images/galerie/left-roll.png'); }, function() { $(this).attr('src','/images/galerie/left.png'); } );		
	
	
	
	//*****--> Lecture Pause 
	this.nodeSlideButtonPlay = $( "body" ).append( "<div style='border:0px solid red;position:absolute;z-index:" + ( _this.zIndex + 1000 ) + ";width:550px;height:350px;'><img src='images/blank.gif' style='background-position: center center;background-repeat: no-repeat;' width='550' height='350' alt='' border='0'/></div>" )[ 0 ].lastChild;		
	var topPlay = iContainerTop + iContainerHeight / 2 - $( this.nodeSlideButtonPlay ).height()/2 ;
	
	var leftPlay = iContainerLeft  + iContainerWidth / 2  - $( this.nodeSlideButtonPlay ).width()/2;
	$( this.nodeSlideButtonPlay ).css( "top", topPlay ).css( "left", leftPlay );
	
	$( this.nodeSlideButtonPlay ).find( "img" ).mouseover( function( e ){ _this.ShowButtonPlay(); return false;  } );
	$( this.nodeSlideButtonPlay ).find( "img" ).mouseout( function( e ){ _this.HideButtonPlay(); return false; } );
	$( this.nodeSlideButtonPlay ).find( "img" ).click( function(){ _this.SlidePlay() } );
	
	$( this.nodeSlideButtonPlay ).hover( 
		function( e ){ e.preventDefault(); return false; }, 
		function( e ){ e.preventDefault(); return false; } 
	);
	
	
	//CONTENUS DU CONTAINER DU SLIDE ==> On charge le Src uniquement de l'image courante + Prev et Next
	//Les autres sont chargés à la volée
	var iIndex = 0;
	var oCurrentPhoto = null;
	sHTMLSlideContainer = "";
	
	for( var i=0; i<_this.Pages.length; i++ )
	{
		for( var j=0; j<_this.Pages[i].photos.length ; j++ )
		{
			var oPhoto = _this.Pages[i].photos[j];
			var oDimension = GetImageDimensionRatioSlide( oPhoto.width, oPhoto.height, iContainerWidth, iContainerHeight );
			oPhoto.marginLeft = Math.round( ( iContainerWidth - oDimension.WIDTH ) / 2 ); 
			oPhoto.marginTop = Math.round( ( iContainerHeight - oDimension.HEIGHT ) / 2 ); 
		
			if( iIndex == this.CurrentPicto )	oCurrentPhoto = oPhoto;
			
			var sSrc = "";
			if( iIndex >= this.CurrentPicto - 1 && iIndex <= this.CurrentPicto + 1  )	sSrc = oPhoto.photo;
				
			sHTMLSlideContainer += "<img class='position"+ iIndex +"' index='" + iIndex + "' path='" + oPhoto.photo + "' src='" +sSrc+ "' style='position: absolute; margin-top: "+oPhoto.marginTop+"; margin-left: " +oPhoto.marginLeft+ "; display: block; opacity: 1; width: " +oDimension.WIDTH+ "px; height: " + oDimension.HEIGHT + "px;border:1px solid #FFFFFF;'/>";	
			
			iIndex++;
		}
	}
	
	$(this.nodeSlideContainer).html( sHTMLSlideContainer );
	$( this.nodeSlideContainer ).css( "top" , iContainerTop ).css( "left" , iContainerLeft );

	
	//BUTTONS du Slide
	$( this.nodeSlideRight ).click( function(){ _this.ScrollNextPicto(  ); })
	$( this.nodeSlideLeft ).click( function(){  _this.ScrollPrevPicto(  ); })
	
		
	//Activation de la transition : cycle
	this.BuildSlideTransition();

	//Container du texte de l'image
	var topText = iContainerTop + oCurrentPhoto.marginTop + oCurrentPhoto.height;
	var leftText = iContainerLeft + oCurrentPhoto.marginLeft;
	this.nodeSlideText = $( "body" ).append( "<div class='galleryzoomLegend' style='position:absolute;z-index:" + ( _this.zIndex + 10 ) + ";left:"+ leftText + ";top:" + topText + "'>"+ oCurrentPhoto.name+"<br/>"+oCurrentPhoto.legend +"</div>" )[ 0 ].lastChild;
}


AMCMSGalerie.prototype.DisableSlideShow = function( )
{
	var _this = this;
	this.Slide = false;
	this.CurrentPicto = null;
	
	
	this.DestroySlideShow();


	//Redimensionnement du container
	$(this.nodeGalerie).height( this.Height );
	$(this.nodeGalerie).width( this.Width );
	$(this.nodeGalerie).css( "background-color", "#000000" );
	$(this.nodeGalerie).css( "border", "1px solid #FFFFFF" );

	//Galerie dans contenu
	if( this.GalerieType != 1 )
	{
		document.body.style.overflow=''; 
		$(this.nodeMask).hide();
		$(this.nodeGalerie).css( "position", "" );
		$(this.nodeLeft).css( "position", "" );
		$(this.nodeRight).css( "position", "" );	
		$(this.nodeGalerie).css( "border", "0" );
	}
	
	//Construction des pages du Slide
	//1°)On recalcule les positions pour les pages et photos
	var tmp = new Array();
	tmp[0] = { ul: null, photos: [] };
	
	var indexPhotos = 0;
	var indexPages = 0;
	for( var i=0; i< this.Pages.length; i++ )
	{
		for( var ii=0; ii< this.Pages[ i ].photos.length; ii++ )
		{
			var oPhoto = this.Pages[ i ].photos[ ii ];
			
			if ( indexPhotos >= _this.Rows * _this.Columns )
			{
				indexPhotos = 0;
				indexPages++;
				tmp[indexPages] = { ul: null, photos: [] };
			}
			tmp[indexPages].photos[indexPhotos] = oPhoto;
			indexPhotos++;			
		}
	}
	this.Pages = tmp;
	this.BuildPages(  );
	
	var iCurrentPage = Math.floor( this.CurrentPicto / (this.Rows * this.Columns) );
	this.ScrollPage( iCurrentPage );
	this.Show();	
}
AMCMSGalerie.prototype.DestroySlideShow = function(  )
{
	//Suppression des noeuds
	$(this.nodeSlideMask ).remove();
	$(this.nodeSlideContainer).cycle( "destroy" );
	$(this.nodeSlideRight).hide();
	$(this.nodeSlideLeft).hide();
	$(this.nodeSlideContainer).remove();
	$(this.nodeSlideText).remove();
	$(this.nodeSlideButtonPlay).remove();
	$(this.nodeSlideButtonClose).remove();
}



//BUTTON PLAY
AMCMSGalerie.prototype.AnimationPlaying = false;

AMCMSGalerie.prototype.ShowButtonPlay = function(  )
{
	var oImgPlay = $( this.nodeSlideButtonPlay ).find( "img" )[ 0 ];
	if( this.AnimationPlaying )
		$( oImgPlay ).css( "background-image", "url('images/galerie/pause.png')" ).css( 'cursor', 'pointer' )
	else
		$( oImgPlay ).css( "background-image", "url('images/galerie/play.png')" ).css( 'cursor', 'pointer' )

}
AMCMSGalerie.prototype.HideButtonPlay = function(  )
{
	var oImgPlay = $( this.nodeSlideButtonPlay ).find( "img" )[ 0 ];	
	$( oImgPlay ).css( "background-image", "none" ).css( 'cursor', 'normal' )
}
AMCMSGalerie.prototype.SlidePlay = function(  )
{
	var oImgPlay = $( this.nodeSlideButtonPlay ).find( "img" )[ 0 ];
	//On passe en play
	if( this.AnimationPlaying )
	{
		$( this.nodeSlideContainer ).cycle( "pause" );
		$( oImgPlay ).css( "background-image", "url('images/galerie/play.png')" ).css( 'cursor', 'pointer' )
	}
	else
	{
		$( this.nodeSlideContainer ).cycle( "resume" );
		$( oImgPlay ).css( "background-image", "url('images/galerie/pause.png')" ).css( 'cursor', 'pointer' )
	}
	this.AnimationPlaying = !this.AnimationPlaying;
}

AMCMSGalerie.prototype.SlideTextUpdate = function(  )
{
	if( typeof this.CurrentPicto != "undefined" && this.nodeSlideText )
	{
		var oPhoto = this.getPhoto( this.CurrentPicto );
		var sText = "";
		sText += oPhoto.name + "<br/>" + oPhoto.legend;
		$( this.nodeSlideText ).html( sText );
		
		var oImage = $(this.nodeSlideContainer).find( "img[ index='"+ this.CurrentPicto +"' ]" )[ 0 ];
		
		var iLeft = parseInt( $( oImage ).css( "margin-left" ).replace( "px", "" ) ) + $(this.nodeSlideContainer).offset(  ).left;
		var iTop = parseInt( $( oImage ).css( "margin-top" ).replace( "px", "" ) ) + $(this.nodeSlideContainer).offset(  ).top + $( oImage ).height();
		$( this.nodeSlideText ).css( "left", iLeft ).css( "top", iTop );
	}
}


AMCMSGalerie.prototype.EnableIconeLoupe = function(  )
{
	var _this = this;
	
	//Affiche la loupe
	if( _this.GalerieType == 3 && !_this.Slide )
	{	
		var oLi = $( _this.Pages[_this.CurrentPage].ul ).find( "li" )[ 0 ];
		var oImg = $( oLi ).find( "img.gallery_picto" )[ 0 ];
		var iMarginTop =  $(oImg).height() - 20;
		var iMarginLeft = $(oImg).width() - 20;
		
		if ( $.browser.msie && parseInt($.browser.version) < 7 ) 
			_this.nodeLoupe = $( "<span class='IEFauxBouttons' style=\"" + "width:16px;margin-top:" +iMarginTop+ "px;margin-left:" + iMarginLeft + "px;z-index:" + ( this.zIndex+1000000 ) + "; display:inline-block;position:absolute;cursor:pointer;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/icones/loupe_big.png\', sizingMethod='scale');\"></span>" ).insertBefore( oImg );
		else
			_this.nodeLoupe = $( "<img src=\"/images/icones/loupe_big.png\" style=\"position:absolute;margin-top:" +iMarginTop+ "px;margin-left:" + iMarginLeft + "px;\" width='16' />" ).insertBefore( oImg );
	}	
}

AMCMSGalerie.prototype.ScrollPage = function( p_iPageIndex )
{
	var _this = this;
	_this.CurrentPage = p_iPageIndex;	
	$( _this.nodeLoupe ).remove();
	
	$(_this.nodeGalerie).animate({ scrollLeft: _this._getLeftIndexForPage( p_iPageIndex ) }, 500, function(){ _this.EnableIconeLoupe();} );

	_this.UpdateFleches();
	
	//Chargement dynamique des images
	if( this.GalerieType == 3 && !this.Slide )
	{
		var oImg = $( _this.Pages[p_iPageIndex+1].ul ).find( "img.gallery_picto" )[ 0 ];
		if( $(oImg).attr( "src" ).indexOf( "blank.gif" ) >= 0 )
		{
			$(oImg).attr( "src", $(oImg).attr( "photo" ) );
		}
	}
	
}


AMCMSGalerie.prototype.ScrollPicto = function( p_oLi )
{
	var _this = this;
	this.CurrentPicto = parseInt( $(p_oLi).attr( "index" ) );
	

	this.BuildSlideTransition();
	this.ScrollNavigationMAJ();
}

AMCMSGalerie.prototype.BuildSlideTransition = function( )
{
	var _this = this;
	
	var transition = _this.SlideTransition;
	
	$( this.nodeSlideContainer ).cycle( "destroy" );
	this.AnimationPlaying = true;
	$( this.nodeSlideContainer ).cycle( {
	    fx: transition
	    ,speed:  400
	    ,startingSlide : _this.CurrentPicto
	    ,prev:  _this.nodeSlideLeft
	    ,next:  _this.nodeSlideRight
	    ,timeout: _this.SlideDuration * 1000  //Manuel = 0
	    ,before : function(){ 
					$(_this.nodeSlideText).hide(); 
					$(_this.nodeSlideButtonClose).hide(); 
				}
	    ,after : function(){ 
					$(_this.nodeSlideText).show();
					$(_this.nodeSlideButtonClose).show();
					
					//MAJ index Picto
					$(_this.nodeSlideContainer).find( "img" ).each( function(){
						if( $(this).css( "display" ) != "none" )
						{
							_this.CurrentPicto = parseInt( $(this).attr( "index" ) );
						}
					} )
					
					_this.LoadSlideImages(  );
					_this.ScrollNavigationMAJ(); 
					_this.SlideTextUpdate();
				}
	} )
	
	//Etat de lecture courant
	var oImgPlay = $( this.nodeSlideButtonPlay ).find( "img" )[ 0 ];
	if( $( oImgPlay ).attr( "src" ).indexOf( "play" ) >= 0 )	
	{
		$( this.nodeSlideContainer ).cycle( "pause" );
	}
}




AMCMSGalerie.prototype.ScrollNextPicto = function(  )
{
	var _this = this;
	this.CurrentPicto = this.CurrentPicto + 1;
	this.LoadSlideImages(  );
	
	//Mise à jour de la barre de navigation du bas
	var iPage = Math.floor( this.CurrentPicto / (this.SlideRows * this.SlideColumns) );
	if( iPage != this.CurrentPage )
		this.ScrollPage( iPage );
		
	return;
}

AMCMSGalerie.prototype.ScrollPrevPicto = function(  )
{
	var _this = this;
	this.CurrentPicto = this.CurrentPicto - 1;
	this.LoadSlideImages(  );

	//Mise à jour de la barre de navigation du bas
	var iPage = Math.floor( this.CurrentPicto / (this.SlideRows * this.SlideColumns) );
	if( iPage != this.CurrentPage )
		this.ScrollPage( iPage );	
	
	return;
}

AMCMSGalerie.prototype.ScrollNavigationMAJ = function(  )
{
	
	var oCurrentLi = $( this.nodeGalerie ).find( "li[ index='"+this.CurrentPicto+"' ]" );
	
	//ACTIVATION DU PICTO DE NAVIGATION
	$( this.nodeGalerie ).find( "div.PictoBorderState" ).hide();
	$( this.nodeGalerie ).find( "*.PictoBorderHide" ).attr( "class", "PictoBorder" );
	$( oCurrentLi ).find( "*.PictoBorder" ).attr( "class", "PictoBorderHide" );
	$( oCurrentLi ).find( "div.PictoBorderState" ).show().css( "border-color", "#FFFFFF" );	
		
	//MAJ des flèches de scroll de Slide
	if( this.CurrentPicto > 0 )
		$(this.nodeSlideLeft).show();
	else
		$(this.nodeSlideLeft).hide();
		
	var iLastIndex = $(this.nodeGalerie).find( "li" ).length;
	if( this.CurrentPicto < iLastIndex-1 )
	{
		$(this.nodeSlideRight).show();
	}	
	else
		$(this.nodeSlideRight).hide();
		
	//Place le bouton de fermeture
	var oImg = $( this.nodeSlideContainer ).find( "img[ index='" + this.CurrentPicto + "' ]" )[ 0 ];
	if( oImg != null )
	{
		var iLeft = $( oImg ).offset().left + $( oImg ).width() - $( this.nodeSlideButtonClose ).width()/2;
		var iTop = $( oImg ).offset().top - $( this.nodeSlideButtonClose ).height()/2;
		$( this.nodeSlideButtonClose ).css( "left", iLeft ).css( "top", iTop ).show();
	}
	
}


//Chargement des IMAGES DU SLIDE à la volée
AMCMSGalerie.prototype.LoadSlideImages = function(  )
{
	//Charge l'image courante
	var oCurrentImage = $(this.nodeSlideContainer).find( "img[ index='"+ this.CurrentPicto +"' ]" )[ 0 ];
	if( $(oCurrentImage).attr( "src" ) == "" )
			$(oCurrentImage).attr( "src", $(oCurrentImage).attr( "path" ) );
	
	
	//Charge l'image d'avant
	var iPrevIndex = this.CurrentPicto-1;	
	var oPrevImage = null;
	if( $(this.nodeSlideContainer).find( "img[ index='"+ iPrevIndex +"' ]" ).length > 0 )
	{
		oPrevImage = $(this.nodeSlideContainer).find( "img[ index='"+ iPrevIndex +"' ]" )[ 0 ];
		if( $(oPrevImage).attr( "src" ) == "" )
			$(oPrevImage).attr( "src", $(oPrevImage).attr( "path" ) );
	}
	
	
	//Charge l'image d'après
	var iNextIndex = this.CurrentPicto+1;
	var oNextImage = null;
	if( $(this.nodeSlideContainer).find( "img[ index='"+ iNextIndex +"' ]" ).length > 0 )
	{
		oNextImage = $(this.nodeSlideContainer).find( "img[ index='"+ iNextIndex +"' ]" )[ 0 ];
		if( $(oNextImage).attr( "src" ) == "" )
			$(oNextImage).attr( "src", $(oNextImage).attr( "path" ) );
	}
}



AMCMSGalerie.prototype.UpdateFleches = function( ) 
{
	if ( this.Pages.length <= 1 )
	{
		$(this.nodeLeft).hide();
		$(this.nodeRight).hide();
	}
	else if ( this.CurrentPage + 1 >= this.Pages.length )
	{
		$(this.nodeLeft).show();
		$(this.nodeRight).hide();
	}
	else if ( this.CurrentPage == 0 )
	{
		$(this.nodeLeft).hide();
		if ( this.Pages.length > 1 )
			$(this.nodeRight).show();
		else
			$(this.nodeRight).hide();
	}
	else
	{
		$(this.nodeLeft).show();
		$(this.nodeRight).show();
	}
	
}


AMCMSGalerie.prototype.Show = function( ) 
{	
	var _this = this;
	
	//On réaffiche la barre de scroll de la fenêtre 
	if( this.GalerieType == 1 || this.Slide )
		document.body.style.overflow='hidden'; 
	
	
	var deltaWidth = Math.floor( ( $.clientCoords().w - $(this.nodeGalerie).outerWidth() ) / 2 );
	var deltaHeight = Math.floor( ( $.clientCoords().h - $(this.nodeGalerie).outerHeight() ) / 2 );
	deltaHeight += $(window).scrollTop();
	
	
	//On place Mask de navigation du Slide 
	if( this.Slide ) 
	{
		deltaHeight = $.clientCoords().h + $(window).scrollTop();
		this.nodeSlideMask = $('body').append( "<div style='width:"+ $.clientCoords().w +"px;height:"+this.SlideHeight+"px;position:absolute;z-index:" + (9999 ) + ";background-color:#000000;'></div>" )[0].lastChild;
		$( this.nodeSlideMask ).css('border-top', "2px solid #5798c6" );
		$( this.nodeSlideMask ).css('top', ( deltaHeight ) +'px');
	}
	
	//Place la galerie
	$(this.nodeGalerie).show().css('left', deltaWidth+'px').css('top', deltaHeight+'px');
	$(this.nodeGalerie)[0].scrollLeft = 0;
	
	//Slide à partir d'une image
	if( this.Slide )
	{
		if( this.GalerieType != 1 )	
		{
			$(this.nodeMask ).show();
		}
		$(this.nodeSlideMask).animate({ top: deltaHeight-this.SlideHeight }, 500 );
		$(this.nodeGalerie).animate({ top: deltaHeight-this.SlideHeight }, 500 , function(){ 
			var topMiddle = $(_this.nodeGalerie).offset().top + Math.floor( ($(_this.nodeGalerie).outerHeight() - $(_this.nodeLeft).outerHeight()) / 2 );
			$(_this.nodeRight).css('top', topMiddle+'px');
			$(_this.nodeLeft).css('top', topMiddle+'px');	

			_this.ScrollNavigationMAJ();
			_this.SlideTextUpdate();
		} );
	}
	
	
	
	//Button CLOSE
	if( this.nodeClose )
	{
		if( !this.Slide )
		{
			$( this.nodeClose ).show();
			$( this.nodeClose ).css('left', $(this.nodeGalerie).offset().left + $(this.nodeGalerie).width() - 10 ).css('top', $(this.nodeGalerie).offset().top - 10);
		}
		else
		{
			$( this.nodeClose ).hide();
		}
	}
	
	// Show Right/Left ?
	if ( this.Pages.length > 1 )
	{
		//Taille des flèches
		if( this.Slide )
		{
			$( this.nodeRight ).height( 50 );
			$( this.nodeLeft ).height( 50 );
		}
		else
		{
			$( this.nodeRight ).height( "" );
			$( this.nodeLeft ).height( "" );
		}
	
		var topMiddle = $(this.nodeGalerie).offset().top + Math.floor( ($(this.nodeGalerie).outerHeight() - $(this.nodeLeft).outerHeight()) / 2 );
		$(this.nodeRight).css('left', (deltaWidth+$(this.nodeGalerie).outerWidth()+6)+'px').css('top', topMiddle+'px').css( "z-index", ( _this.zIndex + 1000 ) );
		$(this.nodeLeft).css('left', (deltaWidth-$(this.nodeLeft).outerWidth()-6)+'px').css('top', topMiddle+'px').css( "z-index", ( _this.zIndex + 1000 ) );	
	}
}
AMCMSGalerie.prototype.Close = function( ) 
{
	
	$(this.nodeGalerie).hide();
	$(this.nodeClose).hide();
	$(this.nodeMask).hide();
	$(this.nodeRight).hide();
	$(this.nodeLeft).hide();
	
	document.body.style.overflow=''; 
}
AMCMSGalerie.prototype.getPhoto = function( p_iIndex )
{
	var iIndex = 0;
	for( var i=0; i<this.Pages.length; i++ )
	{
		for( var j=0; j<this.Pages[i].photos.length ; j++ )
		{
			if( iIndex == p_iIndex  )
				return this.Pages[i].photos[j];
			
			iIndex++;
		}
	}
	return null;
}

function GetImageDimensionRatioSlide( p_iSrcImgWidth, p_iSrcImgHeight, p_iMaxWidth, p_iMaxHeight )
{
	//Si image plus petit que container on renvoie l'image
	if( p_iSrcImgHeight < p_iMaxHeight && p_iSrcImgWidth < p_iMaxWidth )	return  { WIDTH :p_iSrcImgWidth, HEIGHT : p_iSrcImgHeight  };
	
	var iImgHeight = p_iSrcImgHeight;
	var iImgWidth = p_iSrcImgWidth;		
	
	if( iImgWidth == 0 )	iImgWidth = p_iMaxWidth;
	
	var iMaxWidth = p_iMaxWidth;
	var iMaxHeight = p_iMaxHeight;

	var ratio = 1.0;
	//Image paysage
	if( iImgWidth > iImgHeight )
	{
		ratio = iMaxWidth / iImgWidth;
		iImgWidth = iImgWidth * ratio;
		iImgHeight = iImgHeight * ratio;
		
		if( iImgHeight > iMaxHeight )
		{
			ratio = iMaxHeight / iImgHeight;
			iImgHeight = iMaxHeight;
			iImgWidth = iImgWidth * ratio;
		}
	}
	else
	{
		ratio = iMaxHeight / iImgHeight;
		iImgWidth = iImgWidth * ratio;
		iImgHeight = iImgHeight * ratio;
		
		if( iImgWidth > iMaxWidth )
		{
			ratio = iMaxWidth / iImgWidth;
			iImgWidth = iMaxWidth;
			iImgHeight = iImgHeight * ratio;
		}						
	}
	iImgWidth = Math.floor( iImgWidth )
	iImgHeight = Math.floor( iImgHeight )
	return { WIDTH :iImgWidth, HEIGHT : iImgHeight  };
	
}


//TRANSITIONS CUSTOMIZE
//Utile pour les transition horizontal
$.fn.cycle.transitions.scrollHorizontal = function($cont, $slides, opts) {

	$cont.css('overflow','hidden');
	opts.before.push($.fn.cycle.commonReset);
	// custom transition fn (trying to get it to scroll forward and backward)
	opts.fxFn = function(curr, next, opts, cb, fwd) {
		var w = $cont.width();
		opts.cssFirst = { left: 0 };
		opts.animIn	  = { left: 0 };
		if(fwd){

			opts.cssBefore= { left: w, top: 0 };
			opts.animOut  = { left: 0-w };

		}else{
			opts.cssBefore= { left: -w, top: 0 };
			opts.animOut  = { left: w };
		};
		var $l = $(curr), $n = $(next);
		var speedIn = opts.speedIn, speedOut = opts.speedOut, easeIn = opts.easeIn, easeOut = opts.easeOut, animOut = opts.animOut, animIn = opts.animIn;
		$n.css(opts.cssBefore);
		var fn = function() {$n.show();$n.animate(animIn, speedIn, easeIn, cb);};
		$l.animate(animOut, speedOut, easeOut, function() {
			if (opts.cssAfter) $l.css(opts.cssAfter);
			if (!opts.sync) fn();
		});
		if (opts.sync) fn();
	};

};
//Utile pour les transition vertical
$.fn.cycle.transitions.scrollVertical = function($cont, $slides, opts) {

	$cont.css('overflow','hidden');
	opts.before.push($.fn.cycle.commonReset);
	// custom transition fn (trying to get it to scroll forward and backward)
	opts.fxFn = function(curr, next, opts, cb, fwd) {
		var h = $cont.height();
		opts.cssFirst = { top: 0 };
		opts.animIn	  = { top: 0 };
		if(fwd){

			opts.cssBefore= { top: h, left: 0 };
			opts.animOut  = { top: 0-h };

		}else{
			opts.cssBefore= { top: -h, left: 0 };
			opts.animOut  = { top: h };
		};
		
		var $l = $(curr), $n = $(next);
		var speedIn = opts.speedIn, speedOut = opts.speedOut, easeIn = opts.easeIn, easeOut = opts.easeOut, animOut = opts.animOut, animIn = opts.animIn;
		$n.css(opts.cssBefore);
		var fn = function() {$n.show();$n.animate(animIn, speedIn, easeIn, cb);};
		$l.animate(animOut, speedOut, easeOut, function() {
			if (opts.cssAfter) $l.css(opts.cssAfter);
			if (!opts.sync) fn();
		});
		if (opts.sync) fn();
	};

};

