﻿	// *******************************************************************************************************************
	// Gestion de la hauteur de plusieurs blocs ::: 
	//		Fonction : permet de fixer la hauteur la plus haute à tout les blocs des conteneurs
	// *******************************************************************************************************************
	(function($){
	
		$.fn.FixeHeight = function( ) {
			$.FixeHeight( ).resize( $(this) );
		}
	
		jQuery.FixeHeight = function( selector ) {
			var __ListContent = [];
			var __iMaxHeight = -1;
			var __MaxHeight = 0;
			
			this.add = function ( o ) {
				if( null !== o && 'undefined' == typeof(o) )
					return this;
				else if( null !== o && 'object' == typeof(o) )
					return this.addContent(o);
				else
					return this.addSelector(o);
			},
			this.addSelector = function ( selector ) {
				__writeLog( 'Conteneur ajouté : ' + selector );
				return this.addContent( $(selector) );
			},
			this.addContent = function ( obj ) {
				obj.each(function(){
					__ListContent.push( $(this) );
				});
				__setMaxHeight();
				return this;
			},
			this.resize = function ( o ) {
				
				this.add(o);
				
				if( __iMaxHeight == -1)
				{
					__writeLog( 'Resize : aucun bloc trouvé.' );
				}
				else
				{
					var oStyle = '';
					for( i=0 ; i < __ListContent.length ; i++ )
					{
						oStyle = __ListContent[i].attr( "style" );
						__ListContent[i].attr( "style" ,  (( oStyle != undefined ) ? oStyle : '') + "height:" + __MaxHeight + "px !important;" );
					}
					__writeLog( 'Resize : ' + __MaxHeight + ' px (bloc ' + (__iMaxHeight + 1) + ').' );
				}
				return this;
			},
			/** ********************************************************************* **/
			/** ********************************************************************* **/
			__getMaxHeight = function ( ) {
				
				return this.__getHeight( __iMaxHeight );
			},
			__getHeight = function ( i ) {
				
				return (i != -1 && __ListContent.length > i ) ? __ListContent[i].height() : 0;
			},
			
			__setMaxHeight = function ( ) {

				var height = 0;
				__MaxHeight = __getMaxHeight();
				for( i=0 ; i < __ListContent.length ; i++ )
				{
					height = __getHeight(i);
					if( __MaxHeight < height )
					{
						__MaxHeight = height;
						__iMaxHeight = i;
					}
				}
			},
			/** ********************************************************************* **/
			/** ********************************************************************* **/
			__writeLog = function (s) {
				try 
				{
					if(typeof(console) != 'undefined')
						if(console.log)
							console.log("[jQuery.FixeHeight] " + s);
				}
				catch(err)
				{
				}
			};
			/** ********************************************************************* **/
			/** ********************************************************************* **/

			this.add( selector );
			return this;
		};
	})(jQuery);

