/**
 * @author arek
 */
  jQuery.extend(
    jQuery.expr[':'], { Contains : "jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0" 
  });
  
$(function(){

	$.fn.findText={
		
		searchDefaultText:"Search on this page",
	    startSearchingLength:3,
	    textWrapper:"#body",
	    searchBoxWrapper:"#searchOnThisPage",
	    searchBoxId:"searchOnThisPageTextBox",
	    activeCssClass:"active",
	    highlightCssClass:"highlight",
	    first:true,
	    // --- prive variables
	    originalText:"",
	    
	    // --- public methods
	    getOriginalText:function() {
	      return originalText;
	    },
	    
	    init:function(target) {
	      var instance = this;
	      $.fn.findText.first=true;
	      //originalText = $(this.textWrapper).html();
	        //$(instance.textWrapper).html(instance.getOriginalText());
	          var regx = new RegExp("(" + target + ")", 'gi');
	          var selector = 'p:Contains("' + target + '")';
	          $("#content").children().each(function() {
	          //  if (this.tagName!='img' && this['href']==undefined) {
					//var text = $(this).html();
					//text = text.replace(regx, '<span class="' + $.fn.findText.highlightCssClass + '">$1</span>');
					//$(this).html(text);
					
					$.fn.findText.highligt(this, regx);
				//}
	          });
	    },
		highligt:function(object, regx){
			if($(object).children().length>0){
				$(object).children().each(function(){
					$.fn.findText.highligt(this, regx);	
				})
			}else{
				var tagname = object.tagName;
				if(tagname=="P" || tagname=="TD" || tagname=="LI" || tagname=="H1" || tagname=="H2" || tagname=="H3" || tagname=="H4"){
					   text = $(object).html();
					   
					  // if ($.fn.findText.first) {
						   	text = text.replace(regx, '<span  class="' + $.fn.findText.highlightCssClass + '">$1</span>');
						   //	$.fn.findText.first=false;
					  // }else{
					   //		text = text.replace(regx, '<span class="' + $.fn.findText.highlightCssClass + '">$1</span>');
					  // }
					   
						$(object).html(text);
				}
			}
		}
		
	}
});

