/* 
 * by HC
 */

HTMLElement.prototype.getElementsByClassName = function(className) {
    var arr = [];
    var els = this.getElementsByTagName("*");
    var exp = new RegExp("^(.* )?"+className+"( .*)?$", "g");
    for (var i = 0; i < els.length; i++ ){
        if (exp.test(els[i].className)){
            arr.push(els[i]);
        }
    }
    return arr;
}
if((new RegExp('.*?(site=wallpapers).*')).test(window.location)){ 
    var Filter = {
        thumbs: null,
        init  : function(){
            if(!this.thumbs)
                this.thumbs = document.getElementById('walls_index').getElementsByClassName('walls_char_name'); 
        },
        exec: function(regex){
            this.init();//przenieść do onDomReady
            var exp = new RegExp("^(.*?)("+regex+")(.*?)(\\([0-9]+\\))$", "gi");
            for (i = 0; i < this.thumbs.length; i++) {
                var thumb = this.thumbs[i];
                var match = [];
                var parent = thumb.parentNode;
                parent = (parent.className=='ithumb') ? parent : parent.parentNode;
                if(regex == '') {
                    thumb.innerHTML = thumb.oldHTML;
                    parent.style.display = 'block';
                    continue;
                }
                thumb.oldHTML = thumb.innerHTML;
                if ((match = exp.exec(thumb.innerText))!=null){
                    thumb.innerHTML = 
                    match[1] + 
                    '<span class="flashFound">' + match[2] + '</span>' + 
                    match[3] +
                    '<span style="float:right;">'+match[4] + '</span>';
                    parent.style.display = 'block';
                } else {
                    thumb.innerHTML = thumb.oldHTML;
                    parent.style.display = 'none';
                }
            }    
        }
    }
}
