
String.prototype.removeFr = function(){
	return this.replace(/[éèêë]/ig,"e").replace(/[àâä]/ig,"a").replace(/[ç]/ig,"c").replace(/[üû]/ig,"u");
}

String.prototype.regex = function(){
	return this.replace(/ /g,"|").replace(/e/ig,"(e|é|è|ê|ë)").replace(/a/ig,"(a|à|â|ä)").replace(/c/ig,"(c|ç)").replace(/u/ig,"(u|ü|û)");
}
String.prototype.containsOneOf = function(arr){
	for (x in arr){
	    val = arr[x].toLowerCase();
	    if(this.indexOf(val) == -1)
	    	return false
	}
	return true;
}
var progval = null;
var width = 0;
$(function(){
    $('.searchfield').keyup(function(e){
        if(e.keyCode == 27) $(this).val('');
		//removehighlight2($('ul.pk_news_list').get(0));
        var val = $(this).val().toLowerCase();
        if (val.length < 3) {
			$('ul.pk_news_list li').show();
			return this;
		}
		//wordhighlight($('ul.pk_news_list').get(0),val.regex())
		var words = val.removeFr().split(" ")
		//$('#searchprog').css('width',0).fadeIn();
		//var max = $('ul.pk_news_list li').length;
		//progval = setInterval(progress,10);
		$.each($('ul.pk_news_list li'),function(idx,elem){
			var text = $(this).text().toLowerCase().removeFr();
			if(text.containsOneOf(words))	$(this).show();
			else							$(this).hide();
			//width = 209/(idx/max);
		})
		/*$('#searchprog').fadeOut();
		removeInterval(progress,10);
		progval = null;*/
    });
})

function progress(){
	$('#searchprog').css('width',width);
}



