/****************************************/
/*		FONCTIONS PARSING				*/
/****************************************/

	function getPub() {
		for( i = 0; i < tplPub.length; i ++ ) {
			tplId			= tplPub[ i ] ;
			contentId		= contentPub[ i ] ;
			urlTarget		= urlSite + "Ajax.php?f=" + contentId + "&EasyPage=" + EasyPage ;
			if( $( 'iFramePub_' + tplId ) == null ) {	
				contentIFrame	= "<IFRAME allowtransparency='true' marginHeight='0' marginWidth='0' scrolling='no' frameborder='0' width='" + widthPub[ i ] + "' height='" + heightPub[ i ] + "' id='iFramePub_" + tplId + "' src='" + urlTarget + "'></IFRAME>";
				if( $( 'A_Pub_' + tplId ) != null )	$( 'A_Pub_' + tplId ).update( contentIFrame ) ;
			}
			else	$( 'iFramePub_' + tplId ).src = urlTarget ;
		}
	}

	function goParse( e ) {
		isPageParse = true ;
		var tabParam	= e.split( "#/?" ) ;
		
		if( tabParam[ 1 ] ) {
			var param		= tabParam[ 1 ]
			var first		= param.split( "&" );
			
			for( i = 0; i < first.length; i ++ ) {
				second		= first[ i ].split( "=" );
				if( second[ 0 ] == "f" )	tplId = second[ 1 ] ;
			}

			var tabUrl		= e.split('#/') ;
			var urlTarget	= urlSite + "Ajax.php" + tabUrl[1] ;
			
			//if( tplId == 48 )	new Effect.Opacity( 'UserMenu', {duration:0.2, fps:25, from:1.0, to:0, afterFinish: function() { var ajaxCall	= new Ajax.Request( urlTarget, options ); } });
		
			var options		= { 
								asynchronous:true ,
								method: "get" ,
								onSuccess: function ( xhr ) {
									$( 'A_Div_' + tplId ).update( xhr.responseText ) ;	
									//if( tplId == 48 )	window.setTimeout( function() { new Effect.Opacity( 'UserMenu', {duration:0.2, fps:25, from:0, to:1}); }, 500 ) ;
									curHashVal = window.location.hash ;
									prepareParse() ;
									getParse() ;
									//getPub() ;
								}
							  } 		
			var ajaxCall	= new Ajax.Request( urlTarget, options );
			
		}
		else {
			curHashVal = window.location.hash ;
			getParse() ;
		}
	}

	function detectChangeUrl() {		
		if( curHashVal != window.location.hash ) { 
			curHashVal = window.location.hash ;
			goParse( curHashVal ) ;
		}
		else getParse() ;
	}

	function getParse() {
		window.setTimeout ( detectChangeUrl, 1000);
	}

	function prepareParse() {
		var Liens = $$( 'a' ) ;
		for( var i = 0; i < Liens.length; i++ ) {
			if( Liens[i].id.substring( 0, 4 ) == "A_A_" )	{
				Liens[i].id = Liens[i].id + "_" + i ;
				Event.observe( Liens[i], "click", function( e ) { $( Event.element( e ).id ).addClassName( "selected" ) ; } ); 
			}
		}
	}



/****************************************/
/*		OBSERVATEURS D'ELEMENTS			*/
/****************************************/
	
	var curHashVal	= window.location.hash; //global reference
	var tplId		= null ;
	var tplPub		= [ 6, 31, 9 ] ;
	var contentPub	= [ 163, 164, 162 ] ;
	var widthPub	= [ 299, 728, 120 ] ;
	var heightPub	= [ 250, 90, 600 ] ;

	Event.observe( window, 'load', getParse );
	//Event.observe( window, 'load', getPub );
	Event.observe( window, 'load', prepareParse );
