/**
 * Extension of Prototype
 */
Object.extend(Element, {
   getClassParameters: function(element, prefix) {
     if (arguments.length < 2) {
       prefix = 'param';
     }
     var match = new RegExp(prefix + '-\\w*=\\S*', 'g');
     var attrs = element.className.match(match);
     var params = new Array();
     if (attrs) {
       for (var i=0;i<attrs.length;i++) {
           var match = new RegExp(prefix + '-(\\w*)=(\\S*)');
           var parts=attrs[i].match(match);
           params[parts[1]] = parts[2];
       }
     }
     return params;
   },
   getClassParameter: function(element, param, prefix) {
       if (arguments.length < 3) {
           prefix = 'param';
       }
       var match = new RegExp(prefix + '-' + param + '=(\\S*)');
       var parts=element.className.match(match);
       if (parts) {
           return parts[1];
       }
   },
   hiliteKeywords: function(el, keywords, hiliteClass) {
      if (!hiliteClass) {
        var hiliteClass = 'hilite';
      }
      if (!keywords || el.childNodes.length == 0) {
        return;
      }

      var keywordsRegExp = new RegExp(keywords.join("|"), "i");

      var doHilite = function(node,matchRegExp,hiliteClass) {
          var match = matchRegExp.exec(node.data);
          if (match) {
              var hiliteNode = node.splitText(match.index);
              hiliteNode = hiliteNode.splitText(match[0].length);
              var spanNode = node.ownerDocument.createElement('SPAN');
              node.parentNode.replaceChild(spanNode, hiliteNode);
              spanNode.className = hiliteClass;
              spanNode.appendChild(hiliteNode);
          }
      };

      var skipElementsRegExp = /^(script|style|textarea)/i;
      var count = 0;
      var node = el.childNodes[0];

      while (node && depth > 0) {
          count ++;
          if (node.nodeType == 1) { // ELEMENT_NODE
              if (!skipElementsRegExp.test(node.tagName) && node.childNodes.length > 0) {
                  node = node.childNodes[0];
                  depth ++;
                  continue;
              }
          } else if (node.nodeType == 3) { // TEXT_NODE
              doHilite(node,keywordsRegExp,hiliteClass);
          }
          while (!node.nextSibling && depth > 0) {
              node = node.parentNode;
              depth --;
          }
          if (node.nextSibling) {
              node = node.nextSibling;
          }
      }
    }

});
