/**
 * @package benchmark
 * @subpackage framework
 * @filesource
 */

/**
 * Util permettant d'handler un lien "Lire la suite" afin de réveler
 * la suite du texte de l'élément qui le précède
 *
 * @note le mieux reste d'utiliser l'ObjLireLaSuite.php
 * @exemple :
 * @todo adapter :
 * 	<p>Bla blabla <span class='olls_ensuite'> bla bal blablab blabla </span><a href="" title="">Lire</a> </p>
 *
 * @deprecated :
 * Exemple :
 *  <div id="texte_74">Texte court</div>
 *  <a href="javascript:void(0)" class="olls_suite">Lire la suite</a>
 *  <intput type="hidden" id="texte_74_suite" value="Texte court dont on avait caché cette portion de texte.">
 *
 * @author Benoit Landhauser <landhauser@benchmark.fr>
 * @author Damien BENOIT <benoit@benchmark.fr>
 *
 * @package benchmark
 * @subpackage framework
 * @version 1.00
 * @since 27/05/2009 Anthony Terrien <terrien@benchmark.fr> Conversion classe
 * @since 29/06/2009 Damien BENOIT <benoit@benchmark.fr> corrections pour utilisation dans un seul et unique texte, correction js (scopes, syntaxe, etc) ancien mode deprecated
 */

if(typeof(benchmark) == "undefined") { var benchmark = new Object(); }
if(typeof(benchmark.framework) == "undefined") { benchmark.framework = new Object(); }
if(typeof(benchmark.framework.ihm) == "undefined") { benchmark.framework.ihm = new Object(); }
if(typeof(benchmark.framework.ihm.util) == "undefined") { benchmark.framework.ihm.util = new Object(); }

/**
 * constructeur :
 * @return void
 */
benchmark.framework.ihm.util.ObjLireLaSuite = function(){

	/**
	* initialisation
	* @return void
	*/
	this.initialise = function(){
		this.bindActions();
	};

	/**
	* Applique les binds sur les éléments nécéssaires
	* @return void
	*/
	this.bindActions = function(){
		// nouvelle méthode :
		$('span.olls_ensuite')
    		.before('<span class="olls_hellip">&hellip;</span>')
    		.parent().find('a')
    		.addClass('olls_lien_affiche')
    		.bind(
    				'click',
    				function(event)
    				{
    					event.preventDefault();
    					if($(this).hasClass('olls_lien_affiche'))
    					{
    						// on affiche :
	    					$(this)
	    						.removeClass('olls_lien_affiche')
	    						.addClass('olls_lien_masque')
	    						.attr('title',$(this).attr('titleMasque'))
	    						.html($(this).attr('libellemasque'))
	    						.parent().find('span.olls_ensuite').slideDown(
	    									'normal',
	    									function()
	    									{
	    										$(this).css('display','inline');
	    									}
	    									)
	    						.parent().find('span.olls_hellip').slideUp()
	    						;
    					}
    					else
    					{
    						// on masque :
    	    					$(this)
	    						.removeClass('olls_lien_masque')
	    						.addClass('olls_lien_affiche')
	    						.html($(this).attr('libellesuite'))
	    						.attr('title',$(this).attr('titleSuite'))
	    						.parent().find('span.olls_ensuite').slideUp()
	    						.parent().find('span.olls_hellip').slideDown(
	    								'normal',
    									function()
    									{
    										$(this).css('display','inline');
    									}
	    							)
	    						;
    					}

    				}
    			)
			;

    	// @deprecated :
		// @todo enlever dès que le systeme de commentaires sera passé à la nouvelle structure :
    	$("a[@class=olls_suite]").click(
    	    function(event){
        		event.preventDefault();

        		var nom_input = $(this).attr('name');
        		var position_dernier_underscore = nom_input.lastIndexOf('_');

        		var id_commentaire = nom_input.substr(position_dernier_underscore+1);

        	    // on capture l'element precedent
        	    var bloc = $(this).prev();
        	    var bloc_suite = $( "#" + bloc.attr('id') + "_suite" );

        	    // on intervertit les contenus
        	    // premier clic = ouverture
        	    // second clic = réduction
        		var contenu_a_afficher = bloc_suite.html();
        		if(contenu_a_afficher != ''){
        			$(this).hide();
        			bloc.empty();
        			bloc.append( contenu_a_afficher );
        		}
    		}
    	);
    }
}

<!--
/**
* pour l'instant l'instanciation est automatique
*/
if(typeof(benchmark.execution) 				== "undefined") { benchmark.execution = new Object(); }
if(typeof(benchmark.execution.framework) 	== "undefined") { benchmark.execution.framework = new Object(); }
$(document).ready(
	function()
	{
		if( typeof(benchmark.execution.framework.monObjLireLaSuite) == 'undefined' )
		{
			benchmark.execution.framework.monObjLireLaSuite = new benchmark.framework.ihm.util.ObjLireLaSuite();
			benchmark.execution.framework.monObjLireLaSuite.initialise();
		}
	}
);
//-->
