/**
 * This script is for Java syntax highlighting using Eclipse IDE
 * style colours and fonts.
 * 
 * @author Adarsh Ramamurthy
 * @version 1.0, 30th April 2006
 */
var keywords = 
    ['private', 'static', 'final', 'null', 'try', 'catch',
     'throw', 'throws', 'transient', 'volatile', 'return',
     'synchronized', 'new', 'finally', 'import', 'class',
     'interface', 'public', 'protected', 'int', 'byte',
     'short', 'double', 'float', 'long', 'if', 'while',
     'do', 'else', 'for', 'break', 'switch', 'default',
     'case', 'package', 'extends', 'implements', 'abstract',
     'instanceof', 'strictfp', 'super', 'this', 'true', 'false'
     ];

var keywordpattern = keywords.join('\\b|\\b');

var keywordEx = new RegExp('(\\b'+keywordpattern+'\\b)', 'gm');
var commentEx = new RegExp('(//.*)$', 'gm');
var stringEx  = new RegExp('("[^"]*")', 'gm');

/**
 * Performs syntax-highlighting of Java code, eclipse style
 */
new function highlightCode()
{
    for(id in codeIds)
    {
        var codeDiv = document.getElementById(codeIds[id]);
        
        if(codeDiv)
        {
            var code = codeDiv.innerHTML;

            code = code.replace(stringEx, '<span id="string">$1</span>');
            code = code.replace(keywordEx, '<span id="keyword">$1</span>');
            var commentLine = '' + code.match(commentEx);
            commentLine = commentLine.replace(/keyword/g, 'not-keyword');
            code = code.replace(commentEx, '<span id="linecomment">'+commentLine+'</span>');
            document.getElementById(codeIds[id]).innerHTML = code;
        }
    }
}

/**
 * Performs syntax-highlighting of JavaDoc comments, eclipse style
 */
new function highlightJavaDoc()
{
    for(id in javadocIds)
    {
        var javadocDiv = document.getElementById(javadocIds[id]);
        
        if(javadocDiv)
        {
            var javadoc = javadocDiv.innerHTML;
            
            javadoc = javadoc.replace(/(&lt;[^&gt;]*&gt;)/g, '<span class="javadoc-htmltag">$1</span>');
            javadoc = javadoc.replace(/(@[a-z]*)/g, '<span class="javadoc-annotation">$1</span>');

            document.getElementById(javadocIds[id]).innerHTML = javadoc;
        }
    }
}
