$.fn.ssHighlight = function() {
	return this.each(function(){
		var input = this.innerHTML;
		var scope = 0;
		var scopeReg = /(\\(u|h|_s))/g;
		var tagReg = /\\(w\d|s\d|s\[.+?\]|_q|[tce]|n(\[half\])?|URL(\[([^\]]|\\\])*?\])+)/g;
		var textReg = /([^\\]|\\\\|\\\%)+/g;
		var index = 0;
		var inSync = false;
		var result = '';

		while (true) {
			tagReg.lastIndex = index;
			tmp = tagReg.exec(input);
			if (tmp && tmp.index == index) {
				var tag = tmp[0];
				if (tag.indexOf('\\URL') >= 0) {
					tag = tag.replace(/https?:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%\#\!]+/g,
						'<a href="$&">$&</a>');
					result += '<span class="sstag urltag">' + tag + "</span>";
				} else {
					result += '<span class="sstag">' + tag + "</span>";
				}
				index += tmp[0].length;
				continue;
			}
			scopeReg.lastIndex = index;
			tmp = scopeReg.exec(input);
			if (tmp && tmp.index == index) {
				if (tmp[0] == '\\h') scope = 0;
				if (tmp[0] == '\\u') scope = 1;
				if (tmp[0] == '\\_s') inSync = !inSync;
				result += '<span class="sstag">' + tmp[0] + "</span>";
				index += tmp[0].length;
				continue;
			}
			textReg.lastIndex = index;
			tmp = textReg.exec(input);
			if (tmp && tmp.index == index) {
				var cls = inSync ? 'sync' : (scope > 0 ? 'scope1' : 'scope0');
				result += "<span class='" + cls + "'>" + tmp[0] + "</span>";
				index += tmp[0].length;
				continue;
			} else {
				result += input.substr(index);
				break;
			}
		}
		this.innerHTML = result;
	});
};
