/*!
 * 代码高亮插件
 * www.JSPGen.com
 * @revise 1.0
 */
;(function($){
    $.fn.highlighter = function(options){
		var jspath = document.scripts;
		jspath = jspath[jspath.length-1].src.substring(0, jspath[jspath.length-1].src.lastIndexOf('/')+1);
		
		/*
		// 转义代码
		var codeEscape  = function(code){
			code = code.replace(/(<)/g,"&lt;");
			code = code.replace(/(>)/g,"&gt;");
			code = code.replace(/ /g, '&nbsp;').replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;');
			return code;
		}
		this.each(function(){
			//$(this).text(codeEscape($(this).text()));
			$(this).html(codeEscape($(this).html()));
		});
		*/
		
		// SyntaxHighlighter
		$("head").append('<link type="text/css" href="'+jspath+'styles/shCore.css" rel="stylesheet" />');
		$("head").append('<link type="text/css" href="'+jspath+'styles/shCoreDefault.css" rel="stylesheet" />');
		$("head").append('<link type="text/css" href="'+jspath+'styles/shThemeDefault.css" rel="stylesheet" />');
		$("head").append('<script type="text/javascript" src="'+jspath+'scripts/shCore.js"></script>');
		$("head").append('<script type="text/javascript" src="'+jspath+'scripts/shAutoloader.js"></script>');
		var path = function(){ 
			var args = arguments, result = [];
			for (var i=0; i<args.length; i++){
				result.push(args[i].replace('@', jspath+'scripts/'));
			}
			return result;
		}
		SyntaxHighlighter.defaults.toolbar = false;
		SyntaxHighlighter.defaults['title'] = '双击代码全选';
		SyntaxHighlighter.config.stripBrs = true;
		if($(this).length>0) SyntaxHighlighter.config.tagName = ($(this).prop("tagName")).toLowerCase();
		SyntaxHighlighter.autoloader.apply(null, path(
			'applescript            @shBrushAppleScript.js',
        	'actionscript3 as3      @shBrushAS3.js',
        	'bash shell             @shBrushBash.js',
        	'coldfusion cf          @shBrushColdFusion.js',
        	'cpp c                  @shBrushCpp.js',
        	'c# c-sharp csharp      @shBrushCSharp.js',
        	'css                    @shBrushCss.js',
        	'delphi pascal          @shBrushDelphi.js',
        	'diff patch pas         @shBrushDiff.js',
        	'erl erlang             @shBrushErlang.js',
        	'groovy                 @shBrushGroovy.js',
        	'java                   @shBrushJava.js',
        	'jfx javafx             @shBrushJavaFX.js',
        	'js jscript javascript  @shBrushJScript.js',
        	'perl pl                @shBrushPerl.js',
        	'php                    @shBrushPhp.js',
        	'text plain             @shBrushPlain.js',
        	'py python              @shBrushPython.js',
        	'ruby rails ror rb      @shBrushRuby.js',
        	'sass scss              @shBrushSass.js',
        	'scala                  @shBrushScala.js',
        	'sql                    @shBrushSql.js',
        	'vb vbnet               @shBrushVb.js',
        	'xml xhtml xslt html    @shBrushXml.js')
		);
		SyntaxHighlighter.all();
	}
})(jQuery);