__hn_hilights_words = [];
__hn_used_objects   = [];
__hn_words = 
[
['жизнь', 1],
['любовь', 2],
['семья', 3],
['красота', 4],
['прогресс', 5],
['мир', 6],
['первый', 7],
['настоящий', 8],
['я', 9],
['мы', 10],
['модный', 11],
['будущее', 12],
['невероятно', 13],
['восторг', 14],
['глобальный', 15],
['впечатление', 16],
['лидер', 17],
['герой', 18],
['желание', 19],
['убедительный', 20],
['информация', 21],
['новый', 22],
['реальность', 23],
['интерес', 24],
['спорт', 25],
['удивление', 26], 
['кино', 27],
['телевидение', 28],
['решение', 29],
['творчество', 30],
['дом', 31],
['видео', 32],
['фото', 33],
['фотография', 34],
['фильм', 35],
['телевизор', 36],
['плазма', 37],
['технологии', 38],
['камера', 39],
['видеокамера', 40],
['фотокамера', 41],
['фотоаппарат', 42],
['blu-ray', 43],
['игра', 44],
['спецэффекты', 45],
['канал', 46],
['формат', 47]
];

__hn_links = [
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2914?&login=pixelaudit_life',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2915?&login=pixelaudit_love',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2916?&login=pixelaudit_family',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2917?&login=pixelaudit_beauty',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2918?&login=pixelaudit_progress',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2919?&login=pixelaudit_world',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2920?&login=pixelaudit_first',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2921?&login=pixelaudit_real',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2922?&login=pixelaudit_I',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2923?&login=pixelaudit_we',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2924?&login=pixelaudit_trendy',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2925?&login=pixelaudit_future',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2926?&login=pixelaudit_unreal',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2843?&login=pixelaudit_rapture',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2927?&login=pixelaudit_global',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2928?&login=pixelaudit_impression',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2929?&login=pixelaudit_leader',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2930?&login=pixelaudit_hero',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2931?&login=pixelaudit_desire',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2932?&login=pixelaudit_cogent',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2933?&login=pixelaudit_information',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2934?&login=pixelaudit_new',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2921?&login=pixelaudit_real',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2935?&login=pixelaudit_interest',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2946?&login=pixelaudit_sport',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2936?&login=pixelaudit_wonder',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2937?&login=pixelaudit_movie',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2938?&login=pixelaudit_TV',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2939?&login=pixelaudit_solution',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2940?&login=pixelaudit_creation',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2941?&login=pixelaudit_home',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2942?&login=pixelaudit_video',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2943?&login=pixelaudit_photo',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2944?&login=pixelaudit_photografia',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2945?&login=pixelaudit_film',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2947?&login=pixelaudit_box',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2948?&login=pixelaudit_plasma',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2949?&login=pixelaudit_technology',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2950?&login=pixelaudit_camera',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2951?&login=pixelaudit_videocamera',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2952?&login=pixelaudit_photocamera',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2953?&login=pixelaudit_photoapparat',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2954?&login=pixelaudit_blu-ray',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2955?&login=pixelaudit_game',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2956?&login=pixelaudit_special',
                                        'http://reklama.mb.vesti.ru/cgi-bin/href/2957?&login=pixelaudit_chanel',
                                        ' http://reklama.mb.vesti.ru/cgi-bin/href/2958?&login=pixelaudit_form ',
];

function __hn_make_hrefs() {
        __hn_forbidden_tags = [ 'A', 'H1', 'TEXTAREA', 'SCRIPT', 'OPTION', 'IFRAME', 'OBJECT' ];
        if ('undefined' != typeof(__hn_stop_tags)) {
                __hn_forbidden_tags = __hn_forbidden_tags.concat(__hn_stop_tags);
        }

        if ('undefined' == typeof(__hn_max_hl_single)) {
                __hn_max_hl_single = 2;
        }

        if ('undefined' == typeof(__hn_max_hl_total)) {
                __hn_max_hl_total = 15;
        }

        if ('undefined' == typeof(__hn_target_blank)) {
                __hn_target_blank = 1;
        }

        if ('undefined' == typeof(__hn_href_class)) {
                __hn_href_class = '';
        }

        div = document.getElementById('hypercontext');
        var found_words = __hn_walk(div);

        var density = __hn_max_hl_total / found_words.length;

        var hl_words = [];
        var counter = 1 - density;
        for (var i = 0; i < found_words.length; ++i) {
                if (Math.floor(counter + density) - Math.floor(counter) >= 1) {
                        hl_words.push(found_words[i]);
                }
                counter += density;
        }
        for (var i = 0; i < hl_words.length; ++i) {
                var newnode = document.createElement('tmp');

                var current_block = hl_words[i][3];
                var offset = 0;
                while (hl_words[i] && current_block == hl_words[i][3]) {
                        var beforeText = current_block.nodeValue.substring(offset, hl_words[i][1]);

                        var link = document.createElement("A");
//                      link.href = 'http://reklama.mb.vesti.ru/cgi-bin/href/2863?&login=pixelaudit';
                        link.href = __hn_links[hl_words[i][2]-1];
//                      link.innerHTML = '123';
                        if (__hn_target_blank) {
                                link.target = '_blank';
                        }
                        if (__hn_href_class.length) {
                                link.className = __hn_href_class;
                        }
                        link.style.color = 'red';
                        link.style.fontWeight = 'bold';
                        link.appendChild(document.createTextNode(hl_words[i][0]));
                        var sup = document.createElement("SUP");
                        sup.appendChild(document.createTextNode('3D'));
                        link.appendChild(sup);

                        newnode.appendChild(document.createTextNode(beforeText));
                        newnode.appendChild(link);

                        offset = hl_words[i][1] + hl_words[i][0].length;

                        ++i;
                }
                --i;

                var afterText = current_block.nodeValue.substring(offset, current_block.nodeValue.length);
                newnode.appendChild(document.createTextNode(afterText));

                if (found_words.length) {
                        current_block.parentNode.replaceChild(newnode, current_block);
                }
        }
}

function __hn_walk(obj)
{
        found_words = [];
        for (var i = 0; i < obj.childNodes.length; i++) {
                if (__hn_in_array(obj.childNodes[i].tagName, __hn_forbidden_tags)) {
                        continue;
                }

                if (3 == obj.childNodes[i].nodeType) {
                        if (__hn_in_array(obj.childNodes[i], __hn_used_objects)) {
                                continue;
                        }
                        __hn_used_objects.push(obj.childNodes[i]);
                        found_words = found_words.concat(__hn_replace(obj.childNodes[i]));
                        continue;
                }

                found_words = found_words.concat(__hn_walk(obj.childNodes[i]));
        }

        return found_words;
}

function __hn_cmp(a, b)
{
        if (a[1] > b[1]) {
                return 1;
        } else if (a[1] < b[1]) {
                return -1;
        }

        if (a[0].length > b[0].length) {
                return -1;
        }

        return 1;
}


function __hn_replace(obj)
{
        var found_words = [];
        for (var i = 0; i < __hn_words.length; ++i) {
                var search_word = __hn_words[i][0];
                var offset = 0;
                var found  = -1;
                while ((found = obj.nodeValue.indexOf(search_word, offset)) > -1) {
                        offset = found + search_word.length;

                        if (__hn_hilights_words[__hn_words[i][1]] >= __hn_max_hl_single) {
                                break;
                        }

                        if (found > 0 && __hn_isAlpha(obj.nodeValue.substr(found - 1, 1))) {
                                continue;
                        }

                        if ((found + search_word.length < obj.nodeValue.length) && __hn_isAlpha(obj.nodeValue.substr(found + search_word.length, 1))) {
                                continue;
                        }

                        found_words.push([search_word, found, __hn_words[i][1], obj]);

                        if (undefined == __hn_hilights_words[__hn_words[i][1]]) {
                                __hn_hilights_words[__hn_words[i][1]] = 1;
                        } else {
                                ++__hn_hilights_words[__hn_words[i][1]];
                        }
                }
        }

        found_words = found_words.sort(__hn_cmp);
        var prev_word = ['', -1];
        var result = [];
        for (var i = 0; i < found_words.length; ++i) {
                if (prev_word[1] + prev_word[0].length > found_words[i][1]) {
                        continue;
                }
                prev_word = found_words[i];
                result.push(found_words[i]);
        }

        return result;
}

function __hn_in_array(needle, haystack)
{
        for (var i = 0; i < haystack.length; ++i) {
                if (haystack[i] == needle) {
                        return 1;
                }
        }

        return 0;
}

function __hn_isAlpha(c) {
        var letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя';
        var q = letters.indexOf(c);
        if (q == -1) {
                return 0;
        } else {
                return 1;
        }
} 


if (document.getElementById('hypercontext')) {

  __hn_make_hrefs();

}


