/**
 * Displays all JavaScript source code in corresponding pre element.
 * A pre element matches script, if value title attribute matches string 
 * "code " + script element id.
 * 
 * Example:
 * script with id="example" will be displayed in pre with title="code example"
 * 
 * At the end content of pre element will be formatted
 * 
 * @requires shCore.js
 * @requires clipboard.swf
 * @requires shBrush$Any$.js (for JS use shBrushJScript.js)
 * 
 * @requires SyntaxHighlighter.css
 */
function highlightSources(){
	highlightSource("script", "code");
	highlightSource("style", "style");
}

function highlightSource(tagname, name){
	var objs = YAHOO.util.Dom.getElementsBy(
  		function(el){
	  		if(el.getAttribute("id") == null || el.getAttribute("id").length == 0){
	  			return false;
	  		}
	  		if(el.getAttribute("src") == null || el.getAttribute("src").length == 0){
	  			return true;
	  		}
	  		return false;
	  	},
  		tagname,
  		document.getElementsByTagName("HEAD")[0] 
	);
	for(var i=0; i<objs.length; ++i){
		var o = objs[i];
		var t = YAHOO.util.Dom.getElementsBy(
	  		function(el){
		  		if(el.getAttribute("name") == name && el.getAttribute("title") == o.id){
		  			return true;
		  		}
		  		return false;
		  	},
	  		"pre",
	  		document.body
	  	);
		if(!t || t.length != 1){
			throw t.length+" matching element found for code »" + o.id + "«.";
		}
		t[0].innerHTML = "";
		t[0].appendChild(document.createTextNode( o.innerHTML.trim() ));
	}
	dp.SyntaxHighlighter.ClipboardSwf = './syntaxHighlighter/scripts/clipboard.swf';
	dp.SyntaxHighlighter.HighlightAll(name);
}

registerNodeListener(window, "load", highlightSources);