var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function chkAgent() {
    if (navigator.userAgent.indexOf('Konqueror') != -1) return false;
    if (navigator.userAgent.match(/Opera [1-7]/)) return false;
    return true;
}

String.prototype.begunSplit = function(limit) {
    var suff = '...';
    limit = this.lastIndexOf(' ', limit);
    if (limit == -1) {
        limit = this.length;
        var suff = '';
    }
    return this.substr(0, limit) + suff;
}

function bJsTs() {
    this.tpl = null;
    this.block = function(block) {
        this.tpl = this.tpl.replace('{{' + block + '}}', '');
        this.tpl = this.tpl.replace('{{/' + block + '}}', '');
    }
    this.parse = function(vars) {
        for (var key in vars) {
            while (this.tpl.match('{' + key + '}'))
                this.tpl = this.tpl.replace('{' + key + '}', vars[key], 'gm');
        }
        var tplA = this.tpl.split(/\{\{[a-z]+\}\}/);
        var tplS = '';
        for (var i = 1; i < tplA.length; i++) {
            var tplA2 = tplA[i].split(/\{\{\/[a-z]+\}\}/);
            tplS = tplS + tplA2[1];
        }
        this.tpl = tplA[0] + tplS;
        return this.tpl;
    }
}

function bJsT() {
    this.tpl = null;
    this.block = function(block) {
        var re = new RegExp('{({/?' + block + '})}', 'gm');
        this.tpl = this.tpl.replace(re, '');
    }
    this.parse = function(vars) {
        for (var key in vars) {
            var re = new RegExp('{' + key + '}', 'g');
            this.tpl = this.tpl.replace(re, vars[key]);
        }

        var re = new RegExp('{({([a-z]+)})}.+?{({/\\2})}', 'gm');
        this.tpl = this.tpl.replace(re, '');
        return this.tpl;
    }
}

function adstek_include(file) {
    document.write('<scr'+'ipt  charset="windows-1251" type="text/javascript" src="' + file + '"></scr'+'ipt>');
}

function begunAppend(params) {
    for (var key in params)
        if (params[key] && params.hasOwnProperty && params.hasOwnProperty(key)) // always check for own property in for .. in ..
            begun_auto_url += '&' + key + '=' + escape(params[key]);
}

//http://www.featureblend.com/license.txt
FlashDetect=new function(){var self=this;self.installed=false;self.raw="";self.major=-1;self.minor=-1;self.revision=-1;self.revisionStr="";var activeXDetectRules=[{"name":"ShockwaveFlash.ShockwaveFlash.7","version":function(obj){return getActiveXVersion(obj);}},{"name":"ShockwaveFlash.ShockwaveFlash.6","version":function(obj){var version="6,0,21";try{obj.AllowScriptAccess="always";version=getActiveXVersion(obj);}catch(err){}
return version;}},{"name":"ShockwaveFlash.ShockwaveFlash","version":function(obj){return getActiveXVersion(obj);}}];var getActiveXVersion=function(activeXObj){var version=-1;try{version=activeXObj.GetVariable("$version");}catch(err){}
return version;};var getActiveXObject=function(name){var obj=-1;try{obj=new ActiveXObject(name);}catch(err){}
return obj;};var parseActiveXVersion=function(str){var versionArray=str.split(",");return{"raw":str,"major":parseInt(versionArray[0].split(" ")[1],10),"minor":parseInt(versionArray[1],10),"revision":parseInt(versionArray[2],10),"revisionStr":versionArray[2]};};var parseStandardVersion=function(str){var descParts=str.split(/ +/);var majorMinor=descParts[2].split(/\./);var revisionStr=descParts[3];return{"raw":str,"major":parseInt(majorMinor[0],10),"minor":parseInt(majorMinor[1],10),"revisionStr":revisionStr,"revision":parseRevisionStrToInt(revisionStr)};};var parseRevisionStrToInt=function(str){return parseInt(str.replace(/[a-zA-Z]/g,""),10)||self.revision;};self.majorAtLeast=function(version){return self.major>=version;};self.FlashDetect=function(){if(navigator.plugins&&navigator.plugins.length>0){var type='application/x-shockwave-flash';var mimeTypes=navigator.mimeTypes;if(mimeTypes&&mimeTypes[type]&&mimeTypes[type].enabledPlugin&&mimeTypes[type].enabledPlugin.description){var version=mimeTypes[type].enabledPlugin.description;var versionObj=parseStandardVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revisionStr=versionObj.revisionStr;self.revision=versionObj.revision;self.installed=true;}}else if(navigator.appVersion.indexOf("Mac")==-1&&window.execScript){var version=-1;for(var i=0;i<activeXDetectRules.length&&version==-1;i++){var obj=getActiveXObject(activeXDetectRules[i].name);if(typeof obj=="object"){self.installed=true;version=activeXDetectRules[i].version(obj);if(version!=-1){var versionObj=parseActiveXVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revision=versionObj.revision;self.revisionStr=versionObj.revisionStr;}}}}}();};FlashDetect.release="1.0.3";

function getCss() {
    if (begunParams.wide) {
        var css_bgulli_width = parseInt(100 / begun_auto_limit) - 1;
        var css_bgulli_float = 'float:left !important;';
    } else {
        var css_bgulli_width = 100;
        var css_bgulli_float = '';
    }
    if (begunParams.thumbs)
        var css_bgbanner_marginleft = 65;
    else
        var css_bgbanner_marginleft = 0;

    var css_bgulli_margin_bottom = 3;
    if (begunParams.thumbs && !begunParams.wide && !begunParams.autoscroll)
        var css_bgulli_height = 'min-height: 48px;';
    else
        var css_bgulli_height = '';

    if (begunParams.autoscroll) {
        var css_bgulli_height = 'height: ' + begun_scroll_height + 'px !important;';
        var css_bgulli_margin_bottom = 0;
    }
    begun_autowidth_string = new String(begun_auto_width);
    begun_autowidth_string =  begun_autowidth_string.indexOf('%')==-1 ? 'px':'';
    var fixedParam = {'fonttype' : 'font-face', 'bgbanner' : '', 'lipadding' : '0px 0px '+css_bgulli_margin_bottom + 'px 0px'};
    if(begunChkParam('style', 'fixed')) {
        fixedParam.fonttype = 'font-family';
        fixedParam.bgbanner = 'margin-bottom:10px;';
        fixedParam.lipadding = css_bgulli_margin_bottom + 'px 0px 0px 0px'
    }
    var cssTpl = '\
        <style><!-- \
        .begun { ' +fixedParam.fonttype+ ':Arial,sans-serif !important; } \
        .bgul'+rndID+' div, .bgulli'+rndID+' div  {float:none !important;clear:none !important;display:block !important;} \
        a.begun:link { color:'+begun_auto_colors[0]+'; '+fixedParam.fonttype+':Arial,sans-serif !important; line-height: 100% !important; } \
        a.begun:visited { color:'+begun_auto_colors[0]+';'+fixedParam.fonttype+':Arial,sans-serif !important; line-height: 100% !important; } \
        a.begun:hover { color:'+begun_auto_colors[0]+';'+fixedParam.fonttype+':Arial,sans-serif !important; line-height: 100% !important; } \
        a.begun:active { color:'+begun_auto_colors[0]+';'+fixedParam.fonttype+':Arial,sans-serif !important; line-height: 100% !important; } \
        .bgul'+rndID+' { float: none !important; margin:5px 5px 0px 5px !important; padding:0px !important; width: '+begun_auto_width+ begun_autowidth_string+' !important; background-color: '+begun_auto_colors[3]+' !important; overflow: hidden; } \
        .bgul1 { margin:5px 5px 0px 5px !important; padding:0px !important;  background-color: '+begun_auto_colors[3]+' !important; } \
        .bgulli'+rndID+' { '+css_bgulli_float+' list-style:none !important; margin:'+fixedParam.lipadding+' !important; padding:0px 5px 0px 0px !important; width: '+css_bgulli_width+'% !important; '+css_bgulli_height+' font-weight:normal;background:none; overflow: hidden !important; } \
        .bgulli'+rndID+'l { '+css_bgulli_float+' list-style:none !important; margin:3px 0px '+css_bgulli_margin_bottom+'px 0px !important; padding:0px 5px 0px 0px !important; width: '+css_bgulli_width+'% !important; '+css_bgulli_height+' font-weight:normal;background:none; overflow: hidden !important; } \
        .bgthumb { margin:5px !important; border: 1px solid '+begun_auto_colors[2]+' !important; } \
        .bgbanner { margin-left:'+css_bgbanner_marginleft+'px !important; text-align: left !important; text-indent: 0px !important; '+fixedParam.bgbanner+'} \
        .ramblersbox, .ramblersbox1 {padding:0px; margin: 0px; }\
        .ramblersbox1 td, .ramblersbox td {padding:0px; margin: 0px; color:#000000; }\
        .ramblersbox1 table, .ramblersbox table {background-color:#009CDE; padding:0px; margin: 0px; }\
        .ramblersbox1 table{background-color:#ffffff; }\
        .ramblersbox1 td{background-color:#ffffff; }\
        .ramblersbox td{background-color:#009CDE; }\
        .ramblersbox1 input, .ramblersbox input {height: 20px;} \
        //--></style>';
    return cssTpl;
}

function begunChkParam(paramName, checkVal) {
    if(!begunParams || !begunParams[paramName]) {
        return false;
    }
    if(checkVal != begunParams[paramName]) {
        return false;
    }
    return true;
}

function getStub(sWidth) {
    var rambler_search_text1 = decodeURIComponent('%D0%A0%D0%B0%D0%BC%D0%B1%D0%BB%D0%B5%D1%80%2C');
    var rambler_search_text = decodeURIComponent('%D0%9D%D0%B0%D0%B9%D1%82%D0%B8!');
    var sWidth = sWidth || begun_auto_width;
    
    var stubFixedTpl = '\
        <div class="begun" style="padding-bottom:3px;background-color: {begun_auto_colors3}; zoom:1; margin: 0px 5px 5px 5px;font-size:{begun_auto_fonts_size3};color:{begun_auto_colors2};width:{begun_auto_width}{begun_autowidth_string};text-align:left" > \
        <div style="' + (begunParams.wide ? 'float: left; width: 33%;text-align:left;' : 'padding-top:3px;') + '"> \
        {{showhref}} \
        <a class="snap_noshots" href="{href0}" style="line-height:100% !important;color:{begun_auto_colors2};" target="_blank">{text0}</a> \
        {{/showhref}} \
        ' + (!begunParams.showhref && begunParams.wide ? '&nbsp;' : '') +  '</div> \
        <div style="' + (begunParams.wide ? 'text-align:center;float: left; width: 33%;' : 'padding-top:3px;') + '"><a class="snap_noshots" href="http://www.begun.ru/advertiser/?r1=Begun&r2=adbegun" style="line-height:100% !important;color:{begun_auto_colors2};" target="_blank">{text1}</a></div> \
        <div style="' + (begunParams.wide ? 'text-align:right;float: left; width: 33%;' : 'padding-top:3px;') + '"><a class="snap_noshots" href="http://www.begun.ru/partner/?r1=Begun&r2=become_partner" style="line-height: 100% !important;color:{begun_auto_colors2};" target="_blank">{text2}</a></div> \
        <div style="clear: both; height:0; font-size:0">&nbsp;</div> \
        </div> ';
    var stubNormlTpl = '<table width="{begun_auto_width}" style="background-color: {begun_auto_colors3}; margin: 0px 5px 5px 5px;"><tr><td width="33%" style="cursor:default;"> \
        {{showhref}} \
            <a class="snap_noshots" href="{href0}" style="color:{begun_auto_colors2};line-height:100% !important;" target="_blank"><font style="font-size:{begun_auto_fonts_size3};" color="{begun_auto_colors2}">{text0}</font></a> \
        {{/showhref}} \
        </td> \
        <td align="center" width="33%" style="cursor:default;"><a class="snap_noshots" href="http://www.begun.ru/advertiser/?r1=Begun&r2=adbegun" style="color:{begun_auto_colors2};line-height:100% !important;" target="_blank"><font style="font-size:{begun_auto_fonts_size3};" color="{begun_auto_colors2}">{text1}</font></a></td> \
        <td align="right"  width="33%" style="cursor:default;"><a class="snap_noshots" href="http://www.begun.ru/partner/?r1=Begun&r2=become_partner" style="color:{begun_auto_colors2};line-height: 100% !important;" target="_blank"><font style="font-size:{begun_auto_fonts_size3};" color="{begun_auto_colors2}">{text2}</font></a> \
        </td></tr></table>';
    var stubRaTpl = '{{showformv}}\
        <form name="ramlerSbegun" class="{begun_rambler_style}" target="_blank" action="http://www.rambler.ru/srch" method="get">\
        <input type="hidden" name="set" value="www" /><input type="hidden" name="sbox" value="{sbox}" />\
        <table width="{begun_auto_width}" cellpadding="0" cellspacing="0" border="0">\
        <tr><td style="padding:2px;padding-left:15px;text-align:left;"><img width="117" height="24" src="http://autocontext.begun.ru/{begun_rambler_img}" alt="Rambler" /></td></tr>\
        <tr><td style="padding-left:11px;">\
        <table width="100%"><tr>\
        <td><input type="text" name="words" value="" style="width:100%;height:18px;" /></td>\
        <td width="75"><input type="submit" name="beguns" style="margin-left:10px;width: 70px; height:24px;" value="'+rambler_search_text+'" /></td>\
        </tr></table>\
        </td></tr></table>\
        </form>\
       {{/showformv}}\
       {{showformh}}\
        <form name="ramlerSbegun" class="{begun_rambler_style}" target="_blank" action="http://www.rambler.ru/srch" method="get">\
        <input type="hidden" name="set" value="www" /><input type="hidden" name="sbox" value="{sbox}" />\
        <table width="{begun_auto_width}" cellpadding="0" cellspacing="0" border="0">\
        <tr><td style="padding:2px;padding-left:15px;text-align:left;" width="125"><img width="117" height="24" src="http://autocontext.begun.ru/{begun_rambler_img}" alt="Rambler" /></td>\
        <td><table width="100%"><tr>\
        <td style="margin:0px;padding:0px;"><input type="text" name="words" value="" style="width:100%;height:18px;" /></td>\
        <td style="margin:0px;padding:0px;" width="75"><input type="submit" name="beguns" style="margin-left:10px;width: 70px; height:24px;" value="'+rambler_search_text+'" /></td>\
        </tr></table>\
        </td></tr></table></form>\
        {{/showformh}}\
    ';
    if(begunChkParam('style', 'fixed')) {
        var stubTpl = stubFixedTpl + stubRaTpl; 
    } else {
        var stubTpl = stubNormlTpl + stubRaTpl; 
    }
    if (isComp)
        var template = new bJsT();
    else
        var template = new bJsTs();
    template.tpl = stubTpl;
    if (begunParams.showhref)
        template.block('showhref');
    begun_rambler_style = 'ramblersbox1';
    begun_rambler_img = 'rambler_2.gif';
    if(window.begun_rambler_type && window.begun_rambler_type == 1) {
        begun_rambler_style='ramblersbox';
        begun_rambler_img='rambler_1.gif';
    }
    if(begunStubs[5] && begunStubs[5].text && sWidth>=250) {
        if(sWidth>=350)
            template.block('showformh');
        else
            template.block('showformv');
    }

    var vars = {
        'begun_auto_colors2': begun_auto_colors[2], 'begun_auto_colors3': begun_auto_colors[3],
        'begun_auto_fonts_size3': begun_auto_fonts_size[3],
        'href0': begunStubs[0].href, 'text0': begunStubs[0].text,
        'text1': begunStubs[1].text, 'text2': begunStubs[2].text,
        'begun_auto_width': sWidth,
        'sbox': begunStubs[5].text,
        'begun_rambler_style' : begun_rambler_style,
        'begun_rambler_img' : begun_rambler_img,
		'begun_autowidth_string' : begun_autowidth_string
    }
    if (begunParams.autoscroll)
        vars.begun_auto_width = sWidth + 3;
    else
        vars.begun_auto_width = sWidth;
    return template.parse(vars);
}

function begun_logic_item(item)
{
    if (typeof(item[7])=="undefined"){item[7]='Card, Url';}
    if (item[7]!='Card, Url' && item[7]!='Card' && item[7]!='Url'){item[7]='Card, Url';}

    if (typeof(item[2])=="undefined"){item[2]='';}
    if (typeof(item[6])=="undefined"){item[6]='';}

    if (item[2]=='' && item[6]==''){return item;}
    if (item[2]=='' && item[6]!=''){item[7]='Card';}
    if (item[2]!='' && item[6]==''){item[7]='Url';}
    if (item[2]!='' && item[6]!=''){item[7]=item[7];}

    switch (item[7]) {
        case 'Card':    {item[2]=item[6]; break;}
        case 'Card, Url':   {break;}
        case 'Url': {
            break;
        }
    }
    return item;
}

function getBanner(bb, bWidth, isLast) {
    bb = begun_logic_item( bb );
    if (!bWidth)
        var bWidth = begun_auto_width;

    var suff = isLast ? 'l' : '';
    var rambler_textb_call = decodeURI('%D0%97%D0%B2%D0%BE%D0%BD%D0%B8%D1%82%D1%8C');
    var rambler_textb_contacts = decodeURI('%D0%9A%D0%BE%D0%BD%D1%82%D0%B0%D0%BA%D1%82%D1%8B');

    var fixedParam = {'wrap' : 'white-space: nowrap;', 'fixpadding' : false};
    if(begunChkParam('style', 'fixed')) {
        fixedParam['wrap'] = '';
        fixedParam['fixpadding'] = true;
    }
    
    var bannerTpl = '\
    <li class="bgulli{rndID}'+suff+'"> \
        {{thumbs}}<div style="float:left !important"><a class="snap_noshots" href="{bb2}" {begun_target}><img src="{thumbSrc}" class="bgthumb" border="0"></a></div>{{/thumbs}} \
        \
        <div class="bgbanner"> \
            <div style="' + (fixedParam.fixpadding ? 'font-size:{begun_auto_fonts_size0};' : '') + '"><a class="begun snap_noshots" style="color:{begun_auto_colors0};font-size:{begun_auto_fonts_size0};font-weight:{begun_bold};cursor:pointer" {begun_target} href="{bb2}" onmouseover="status=\'http://{domain}/\';return true" onmouseout="status=\'\';return true" title="{domain}">{bb0}</a></div> \
            <div style="' + (fixedParam.fixpadding ? 'font-size:{begun_auto_fonts_size1};' : '') + 'margin-top:3px;"><a class="begun snap_noshots" {begun_target} href="{bb2}" style="font-size:{begun_auto_fonts_size1};color:{begun_auto_colors1};text-decoration:none;" onmouseover="status=\'http://{domain}/\';return true" onmouseout="status=\'\';return true" title="{domain}">{bb1}</a></div> \
            <div style="' + (fixedParam.fixpadding ? 'font-size:{begun_auto_fonts_size2};margin-top:2px;' : 'margin-top:3px;') +' "> \
                {{site}}<a class="begun snap_noshots" {begun_target} href="{bb2}" style="'+fixedParam.wrap+'font-size:{begun_auto_fonts_size2};color:{begun_auto_colors2};text-decoration:none;" onmouseover="status=\'http://{domain}/\';return true" onmouseout="status=\'\';return true" title="{domain}">{bb4}</a>{{/site}} ' +(fixedParam.wrap == '' ? '' : '<span style="white-space: nowrap">' )+ '\
                {{ppcall}}<img src="http://autocontext.begun.ru/phone_icon.gif" style="width:12px;height:8px;border:none;" alt="" />&nbsp;<a href="javascript:void(0);" onClick="showEnterForm({i}, this,event);" class="begun snap_noshots" style="font-size:{begun_auto_fonts_size2};color:{begun_auto_colors2};text-decoration:none;">'+rambler_textb_call+'</a>{{/ppcall}} \
                {{ppcallcard}}<img src="http://autocontext.begun.ru/phone_icon.gif" style="width:12px;height:8px;border:none;" alt="" />&nbsp;<a href="{card_href}" target="_blank" class="begun snap_noshots" style="font-size:{begun_auto_fonts_size2};color:{begun_auto_colors2};text-decoration:none;">'+rambler_textb_contacts+'</a>&nbsp;<span style="color: #aaa;font-size:10px;">&#149;</span>&nbsp;<a href="javascript:void(0);" onClick="showEnterForm({i}, this, event);" class="begun snap_noshots" style="font-size:{begun_auto_fonts_size2};color:{begun_auto_colors2};text-decoration:none;">'+rambler_textb_call+'</a>{{/ppcallcard}}\
				{{card}}<img src="http://autocontext.begun.ru/phone_icon.gif" style="width:12px;height:8px;border:none;" alt="" />&nbsp;<a href="{card_href}" target="_blank" class="begun snap_noshots" style="font-size:{begun_auto_fonts_size2};color:{begun_auto_colors2};text-decoration:none;">'+rambler_textb_contacts+'</a>{{/card}}\
	'+ (fixedParam.wrap == '' ? '' : '</span>' ) +' \
            </div> \
        </div> \
    </li> \
    ';

    if (isComp)
        var template = new bJsT();
    else
        var template = new bJsTs();
    template.tpl = bannerTpl;
    if (bb == null)
        return '';
    if (bb[4] == null) bb[4] = '';
    if (begunParams.thumbs) {
        var thumbSrc = begunParams['thumbs_src'] ? 'http://' + begunParams['thumbs_src'] + '/' : 'http://thumbs01.begun.ru/';
        if (bb[5] != undefined && bb[5].toString().length > 2) {
            var bannerId = bb[ 5 ].toString();
            thumbSrc = thumbSrc + bannerId.charAt( bannerId.length - 2 );
            thumbSrc = thumbSrc + '/' + bannerId.charAt( bannerId.length - 1 );
            thumbSrc = thumbSrc + '/' + bannerId + '.jpg';
        } else {
            thumbSrc = thumbSrc + 'empty.jpg';
        }
        template.block('thumbs');
    }
    if ( typeof( window.ppcallArray ) == 'undefined' || window.ppcallArray == null ){
        window.ppcallArray = [];
    }
    switch(bb[7]){
        case "Card, Url": {
            template.block("site");
            if(ppcallArray[i]==1)
                template.block('ppcallcard');
            else
                template.block("card");
        } break;
        case "Url": {
            template.block("site");
            if(ppcallArray[i]==1) template.block('ppcall');
        } break;
        case "Card":{
            if(ppcallArray[i]==1)
                template.block('ppcallcard');
            else
                template.block("card");
            bb[2] = bb[6];
        } break;
        default: break;
    }
    function getDomain(s){
        return s.replace(/^(.*?) - (.*?)$/i, "$1");
    }
    var vars = {
        'bb0': bb[0], 'bb1': bb[1], 'bb2': bb[2], 'bb3': bb[3], 'bb4': bb[4],
        'begun_auto_colors0': begun_auto_colors[0], 'begun_auto_colors1': begun_auto_colors[1],
        'begun_auto_colors2': begun_auto_colors[2],
        'begun_auto_fonts_size0': begun_auto_fonts_size[0], 'begun_auto_fonts_size1': begun_auto_fonts_size[1],
        'begun_auto_fonts_size2': begun_auto_fonts_size[2],
        'i': i, 'begun_target': begun_target, 'begun_auto_width': bWidth,
        'begun_bold': begun_bold, 'thumbSrc': thumbSrc, 'rndID': rndID,
        'card_href': bb[6], 'domain': getDomain(bb[4])
    }
    return template.parse(vars);
}

function begunFillIfNotExist(oldCollection, newCollection) {
    for(var key in newCollection) {
        oldCollection[key] = oldCollection[key] || newCollection[key];
    }
}

function begunPrint() {
    isComp = chkAgent();
    if (window.begun_block_type == 'Horizontal')
        begunParams.wide = 1;
    if (window.begun_block_type == 'Vertical')
        begunParams.wide = 0;
    if (window.ppcallArray != null) {
		document.write('<scr' + 'ipt src="http://ppcall.begun.ru/auto_ppcall.js" type="text/javascript"></scr' + 'ipt>');
    }
    begun_auto_width = window.begun_auto_width || 350;
    begun_auto_limit = window.begun_auto_limit || 3;
    begun_scroll_height = window.begun_scroll_height || '';
    var begunSpans = window.begun_spans;

    var fixedParam = {'font2' : '#00CC00'};
    if(begunChkParam('style', 'fixed')) {
        fixedParam['font2'] = '#167201';
    }
    if(typeof(begun_auto_colors) == "undefined") begun_auto_colors = [];
    if(typeof(begun_auto_fonts_size) == "undefined") begun_auto_fonts_size = [];
    var defFontColor = ['#0000CC', '#000000', fixedParam.font2, '#FFFFFF'];
    begunFillIfNotExist(begun_auto_colors, defFontColor);
    var defFontSize = ['10pt', '9pt', '9pt', '9pt'];
    begunFillIfNotExist(begun_auto_fonts_size, defFontSize);
    begun_target = 'target="_blank"';
    begun_bold = 'bold';

    rndID = Math.round(Math.random() * 99 + 2); // not "+ 1", or else we might have 2 "bgul1" CSS classes

    if (begunParams.multispan)
        begunParams.wide = 0;

    if (begunParams.wide) {
        if (begun_auto_limit < 3)
            begun_auto_limit = 3;
        else if (begun_auto_limit > 5)
            begun_auto_limit = 5;
        begunBanners = begunBanners.slice(0, begun_auto_limit);
    }
    //for (var i in begunBanners) {
    //    begunBanners[i][0] = begunBanners[i][0].begunSplit(30);
    //    begunBanners[i][1] = begunBanners[i][1].begunSplit(70);
    //};

    document.write(getCss());

    var begunContent = '';
    var begunContentHeader = '';

    if (begunParams.autoscroll) {
        _begun_auto_width = begun_auto_width + 3;
        begunContentHeader = '<div id="begunScroll" style="width: ' + _begun_auto_width + 'px; height: '+(begun_view_limit * begun_scroll_height)+'px; background-color:'+begun_auto_colors[3]+'; overflow:hidden;"> \
        <div id="begunSpacer" style="height: 0px"></div>';
    }
    if (typeof window.begunExtLinks == 'object') {
    	for (var indx = 0; indx < window.begunExtLinks.length; indx++) {
    		if (window.begunExtLinks[indx][0] == 'js') {
    			document.write('<s' + 'cript type="text/javascript" src="' + window.begunExtLinks[indx][1] + '"></s' + 'cript>');
    		} else if (window.begunExtLinks[indx][0] == 'img') { 
    			document.write('<img src="' + window.begunExtLinks[indx][1] + '" width="1" height="1" border="0" />');
    		}
    	}
    }
    if (!begunParams.multispan) {
        begunContentHeader += '<div><ul class="bgul'+rndID+'" id="begunRoot">';
        begunContent += begunContentHeader;
        if (begunBanners != null) {
            for (i = 0; i < begunBanners.length; i++)
                begunContent += getBanner(begunBanners[i], null, i == begunBanners.length  - 1 ? 1 : 0);
        }
        begunContent += '</ul>';
        if (begunParams.wide)
            begunContent += '<div style="clear:left;"></div>';
        if (begunParams.autoscroll)
            begunContent += '</div>'
        if (begunParams.stub)
            begunContent += getStub();
        begunContent += '</div>';
    } else {
        begunContentHeader += '<ul class="bgul1" id="begunRoot">';

        if (begunBanners.length) {
            i = 0;
            for (var j = 0 ; j < begunSpans.length; j++ ) {
                begunContent = '';
                var breakFlag = 0;
                if (!document.getElementById(begunSpans[j].span_id)) continue;
                if (begunSpans[j].width)
                    var spanWidth = begunSpans[j].width;
                else
                    var spanWidth = begun_auto_width;
                begunContent += begunContentHeader.substr(0, begunContentHeader.length - 1) + ' style="width:'+spanWidth+'px;">';
                if (begunBanners != null) {
                    for (k = 0; k < begunSpans[j].limit; k++) {
                        if (typeof begunBanners[i] == 'object') {
                            begunContent += getBanner(begunBanners[i], spanWidth, k == begunBanners.length - 1 ? 1 : 0);
                            i++;
                        } else {
                            breakFlag = 1;
                            break;
                        }
                    }
                    if(begunChkParam('style', 'fixed')) {
                        begunContent += '</ul>';
                    }
                    if (begunParams.stub)
                        begunContent += getStub(spanWidth);
                    if(!begunChkParam('style', 'fixed')) {
                        begunContent += '</ul>';
                    }
                    document.getElementById(begunSpans[j].span_id).innerHTML = begunContent;
                    if (breakFlag) break;
                }
            }
        }
    }

    if (typeof begunSpans == 'object') {}
    else if (document.getElementById('begunSpan'))
        document.getElementById('begunSpan').innerHTML = begunContent;
    else
        document.write(begunContent);
    if (begunParams.autoscroll) {
        document.write('<scr' + 'ipt type="text/javascript">scrollPrint();</scr' + 'ipt>');
    }

    if (begunParams.begun_auto_hyper) {
        adstek_include('http://autocontext.begun.ru/hypertext_a.js');
        document.write('<scr' + 'ipt type="text/javascript">hyperRun();</scr' + 'ipt>');
    }
}

function begunAutoRun() {
    if (!FlashDetect.installed)
	{
		if (!confirm(decodeURIComponent('%D0%A3%20%D0%92%D0%B0%D1%81%20%D0%BD%D0%B5%20%D1%83%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BB%D0%B5%D0%BD%20Adobe%20Flash.%20%D0%96%D0%B5%D0%BB%D0%B0%D0%B5%D1%82%D0%B5%20%D0%B5%D0%B3%D0%BE%20%D1%83%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%B8%D1%82%D1%8C%3F')))
			return;
		location = 'http://get.adobe.com/flashplayer/';
		
	}
	else
	{
		document.write('<div id="adstek_cr_container"></div>');
		setTimeout(adstek_draw_corner,100);
	}
}

function begunIsReadyForNewBlocks(pad_id){
	if (Number(window.begun_scroll) || window.begun_spans) return false; // scroll blocks & spans left alone
	var SELECTED_PAD_IDS = [46943110, 48733196, 62618637, 62596273, 54160642, 25234021, 72582117, 47052609, 61790284, 30693924,
	50870633, 86497518, 93177652, 55270147, 91548444, 56286010, 83995978, 60917667, 80531669, 55159210, 99641833, 99507551, 99801967, 49845601, 91776850, 92744334, 51093947, 55673016, 46872084, 78412811, 93018260, 76530696, 50929833, 90499168, 100716996, 94761119, 57424009, 72516047, 98006329, 80843217, 86583990, 99326296, 54004239, 61986115, 55135257, 68254713, 98660746, 57949744, 97029249, 45123123, 91903003, 65874826, 94104003, 99497194, 76451711, 90304330, 100867187, 101951894, 98016712, 72439739, 87740631, 97598311, 85723490, 75648645, 67596609, 88822410, 93902779, 96440443, 62281526, 90447761, 97213557, 58753224, 94999558, 62186809, 64693149, 16908740, 96015893, 99415768, 76530142, 72905739, 62931979, 54444031, 62281309, 86975934, 44345946, 47069389, 98173616, 98554918, 90324117, 49333330, 14040939, 93640842, 76550105, 72244164, 75106731, 85665275, 89714484, 89254474, 62015193, 18964228, 82512127, 85735375, 77591994, 60991448, 100821611, 45537004, 75747170, 50314912, 87146196, 100378783, 72892520, 5761858, 99465801, 96424277, 57709849, 62905092, 47033500, 49842009, 86954655, 47153311, 101343179, 98643228, 100154322, 88165774, 76765637, 61004565, 62655996, 92120169, 62147499, 101951911, 100577869, 98827788, 100692812, 83985998, 90073161, 59999807, 91531864, 59621040, 82412758, 71032922, 96127452, 94610090, 76632930, 98015730, 62272965, 89868918, 99539745, 88692425, 50758856, 47043339, 52161494, 69600728, 73577511, 90582530, 50940701, 98724621, 96579881, 98393977, 72905375, 7899130, 85336499, 99644395, 95092260, 89945715, 52716889, 97811082, 61485746, 100024284, 62945408, 56478831, 11609223, 49301422, 62285699, 57658264, 72422420, 56484398, 74411403, 83845100, 88999140, 90026985, 49697385, 94317211, 101061658, 99983583, 68551255, 87769471, 86109138, 98446723, 101190565, 7654067, 58260221, 51367936, 75045732, 55131909, 91518224, 48897487, 99333704, 97213418, 63800514, 87672140, 36538320, 61501757, 91387288, 49555378, 51099000, 96576434, 58098667, 48899487, 52468031, 1040527, 75590674, 64467669, 51521924, 99360796, 49533553, 83627480, 71525177, 62621199, 100733390, 100687358, 100687665, 64483240, 18851246, 95702071, 96741312, 98638157, 54528751, 55148434, 44236149, 95547215, 45940147, 77400298, 77563748, 45113737, 88046187, 53502808, 77415688, 96650474, 86955663, 44595207, 89871414, 87872053, 66632916, 55654879, 75784154, 94180927, 10762997, 81434495, 88399110, 45890674, 71930339, 69664651, 86976381, 88389616, 71233627, 80503616, 90404857, 18718570, 53135140, 63144340, 92552990, 43054623, 87867272, 93605172, 45891910, 101458004, 79972765, 83179160, 44734123, 90943034, 92372028, 94245421, 57570460, 75601267, 77417953, 100507739, 98659011, 96111579, 88744569, 57429837, 72891046, 59621620, 81549611, 99522326, 75803273, 47580926, 89883878, 99416461, 76780832, 100946821, 100522192, 78795051, 99522817, 70351811, 90150948, 54745728, 60988535, 100528627, 91102678, 100715708, 87407538, 90075447, 67380881, 72714534, 64140554, 68620374, 64471214, 85830631, 100413202, 70350692, 79122445, 98724083, 90571815, 96317676, 97554268, 98670052, 98197738, 74753539, 18029373, 60109751, 87223890, 76921370, 99583550, 75105504, 99313866, 61576841, 92336223, 46243447, 94128269, 47281101, 96111412, 85335095, 98675130, 53747043, 98841318, 77380348, 99470005, 50238186, 16872647, 57900409, 10329583, 78871965, 99313847, 90524530, 5163547, 45740904, 86605549, 94934110, 93645747, 62148644, 72050424, 81454084, 70349107, 62153650, 20498687, 98841356, 50265622, 44520407, 44536835, 87842606, 92301751, 100704472, 77954257, 95389634, 10520228, 72237228, 51213807, 73612440, 71949677, 47047667, 76647441, 89214259, 97676410, 70730919, 94255588, 99344923, 75047155, 99839828, 92874745, 53540550, 100257492, 75038280, 79413969, 99246022, 91618263, 91191108, 45897337, 94448734, 54918357, 65858456, 62948099, 71639524, 57614098, 100979778, 59625098, 20617348, 96441713, 35236512, 99161670, 71539871, 66930059, 91382373, 101376536, 99321983, 51214495, 97130954, 59504983, 44925413, 75945208, 96317811, 74019210, 86398176, 90143668, 71925623, 99416548, 101795053, 91140963, 57958886, 50934469, 64152773, 99539905, 48234833, 48296864, 75767983, 78068287, 98147546, 61991488, 90696427, 71846790, 80101430, 76803258, 61178624, 86700221, 84981036, 43052329, 98686908, 81476121, 78596384, 43057530, 101815893, 6022146, 62987398, 6082771, 72924741, 99754265, 73608887, 93805228, 84498612, 100528632, 78102390, 101871469, 18851244, 99838815, 55859523, 92760823, 101024618, 67391969]; // pads in the experiment
	function in_array(arr, value){
		for (var i = 0, l = arr.length; i < l; i++)
			if (arr[i] == value) return true;
		return false;
	}
	return in_array(SELECTED_PAD_IDS, pad_id);
}

function begunTryNewBlocks(){
	var AC2_URL = 'http://autocontext.begun.ru/autocontext2.js'; // autocontext2.js url
	window.begun_block_id = 23; // a fake block
	
	document.write('<scr' + 'ipt type="text/javascript" src="' + AC2_URL + '"></scr' + 'ipt>');

	if (typeof window.begun_auto_colors == 'undefined') window.begun_auto_colors = [];
	window.begun_extra_block = {
		"id": window.begun_block_id,
		"options": {
			"visual": {
				"title": {
					"color": window.begun_auto_colors[0] || "",
					"fontSize": window.begun_auto_fonts_size[0] || ""
				},
				"text": {
					"color": window.begun_auto_colors[1] || "",
					"fontSize": window.begun_auto_fonts_size[0] || ""
				},
				"domain": {
					"color": window.begun_auto_colors[2] || "",
					"fontSize": window.begun_auto_fonts_size[2] || ""
				},
				"block": {
					"backgroundColor": window.begun_auto_colors[3] || ""
				}
			},
			"dimensions": {
				"type": String(window.begun_block_type || "vertical").toLowerCase(),
				"width": window.begun_auto_width || ""
			},
			"banners_count": window.begun_auto_limit || 0,
			"use_scroll": window.begun_scroll || 0,
			"show_thumbnails": 0, // can't check it
			"misc_id": window.misc_id || -1
		}
	};
}

if (begunIsReadyForNewBlocks(window.begun_auto_pad || 0)){
	begunTryNewBlocks();
}else{
	function begunGetFrameLevel(){
		var level = 0;
		var _parent = self;
		while (_parent !== top && level < 999){
			_parent = _parent.parent;
			level++;
		}
		return level;
	}
	
	begun_auto_url = 'http://autocontext.begun.ru/context.jsp?';
	var params = {
		'pad_id': window.begun_auto_pad,
		'lmt': Date.parse(document.lastModified) / 1000,
		'n': window.begun_auto_limit,
		'begun_utf8': window.begun_utf8,
		'begun_koi8': window.begun_koi8,
		'begun_scroll': window.begun_scroll,
		'many_span': window.many_span,
		'misc_id': typeof(window.begun_misc_id) == 'undefined' ? window.misc_id : window.begun_misc_id,
		'begun_multispan': window.begun_multispan,
		'sense_mode': 'custom',
		'stopwords': window.stopwords || '',
		'begun_self_keywords': window.begun_self_keywords,
		'ref': document.referrer,
		'real_refer': document.location,
		'pure_graph_data': window.begun_pure_graph_data || 0
	}
	if(screen && screen.width && screen.height) {
		params['ut_screen_width'] = screen.width;
		params['ut_screen_height'] = screen.height;
	}
	begun_frame_level = begunGetFrameLevel();
	if (begun_frame_level){
		params['frm_level'] = begun_frame_level;
		try{
			params['frm_top'] = top.location.href;
		}catch(e){
			params['frm_top'] = 'top not accessible';
		}
	}
	
	begunAppend(params);
	
	if (window.begun_scroll) {
		var host = 'http://autoscroll.begun.ru/';
		var jsfiles = ['prototype.lite.js', 'moo.fx.js', 'moo.fx.scroll.js', 'begunScroll.js'];
		for (var i in jsfiles)
			if (jsfiles[i] && jsfiles.hasOwnProperty && jsfiles.hasOwnProperty(i)) // always check for own property in for .. in ..
				adstek_include(host + jsfiles[i]);
	}
	
	begun_auto_url = begun_auto_url.substring(0, 1524).replace(/%[0-9a-fA-F]?$/, '');
	adstek_include(begun_auto_url);
}


var adstek_cr_d = adstek_cr_d || 1;
var adstek_cr_w2 = begun_auto_width || 300;
var adstek_cr_f1 = begun_auto_fonts_size[0] || 12;
var adstek_cr_f2 = begun_auto_fonts_size[1] || 10;
var adstek_cr_f3 = begun_auto_fonts_size[2] || 10;
if (!window.begun_auto_colors)
	begun_auto_colors = [];
var adstek_cr_c1 = typeof begun_auto_colors[0] == 'undefined'? 0xFFCC66 : adstek_parse_color(begun_auto_colors[0]);
var adstek_cr_c2 = typeof begun_auto_colors[1] == 'undefined'? 0xFFFFFF : adstek_parse_color(begun_auto_colors[1]);
var adstek_cr_c3 = typeof begun_auto_colors[2] == 'undefined'? 0xFFCC66 : adstek_parse_color(begun_auto_colors[2]);
if (!window.corner_color)
	corner_color = [];
var adstek_cr_bc1 = typeof corner_color[1] == 'undefined'? 0xFF0000 : adstek_parse_color(corner_color[1]);
var adstek_cr_bc2 = typeof corner_color[0] == 'undefined'? 0x993300 : adstek_parse_color(corner_color[0]);
var adstek_cr_brc = typeof corner_color[2] == 'undefined'? 0x880000 : adstek_parse_color(corner_color[2]);

var adstek_cr_obj_content;
var adstek_cr_container=true;

adstek_cr_w2 = adstek_process_width(adstek_cr_w2);
	
function adstek_cr_add_param(name, value)
{
    adstek_cr_obj_content += '<param name="'+name+'" value="'+value+'"></param>';
}

function adstek_cr_add_attr(name, value)
{
    adstek_cr_obj_content += ' '+name+'="'+value+'" ';
}

function adstek_cr_open()
{
    adstek_cr_container.style.width = adstek_cr_w2;
    adstek_cr_container.style.height = adstek_cr_w2;
    adstek_cr_container.scrollLeft = 1000;
}

function adstek_get_width_by_percent(percent_width)
{
	var width;
	if (isIE)
		width = document.body.offsetWidth;
	else
		width = window.innerWidth;
	return parseInt(width*parseInt(percent_width)/100)+'px';
}

function adstek_parse_color(color)
{
	if (color.constructor == String)
	{
		if (color.indexOf('0x')==-1)
			color = '0x'+color.replace(/#/, '');
		color = parseInt(color);
	}
	return color;
}

function adstek_process_width(width)
{
	if ((width+' ').indexOf('%')!=-1)
		return adstek_get_width_by_percent(width);
	else
		return parseInt(width)+'px';
}

function adstek_cr_close()
{
    adstek_cr_container.style.width = '80px';
    adstek_cr_container.style.height = '80px';
    adstek_cr_container.scrollLeft = 1000;
}

function adstek_cr_()
{
	adstek_cr_hide();
}

function adstek_cr_hide()
{
    adstek_cr_container.style.display = 'none';
}

function insertAfter(newElement,targetElement) {
	var parent = targetElement.parentNode;
	if (parent.lastChild == targetElement) {
		parent.appendChild(newElement);
	} else {
		parent.insertBefore(newElement,targetElement.nextSibling);
	}
}

function insertAfterScript(script_src, insert_el)
{
	var scripts = document.getElementsByTagName('script');
	for (var i in scripts)
		if (scripts[i].src && scripts[i].src.indexOf(script_src) != -1)
		{
			var script = scripts[i]; 
			break;
		}
	insertAfter(insert_el, script);
}

function adstek_create_tag(name, content)
{
	return '<'+name+'>'+content.replace(/\<\/?b\>/g, "")+'</'+name+'>';
}

function adstek_cr_go(url)
{
	if ( isIE && !isOpera )
	{
		var a = document.createElement('a');
		a.href = url;
		a.target = '_blank';
		document.body.appendChild(a);
		a.click();
	}
	else
		window.open(url);
}

function adstek_get_ads_xml()
{
	
	var xml = '<?xml version="1.0" encoding="utf-8"?><begun>';
	for (var i in begunBanners)
	{
		if (parseInt(i) != i)
			continue;
		xml += '<banner>';
		xml += adstek_create_tag('url', begunBanners[i][2]);
		xml += adstek_create_tag('title', begunBanners[i][0]);
		xml += adstek_create_tag('desc', begunBanners[i][1]);
		xml += adstek_create_tag('domain', begunBanners[i][4]);
		xml += '</banner>\n';
	}
	return xml+'</begun>';
}


function adstek_draw_corner()
{

	var params = {
		'src': 'http://search.sputnik1.ru/corner.swf?bc1='+adstek_cr_bc1+'&bc2='+adstek_cr_bc2+'&brc='+adstek_cr_brc+'&f1='+adstek_cr_f1+'&f2='+adstek_cr_f2+'&f3='+adstek_cr_f3+'&d='+adstek_cr_d+'&c1='+adstek_cr_c1+'&c2='+adstek_cr_c2+'&c3='+adstek_cr_c3+'&w2='+parseInt(adstek_cr_w2),
		'quality': 'high',
		//'play':'true',
		//'loop':'true',
		'wmode': 'transparent',
		'width': 1000,
		'height': 700,
		'align': 'middle',
		'allowScriptAccess': 'always',
		//'allowFullScreen': 'false',
		'type':'application/x-shockwave-flash',
		'pluginspage': 'http://www.macromedia.com/go/getflashplayer'
	};
	adstek_cr_obj_content = '<div style="width:1000px;"><object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="1000" height="700" align="middle" id="FunnyCorner" name="FunnyCorner" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" >';
	
	adstek_cr_container = document.getElementById('adstek_cr_container');
	adstek_cr_container.style.visibility = 'hidden';
	adstek_cr_container.style.position = 'absolute';
	adstek_cr_container.style.zIndex = 100000;
	adstek_cr_container.style.top = '0px';
	adstek_cr_container.style.right = '0px';
	adstek_cr_container.style.width = '80px';
	adstek_cr_container.style.height = '80px';
	adstek_cr_container.style.overflow = 'hidden';
	adstek_cr_container.style.zIndex = '1000000';
	
	for (var i in params)
		adstek_cr_add_param(i, params[i]);

	if (isIE && !isOpera)
	{
		adstek_cr_obj_content += '</object></div>';
	}
	else
	{
		adstek_cr_obj_content += '<embed';
		var flashvars = ' flashvars="';
		for (var i in params)
		{
			adstek_cr_add_attr(i, params[i]);
			flashvars += i+'='+params[i]+'&';
		}
		flashvars += '"' ;
		adstek_cr_obj_content += flashvars+'></embed></object></div>';
	}
	
	adstek_cr_container.innerHTML = adstek_cr_obj_content;

	adstek_cr_container.scrollLeft = 1000;
	setTimeout(function(){
	    adstek_cr_container.firstChild.firstChild.outerHTML = adstek_cr_container.firstChild.firstChild.outerHTML;
	    adstek_cr_container.style.visibility = 'visible';
	}, 100);
}