    /*------------------------------------------------------------------------------
    Function:       footnoteLinks()
    Author:         Aaron Gustafson (aaron at easy-designs dot net)
    Creation Date:  8 May 2005
    Version:        1.3
    Homepage:       http://www.easy-designs.net/code/footnoteLinks/
    License:        Creative Commons Attribution-ShareAlike 2.0 License
                    http://creativecommons.org/licenses/by-sa/2.0/
    Note:           If you change or improve on this script, please let us know by 
                    emailing the author (above) with a link to your demo page.
    ------------------------------------------------------------------------------*/
    
    /*
    <h2 class="printOnly">Links</h2>
    <ol class="printOnly">
        <li>http://www.easy-designs.net/articles/replaceSelect2</li>
        <li>http://www.mozilla.org/products/firefox/</li>
        <li>http://chrispederick.com/work/firefox/webdeveloper/</li>
    </ol>
    */
    
    /*
    containerID : id of container we are grabbing the URIs from
    targetID : id of the target container for our footnotes
    dans la css screen : .printOnly{display:none}
    pour que des liens n'apparaissent pas dans le footnotes, leur ajouter la class "printIgnore"
    */
    
var $myPrint = {
    linksListTitleTag : "h2",
    linksListTitleText : "Liens évoqués ci-dessus",

    footnoteLinks : function (containerID,targetID) {
      if (!document.getElementById || 
          !document.getElementsByTagName ||
          !document.createElement) return false;
      if (!document.getElementById(containerID) ||
          !document.getElementById(targetID)) return false;
      var container          = document.getElementById(containerID),
          target             = document.getElementById(targetID),
          linksListTitleTag  = document.createElement($myPrint.linksListTitleTag),
          linksListTitleText = document.createTextNode($myPrint.linksListTitleText),
          //coll               = container.getElementsByTagName('*'),
          coll               = container.getElementsByTagName('a'),
          ol                 = document.createElement('ol'),
          myArr              = [],
          thisLink,
          num                = 1;
      addClass.apply(linksListTitleTag,['printOnly']);
      linksListTitleTag.appendChild(linksListTitleText);
      addClass.apply(ol,['printOnly']);
      for (var i=0; i<coll.length; i++) {
        var thisClass = coll[i].className;
        if ( (coll[i].getAttribute('href') && coll[i].getAttribute('href').indexOf('mailto') === -1/*||
              coll[i].getAttribute('cite')*/) &&
              (thisClass === '' ||
               thisClass.indexOf('printIgnore') === -1)) {
          thisLink = coll[i].getAttribute('href') ? coll[i].href : coll[i].cite;
          var note = document.createElement('sup'),
              note_txt,
              j    = inArray.apply(myArr,[thisLink]);
          addClass.apply(note,['printOnly']);
          if ( j || j===0 ) {
            note_txt = document.createTextNode(j+1);
          } else {
            var li     = document.createElement('li'),
                li_txt = document.createTextNode(thisLink);
            li.appendChild(li_txt);
            ol.appendChild(li);
            myArr.push(thisLink);
            note_txt = document.createTextNode(num);
            num++;
          }
          note.appendChild(note_txt);
          if (coll[i].tagName.toLowerCase() == 'blockquote') {
            var lastChild = lastChildContainingText.apply(coll[i]);
            lastChild.appendChild(note);
          } else {
            coll[i].parentNode.insertBefore(note, coll[i].nextSibling);
          }
        }
      }
      target.appendChild(linksListTitleTag);
      target.appendChild(ol);
      addClass.apply(document.getElementsByTagName('html')[0],['noted']);
      return true;
    }
}
    
function inArray(needle) {
  for (var i=0; i < this.length; i++) {
    if (this[i] === needle) {
      return i;
    }
  }
  return false;
}

function addClass(theClass) {
  if (this.className != '') {
    this.className += ' ' + theClass;
  } else {
    this.className = theClass;
  }
}

function lastChildContainingText() {
  var testChild = this.lastChild;
  var contentCntnr = ['p','li','dd'];
  while (testChild.nodeType != 1) {
    testChild = testChild.previousSibling;
  } 
  var tag = testChild.tagName.toLowerCase();
  var tagInArr = inArray.apply(contentCntnr, [tag]);
  if (!tagInArr && tagInArr!==0) {
    testChild = lastChildContainingText.apply(testChild);
  }
  return testChild;
}

$myEvents.addLoadEvent(function(){
	$myPrint.footnoteLinks('hresume','footnotes');
});