$.expr[':'].containsIgnoreCase = function(a,i,m){
return $(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0;
};

$.fn.search = function(searchElements) {
  $(this).keyup(function(){
    var searchString = $(this).val();
    if (searchString.length > 0){
      $(searchElements).hide();
	  $(searchElements).filter(':containsIgnoreCase(' +searchString+ ')').show();
	  $("table").each( function(e){
		var visLin = $(this).find(searchElements+":visible").length;
		if (visLin<1){
			$(this).hide();
		} else $(this).show();
	  });
    } else {
		$("table").show();
		$(searchElements).show();
    }
  });

};
$(document).ready( function() {
	
	var defValue="Search RRFB.org";
	var mTo=0;
	var hDir=500;
	var mWdh=190;
	
	$("#s").live("focus", function(){
		if ( $(this).val() == defValue) $(this).val("");
	}).live("blur", function(){
		if ( $(this).val() == "") $(this).val(defValue);
	}).val(defValue);
	
	function hideMenu(){
		$("#undermenu").fadeOut( 100 );
	}
	
	$("#menu a").live("mouseenter", function(){
		if ( mTo>0) { clearTimeout( mTo); mTo=0; }
		var tOff = $(this).offset();
		var w = $(this).width();
		var rel = $(this).attr("rel");
		if (w < mWdh) w=mWdh;
		$("#undermenu").css( { "left": tOff.left + "px", "top": (36+tOff.top) + "px" } );
		$("#undermenu ul").width( w ).html( $("#menujazz .page-item-" + rel).children(".children").html() );
		$("#undermenu").show();
		setTimeout( function(){ $("#undermenu").show(); }, 10);
	}).live("mouseleave", function(){
		mTo = setTimeout( function(){ hideMenu(); }, hDir);
	}).live("click", function(){
		if ( mTo>0) { clearTimeout( mTo); mTo=0; }
	});
	$("#undermenu").live("mouseenter", function(){
		if ( mTo>0) { clearTimeout( mTo); mTo=0; }
	}).live("mouseleave", function(){
		mTo = setTimeout( function(){ hideMenu(); }, hDir);
	});
	$("a#top_submit").click(function(){
		$("#searchform").submit();
		return false;
	});
	
	
	$("#search_query").search("div.sqh");
});
