/***************      CONSTANTS ***********************************************/
TOOGLE_CLOSED = "closed";
TOOGLE_OPEN = "open";

/*************** HOW TO CALL METHODS ******************************************/
/* This script will show or hide content displayed in a block. It is          */
/* associated to a style sheet named toggle.css                               */
/* Methods that can be used in this script are  :                             */
/*     - void toggleContentVisibility(container)
/* sample :  <div id="blockContainer"
                  class="open" onClick="toggleContentVisibility(this)" >      */
/* For this sample, when the blockContainer will be clicked the method will   */
/* close it.                                                                  */
/*     - void cancelBubble(event)
/* sample : <div class="toggle-body" onClick="cancelBubble(event)">           */
/* This method permit to cancel method toggleContentVisbility propagation in  */
/* block container body.                                                      */
/*     - void toggleContentsVisibility(arrayOfContainer)
/* sample  : toggleContentsVisibility(new Array('container4', 'container5')); */
/* This method will close container 4 and 5 if there are opened, else open it.*/
/*     - void showContents(arrayOfContainer)
/* sample : showContents(new Array('container4', 'container5'));              */
/* This method will show contents of container 4 and 5.                       */
/*     - void hideContents(arrayOfContainer)
/* sample  : hideContents(new Array('container4', 'container5'));             */
/* Thiw method will hide contents of container 4 and 5.                       */
/******************************************************************************/


/** toggle content visibility
 * param : container -> HTML element DIV
 */
function toggleContentVisibility(container)
{
    // is it closed? Open it
	if (container.className.match(TOOGLE_CLOSED)) {
	   showContent(container);
    }
    else {
	// it's open, so close it
        hideContent(container);
    }
}

/**
 * cancel event propagation ( this propagation is named bubble effect by IE
 * param : ev -> event
 */
function cancelBubble(ev)
{
    //cancel buble event for IE
    ev.cancelBubble = true;
    //stop propagation event for Firefox
    if (ev.stopPropagation)
       ev.stopPropagation();
}

/**
 *  open current content
 * param : el -> element
 */
function showContent(el)
{
 el.className = el.className.replace(/closed/gi, TOOGLE_OPEN);
}

/*
 * close current content
 * param : el -> element
 */
function hideContent(el)
{
    el.className = el.className.replace(/open/gi, TOOGLE_CLOSED);
}

