
$.fn.relFilter=function(){me=this;this.filter=function(){tag=$('#EventFilter').val().toString();promo_bookie='bookmaker-'+$('#Promotions SELECT').val();free_bet_bookie='bookmaker-'+$('#FreeBets SELECT').val();$('.filtered').each(function(){if(tag.length&&($.inArray(tag,this.tagged)==-1)){$(this).hide();return;};bookie=$(this).find('.bookie IMG');if(bookie.hasClass('promo')&&promo_bookie!='bookmaker-0'&&bookie.attr('rel')!=promo_bookie){$(this).hide();return;};if(bookie.hasClass('free-bet')&&free_bet_bookie!='bookmaker-0'&&bookie.attr('rel')!=free_bet_bookie){$(this).hide();return;};$(this).show();});};return this.each(function(){var tag_list=[];$(this).find('TABLE > TBODY > TR:not(.error)').addClass('filtered').each(function(){this.tagged=$(this).attr('rel').split(/,/);tag_list=$.merge(this.tagged,tag_list);});tag_list=tag_list.unique();$.each(tag_list,function(i,v){if(!v)return;$('<option>').attr('value',v).text(v).appendTo('#EventFilter');});$('#EventFilter').change(function(){me.filter();});bookies=[];$('IMG.promo').each(function(){bid=$(this).attr('rel').replace(/bookmaker-/,'');bn=$(this).attr('alt');bookies[bid]=bn;});$.each(bookies,function(i,v){if(!v)return;$('<option>').attr('value',i).text(v).appendTo('#Promotions SELECT');});bookies=[];$('IMG.free-bet').each(function(){bid=$(this).attr('rel').replace(/bookmaker-/,'');bn=$(this).attr('alt');bookies[bid]=bn;});$.each(bookies,function(i,v){if(!v)return;$('<option>').attr('value',i).text(v).appendTo('#FreeBets SELECT');});$('#Offers SELECT').change(function(){me.filter();});});};