var easeAnimateId;
var easing = false;
function mondoEaseManagerClass()
{
	var coeffease = 0.2;
	this.coeffease = 0.2;

	var ArrivedNegligence = Math.floor( 1 / 0.2 );
	this.ArrivedNegligence = ArrivedNegligence;
	
	var TabDesiredWidth = new Array();
	this.TabDesiredWidth = TabDesiredWidth;
	
	var TabCurrentWidth = new Array();
	this.TabCurrentWidth = TabCurrentWidth;

	var TabDesiredHeight = new Array();
	this.TabDesiredHeight = TabDesiredHeight;
	
	var TabCurrentHeight = new Array();
	this.TabCurrentHeight = TabCurrentHeight;
	
	var TabEtats = new Array();
	this.TabEtats = TabEtats;
	
	var TabWidths = new Array();
	this.TabWidths = TabWidths;
	
	var TabDivIDs = new Array();
	this.TabDivIDs = TabDivIDs;

	var Processing = false;
	this.Processing = Processing;
	
	var OutFunction;
	this.OutFunction = OutFunction;

	function setEase( newease )
	{
		this.coeffease = newease;
	}
	this.setEase = setEase;

	function getMovie(movieName) 
	{
		if (navigator.appName.indexOf ("Microsoft") !=-1) 
		{
			return window[movieName]
		}
		else 
		{
			return document[movieName]
		}
	}
	this.getMovie = getMovie;
	function Register( iditem, opened, move, offset )
	{
		if( !exists( iditem ) ){return false;}
		if( exists( opened ) )
		{
			this.TabEtats[iditem] = opened;
		}
		else
		{
			this.TabEtats[iditem] = true;
		}
		
		if( exists( offset ) )
		{
			this.TabWidths[iditem] = document.getElementById( iditem ).offsetHeight + offset;
		}
		else
		{
			this.TabWidths[iditem] = document.getElementById( iditem ).offsetHeight;
		}
		if( ( exists( move ) ) && move == true )
		{
			if( this.TabEtats[iditem] == false )
			{
				document.getElementById( iditem ).style.height = this.TabWidths[iditem] + 'px';
				this.TabEtats[iditem] = false;				
			}
			else
			{
				document.getElementById( iditem ).style.height = '0px';
				this.TabEtats[iditem] = false;				
			}
		}
	}
	this.Register = Register;
	function manageEase( divId, TabBtns, TabEtat )
	{
		// Chaque Div :
		for( var i = 0; i < TabEtat.length; i++ )
		{
			// Si celui cliqué
			if( TabBtns[i] == divId )
			{
				if( TabEtat[i] == false )
				{
					TabEtat[i] = invert( TabEtat[i] );
					mondoEaseManager.EaseOpenClose( divId );
				}
			}
			else if( TabEtat[i] == true )
			{
				TabEtat[i] = invert( TabEtat[i] );
				mondoEaseManager.EaseOpenClose( TabBtns[i] );
			}
		}
	}
	this.manageEase = manageEase;
	function EaseOpenClose( iditem, closeOffset, outFunction )
	{
		var minValue = 0;
		if( exists( closeOffset ) )
		{
			minValue = parseInt(closeOffset);
		}
		if( !exists(iditem) )
		{
			return false;
		}
		if(! exists( this.TabEtats[iditem] ) )
		{
			this.Register( iditem, true );
		}
		if( exists( outFunction ) )
		{
			this.OutFunction = outFunction;
		}
		if( this.TabEtats[iditem] == false)
		{
			this.launchEase( iditem , null, null, minValue, this.TabWidths[iditem] );
			TabEtats[iditem] = true;
		}
		else
		{
			this.launchEase( iditem , null, null, this.TabWidths[iditem], minValue );
			this.TabEtats[iditem] = false;	
		}
	}
	this.EaseOpenClose = EaseOpenClose;
	function launchEase( divid, widthBase, widthCible, heightBase, heightCible, outFunction )
	{
		if( divid == null )
		{return;}
		if( exists( outFunction ) )
		{
			this.OutFunction = outFunction;
		}
		if( exists( widthCible ) )
		{			
			widthCible = tryRemovePx( widthCible );
			this.TabDesiredWidth[divid] = parseInt(widthCible);
			if( !exists( this.TabCurrentWidth[divid] ) )
			{
				if( exists( widthBase ) )
				{
					widthBase = tryRemovePx( widthBase );
				}
				else
				{
					widthBase = document.getElementById( divid ).offsetWidth;
				}
				this.TabCurrentWidth[divid] = parseInt(widthBase);
			}
		}
		if( exists( heightCible ) )
		{
			var TheHeightCible = tryRemovePx( heightCible );
			this.TabDesiredHeight[divid] = parseInt(TheHeightCible);
			if( !exists( this.TabCurrentHeight[divid] ) )
			{
				var TheHeightBase = document.getElementById( divid ).offsetHeight;
				if( exists( heightBase ) )
				{
					TheHeightBase = tryRemovePx( heightBase );
				}
				TheHeightBase = tryRemovePx( TheHeightBase );
				this.TabCurrentHeight[divid] = tryRemovePx( TheHeightBase );
			}
		}
		if( this.TabDivIDs.length < 1 || (!in_array( divid, this.TabDivIDs )) )
		{
			this.TabDivIDs.push( divid );
		}
		if( easing == false )
		{
			easing = true;
			easeAnimateId = setInterval(this.animateEase, 50);
		}
	}
	this.launchEase = launchEase;
	function animateEase()
	{
		var ie = '';
		var nb = 0;
		for( var iid = 0; iid < TabDivIDs.length; iid++ )
		{
			ie = TabDivIDs[iid];
			if( exists( TabCurrentWidth[ie] ) )
			{	
				nb++;
				if( Math.abs( TabDesiredWidth[ie] - TabCurrentWidth[ie] ) < ArrivedNegligence )
				{
					document.getElementById(ie).style.width = TabDesiredWidth[ie] + "px";
					TabCurrentWidth[ie] = TabDesiredWidth[ie];
					deleteEaseParams( iid, true );
				}
				else
				{
					try
					{
						var newWidth = TabCurrentWidth[ie] +  Math.round(  mondoEaseManager.coeffease * ( TabDesiredWidth[ie] - TabCurrentWidth[ie] ) );
						document.getElementById(ie).style.width = newWidth + "px";
						TabCurrentWidth[ie] = newWidth;
					}
					catch( e )
					{
						document.getElementById(ie).style.width = TabDesiredWidth[ie] + "px";
						TabCurrentWidth[ie] = TabDesiredWidth[ie];
					}
				}
			}
			if( exists( TabCurrentHeight[ie] ) )
			{
				nb++;
				var diff =  TabDesiredHeight[ie] - TabCurrentHeight[ie];
				if( Math.abs( TabDesiredHeight[ie] - TabCurrentHeight[ie] ) < ArrivedNegligence )
				{
					TabCurrentHeight[ie] = TabDesiredHeight[ie];
					document.getElementById(ie).style.height = TabDesiredHeight[ie] + "px";
					deleteEaseParams( iid, false );
				}
				else
				{
					try
					{
						var newHeight = TabCurrentHeight[ie] +  Math.round(  mondoEaseManager.coeffease * ( TabDesiredHeight[ie] - TabCurrentHeight[ie] ) );
						document.getElementById(ie).style.height = newHeight + "px";						
						TabCurrentHeight[ie] = newHeight;
					}
					catch( e )
					{
						document.getElementById(ie).style.height = TabDesiredHeight[ie] + "px";
						TabCurrentHeight[ie] = TabDesiredHeight[ie];
						deleteEaseParams( iid, false );
					}
				}
			}
		}
		if(	nb < 1 )
		{
			if( exists( mondoEaseManager.OutFunction ) )
			{
				mondoEaseManager.OutFunction();
				mondoEaseManager.OutFunction = null;
			}
			clearInterval( easeAnimateId );
			easing = false;
		}
	}
	this.animateEase = animateEase;
	
	function deleteEaseParams( id, hor )
	{
		var idtext = TabDivIDs[id];
		TabDivIDs[id] = null;
		if( hor == true )
		{
			TabCurrentWidth[idtext] = null;
			TabDesiredWidth[idtext] = null;
		}
		else
		{
			TabCurrentHeight[idtext] = null;
			TabDesiredHeight[idtext] = null;
		}
	}
	this.deleteEaseParams = deleteEaseParams;
}

var InlineDebug = '';
function tryRemovePx( input )
{
	if( typeof( input ) == 'number' )
	{
		return input;
	}
	else
	{
		if( input.substr( input.length - 2 ) == 'px' )
		{
			input = parseInt( input.substr( 0, input.length - 2 ) );
			return input;
		}
		else
		{
			return input;
		}
	}
}

function exists( maVar )
{
	if ( ( typeof maVar != "undefined" ) && ( maVar != null ) )
	{
		return true;
	}
	else
	{
		return false;	
	}
}

function in_array( str, stack )
{
	for(var k = 0; k < stack.length; k++)
	{
		if( stack[k] == str )
		{
			return true;
		}
	}
	return false;
}
function invert( input )
{
	if( input == true )
	{
		return false;
	}
	else
	{
		return true;
	}
}

var CloseThis = false;
var IdOpened = true;
var TabMenuBtns = new Array();
var TabMenuEtat = new Array();

var mondoEaseManager = new mondoEaseManagerClass();
