/*--------------------------------------------------------------------------------------*/ 
/* Function "initHistory": INIT HISTORY                                                 */
/*--------------------------------------------------------------------------------------*/
function initHistory()
{
    biviHistory = new Array();
    historyCookie = ez.cookie.get( 'biviHistory_cookie' );
    
    if( historyCookie )
    {
        biviHistory = historyCookie.split( '||' );
     
        $.each( biviHistory, function( indexHistory )
	                         {
	                            currentContent = biviHistory[indexHistory].split( '##' );
	                           
	                            $( '<li><a href="' +currentContent[2] +'"><strong>' +currentContent[0] +' : </strong>' +currentContent[1] +'</a></li>' ).appendTo( '#historique ul' );
	                         }        
        );
        
        nbSelection = biviHistory.length;
        
        $( '#historique_lnk' ).html( '<strong>' +biviHistory.length +'</strong> document(s)' ).mouseover( function(){ historique_on(); } );
    }
    else
        $( '#historique_lnk' ).html( '<strong>0</strong> document(s)' );
}


/*--------------------------------------------------------------------------------------*/ 
/* Function "addHistory" : ADD current ref to user history                              */
/*--------------------------------------------------------------------------------------*/ 
function addHistory( type, name, url )
{
    ref = type +'##' +name +'##' +url;
    historyCookie = ez.cookie.get( 'biviHistory_cookie' );
    
    if( historyCookie )
        historyList = historyCookie.split( '||' );
    else
        historyList = '';
    
    // Current element isn't in the user history
    if( jQuery.inArray( ref, historyList ) == -1 )
    {
        // Current history have reached the max item number of 10
        if( historyCookie && ( $( '#historique' +' ul li' ).children().size() >=10 ) )
	    {
	       historyList.splice( 9, 1, ref );
	       historyCookie = historyList.join( '||' );
	    }
	    else if( historyCookie )
	       historyCookie += '||' +ref;
        else
           historyCookie = ref;
        
        ez.cookie.set( 'biviHistory_cookie', historyCookie );
    }
}