function rPrintDebugInfo( pMessage )
{
	var lDebugParagraph = document.getElementById('DebugP');
	if( lDebugParagraph && ( pMessage != null ))
	{
		var lText = "\n"; lText += pMessage;
		lDebugParagraph.innerHTML += lText;
	}
}

function PrintObjectDebugInfo( pObject )
{
	var lMessage='';
	var lCount = 0;
	var lSkipCount = 0;

	for( lProprety in pObject )
	{
		if( pObject[ lProprety ] )
		{
			if( lSkipCount <= 0 )
			{
				lMessage = lCount + ':' + lProprety + ' --value :'+ String( pObject[ lProprety ] ) + '  Type :'+  typeof lProprety +'  ; <br>';
				rPrintDebugInfo( lMessage );
			}
			else
			{
				lSkipCount--;
			}

			/*if( lCount > 150 )
			{
				lCount = 0;
				lMessage+= "\n";
			}*/

			lCount++;
		}
	}

	lMessage = '<br>' + pObject.nodeName + '  -Id :' + pObject.id  +'  -Count : ' + lCount+' -- '+ pObject +'\n' + lMessage + '  Type :'+  typeof pObject +'<br><br>';
	


	rPrintDebugInfo( lMessage );
}

function getDimensionXYWH( pElement )
{
	var lObject = pElement;

	if( !lObject )
	{
		return {x :0, y : 0, w : 0,  h : 0};	
	}

	var lObjectOffsetTop = 0;
	var lObjectOffsetLeft = 0;
	var lWidth = lObject.offsetWidth;
	var lHeight = lObject.offsetHeight;
	
	while( lObject != null )
	{
		lObjectOffsetTop += lObject.offsetTop;
		lObjectOffsetLeft += lObject.offsetLeft;
		lObject = lObject.offsetParent;
	}
	
	/*document.write('XYWH: '+lObjectOffsetLeft+','+lObjectOffsetTop+'-'+ lWidth+','+lHeight+' Nom:'+pElementIdName+'<br>');*/

	return {x : lObjectOffsetLeft, y : lObjectOffsetTop, w : lWidth,  h :lHeight };
}




function FinAndUnderlineCurrentLink()
{
	var lLinkArray = document.getElementsByTagName("a");

	var lDocumentUrl = document.location.href;

	if( lDocumentUrl.indexOf( ".php" ) <= 0 )
	{
		if( lDocumentUrl.indexOf( ".htm" ) <= 0 )
		{
			if( lDocumentUrl.indexOf( ".html" ) <= 0 )
			{
				lDocumentUrl += 'index.php';			/* la page par default */
			}
		}
	}	

	for( var lIndex = 0; lIndex < lLinkArray.length; lIndex++ )
	{
		var lLinkUrl = lLinkArray[ lIndex ].href;
		
		if( lLinkUrl )
		{
			var lHaveAGoodLink = ( lDocumentUrl == lLinkUrl);

			if( !lHaveAGoodLink )
			{
				if( lDocumentUrl.indexOf( lLinkUrl ) >= 0 )
				{
					lHaveAGoodLink = true;
				}
				else
				{
					if( lLinkUrl.indexOf( lDocumentUrl ) >= 0 )
					{
						lHaveAGoodLink = true;
					}
					else
					{
					}
				}
			}
			
			if( lHaveAGoodLink)
			{
				if( lLinkArray[ lIndex ].id.indexOf("DontUnderline") < 0 ) 
				{
					if( lLinkArray[ lIndex ].className.indexOf("Active") < 0 ) 
					{

						var lHaveActiveClassVersion = false;

						if( lLinkArray[ lIndex ].className.length > 0 )
						{// have a classname
							if( document.styleSheets )
							{
								var lSearchName1 = lLinkArray[ lIndex ].className + 'Active';

								for( var lCssIndex = 0; (lCssIndex < document.styleSheets.length) && (!lHaveActiveClassVersion); lCssIndex++ )
								{
									var lStyleSheet = document.styleSheets[ lCssIndex ];								
									var lRuleTotalCount = 0;
									if( lStyleSheet.cssRules )	{ lRuleTotalCount = lStyleSheet.cssRules.length; } 
									else						{ lRuleTotalCount = lStyleSheet.rules.length; }

									for( var lRuleIndex=0; (lRuleIndex < lRuleTotalCount) && (!lHaveActiveClassVersion); lRuleIndex++ )
									{
										var lCSSRule	= false; 

										if( lStyleSheet.cssRules )	{ lCSSRule = lStyleSheet.cssRules[lRuleIndex]; } 
										else						{ lCSSRule = lStyleSheet.rules[lRuleIndex]; }

										if( lCSSRule )  
										{
											if( lCSSRule.selectorText.indexOf( lSearchName1 ) >= 0 )
											{
												lLinkArray[ lIndex ].className = lSearchName1;
												lHaveActiveClassVersion = true;
											}
										}
									}

								}// scan all css
							}// have a style sheet
						}// link have a className



						//lLinkArray[ lIndex ].className = lLinkArray[ lIndex ].className + 'Active';

						if( !lHaveActiveClassVersion )
						{
							lLinkArray[ lIndex ].style.textDecoration='underline';
							//lLinkArray[ lIndex ].style.color='#cc9999';
						}// underline by default
					}
				}
			}
		}
	}
}


function SetAlphaStyle( pObject, pPercentAlpha )
{
	var lAlpha01 = pPercentAlpha / 100.0;
    if( "opacity" in pObject.style )		{ pObject.style.opacity = lAlpha01; }
    if( "MozOpacity" in pObject.style )		{ pObject.style.MozOpacity = lAlpha01; }
    if( "KhtmlOpacity" in pObject.style )	{ pObject.style.KhtmlOpacity = lAlpha01; }
	if( "filters" in pObject )				{ pObject.filters.item("alpha").opacity = pPercentAlpha; }
}

function SetForegroundAndBackgroundImage( pBackgroundGroundElement, pForeGroundElement, pImage1, pImage2, pWidth, pHeight )
{
	pForeGroundElement.innerHTML ='<img src="'+ pImage1 +'" width="'+ pWidth +'" height="'+ pHeight +'">';
	pBackgroundGroundElement.style.backgroundImage = "url('" + pImage2 + "')";

}


GlobalImageArrayLastIndex	= 0;
GlobalImageArrayIndex		= 1;
GlobalPreloadImage			= new Array();


function ProgramNextImage()
{
	window.setTimeout( ShowImageSequence, 1000 );
}

function ShowImageSequence()
{

	var pWidth = 422; var pHeight = 167;

	var pForegroundDivId	= 'ZoneImage';
	var pBackgroundDivId	= 'ZoneBackground';

	if( GlobalPreloadImage.length >= 2 )
	{

		if( GlobalPreloadImage[ GlobalImageArrayLastIndex ].complete && GlobalPreloadImage[ GlobalImageArrayIndex ].complete )
		{

			FadeImage( pBackgroundDivId, pForegroundDivId, GlobalPreloadImage[ GlobalImageArrayLastIndex].src, GlobalPreloadImage[ GlobalImageArrayIndex ].src, pWidth,  pHeight  );

			
			GlobalImageArrayLastIndex = GlobalImageArrayIndex;
			GlobalImageArrayIndex ++;
			if( GlobalImageArrayIndex >= GlobalPreloadImage.length )
			{
				GlobalImageArrayIndex = 0;
			}
		}
		else
		{
			//rPrintDebugInfo( 'Need to wait for downloading image : ' + GlobalPreloadImage[ GlobalImageArrayLastIndex].src +' next ->'+ GlobalPreloadImage[ GlobalImageArrayIndex ].src );
			window.setTimeout( ShowImageSequence, 500 );
		}
	}
	
}


function FadeImage( pBackgroundDivId, pForegroundDivId, pImage1, pImage2, pWidth, pHeight )
{

	var lBackgroundGroundElement	= document.getElementById( pBackgroundDivId );
	var lForeGroundElement			= document.getElementById( pForegroundDivId );

	if( (!lBackgroundGroundElement) || (!lForeGroundElement) )	{ return; }

	//lForeGroundElement.innerHTML ='<img src="'+ pImage1 +'" width="'+ pWidth +'" height="'+ pHeight +'">';
	//lBackgroundGroundElement.style.backgroundImage = "url('" + pImage2 + "')";
	//SetForegroundAndBackgroundImage( lBackgroundGroundElement, lForeGroundElement, pImage1, pImage2, pWidth, pHeight );

	

	var lDeltaSpeed = 0;
	var lDelta = -2;

	var lMin	= 0;
	var lMax	= 99;
	var lValue	= 99;

	var lImageIndex = 1;

	var lTimeDelta = 20; // millisecond

	var lWaitTime = ( (1) * 1000 ) / lTimeDelta; //() = wait time in second
	var	lWait = 0;


	SetForegroundAndBackgroundImage( lBackgroundGroundElement, lForeGroundElement, pImage1, pImage1, pWidth, pHeight );
	SetAlphaStyle( lForeGroundElement, 100 );
	SetForegroundAndBackgroundImage( lBackgroundGroundElement, lForeGroundElement, pImage1, pImage2, pWidth, pHeight );

	var lIntervalId = setInterval( 
		function()
		{

			if( lWait > 0 ){ lWait--; return; }
			

			if( lValue >= lMax  )	{ lValue = lMax; lDelta = -Math.abs( lDelta );  }
			if( lValue <= lMin )	
			{ 
					//lValue = lMin; lDelta = Math.abs( lDelta );
					lValue = lMax;

					/*lImageIndex++;
					if( lImageIndex >=  pImageArray.length )
					{
						lImageIndex = 0;
					}

					lLastImage = lNextImage;
					lNextImage = pImageArray[ lImageIndex ];

					SetForegroundAndBackgroundImage( lBackgroundGroundElement, lForeGroundElement, lLastImage, lLastImage, pWidth, pHeight );
					//SetAlphaStyle( lForeGroundElement, lValue );
					
					SetForegroundAndBackgroundImage( lBackgroundGroundElement, lForeGroundElement, lLastImage, lNextImage, pWidth, pHeight );
					SetAlphaStyle( lForeGroundElement, lValue );*/

					clearInterval( lIntervalId );
					ProgramNextImage();

					//lWait = lWaitTime;
					//lWait = ( (1) * 1000 ) / 20;
			}
			else
			{
				lDelta += lDeltaSpeed;
				lValue += lDelta;

				SetAlphaStyle( lForeGroundElement, lValue );
			}

			//rPrintDebugInfo( 'Alpha :'+lValue );


		}
	, lTimeDelta );
}

function GetFunctionIsDefined( pFunctionName )
{
	if( eval("window." + pFunctionName) )
	{
		return true;
	}

	return false;
}



function OnLoadLocalEvent()
{
	FinAndUnderlineCurrentLink();

	if( GetFunctionIsDefined( 'GetRealisationImageSequenceArray' ) )
	{
		var lImageNameArray = GetRealisationImageSequenceArray();
		
		for( var lIndex = 0; lIndex < lImageNameArray.length; lIndex ++ )
		{
			GlobalPreloadImage[ lIndex ] = new Image;
			GlobalPreloadImage[ lIndex ].src = lImageNameArray[ lIndex ];
		}
		ProgramNextImage();		
	}	
}


//_____________________________________________________________________________
window.onload	= OnLoadLocalEvent;
//_____________________________________________________________________________
