/*
Expert.ru TeaserBlock Plugin
Last edit: 10.09.2012
*/
(function(pluginName) {
    new adriver.Plugin(pluginName);

    adriver.prototype.TeaserBlock = {
        hide:function(e) {
            clearInterval(e.t);
            e.d = 5;
            e.d2 = 2;
            e.t = setInterval(function() {
                var p = e.parentNode;
                p.parentNode.style.zIndex = p.style.zIndex = 9998;
                if (e.ext) p.parentNode.parentNode.style.zIndex = 9998;
                var h = p.offsetHeight;
                var w = p.offsetWidth;
                if (h <= 100 || w <= 100) {
                    clearInterval(e.t);
                    p.parentNode.style.zIndex = p.style.zIndex = 9997;
                    if (e.ext) p.parentNode.parentNode.style.zIndex = 9997;
                    p.style.height = '100px';
                    p.style.width = '100px';
                    p.style.top = p.style.left = '0px';
                }
                else {
                    if (e.direction == 1) p.style.top = p.offsetTop + 0 + 'px';
                    else if (e.direction == 2) p.style.top = -Math.ceil((h - e.d - 100) / 2) + 'px';
                    else if (e.direction == 3) p.style.top = --e.X - h + e.d + 100 + 'px';
                    p.style.height = h - e.d + 'px';
                    p.style.width = w - e.d + 'px';
                }
                e.d += e.d2;
                if (e.d > 13)e.d2 = -2;
            }, 15);
        },

        show:function(e) {
            clearInterval(e.t);
            e.d = 5;
            e.d2 = 2;
            e.X = 0;
            e.t = setInterval(function() {
                var p = e.parentNode;

                p.parentNode.style.zIndex = p.style.zIndex = 9999;
                if (e.ext) p.parentNode.parentNode.style.zIndex = 9999;
                var h = p.offsetHeight;
                // комментирован вывод в консоль для корректной работы в IE 7-8 10.09.2012
				//console.log(h);
                var w = p.offsetWidth;
                if (h >= 200 || w >= 200) {
                    clearInterval(e.t);
                    p.style.height = '200px';
                    p.style.width = '200px';
                    p.style.top = p.style.left = '0px';
                }
                else {
                    if (e.direction == 1) p.style.top = p.offsetTop - 0 + 'px';
                    else if (e.direction == 2) p.style.top = -Math.ceil((h + e.d - 100) / 2) + 'px';
                    else if (e.direction == 3) p.style.top = ++e.X - h - e.d + 100 + 'px';
                    p.style.height = h + e.d + 'px';
                    p.style.width = w + e.d + 'px';

                }

                e.d += e.d2;
                if (e.d > 13)e.d2 = -2;
            }, 15);
        },
        draw:function(a,animate) {
            var sep = "&#x7C;",
            	alt = a.reply.alt.replace(/&#x5C;n/g, '<br>').split(sep);

            var ar_img = ((/^http:\/\//i.test(a.reply.comp0) ? '' : a.reply.comppath) + a.reply.comp0).replace(/!\[rnd\]/g, a.reply.rnd);
            var ar_img_float = "left";
			a.p.innerHTML ='<div class="sponsor"><div class="picture" style="margin:0;padding:0;position:relative;float:left;margin-rigth:10px;"><a target="_blank"  style="position:absolute;width:100px;height:100px" href="'
			+ a.reply.cgihref+'"><img NAME=im0 id="ar_img'+a.reply.bn+'" border="none" width="100%" height="100%" align="left" alt="" src="'+ar_img+'"></a></div>'
             +'<p style="padding-left:110px;"><a target="_blank" style="color:#005689;font-size:12px" href="'+ a.reply.cgihref+'">'+'<b>'+alt[0]+'</b><br>'+alt[1]+'</a></p></div>';
            if(animate) {
			var e = document.getElementById('ar_img' + a.reply.bn);
            if (e) {
                e.onmouseover = function() {
                    a.TeaserBlock.show(e)
                };
                e.onmouseout = function() {
                    a.TeaserBlock.hide(e)
                };
                e.direction = 1;
                if (parent == self) e.ext = 0;
                else e.ext = 1;
            }
			}
			if(alt[2]) {
			    var pix=unescape(alt[2].replace(new RegExp("&#x",'g'),'%').replace(new RegExp(';','g'),''));
			    adriver.x(pix);
			}
            return a
        }
    }

    var ar_animate=0; //0 - ??? ???????? ????????; 1-? ????????? ???????? ?? ?????????.
    adriver.TeaserBlock = {
        drawContainer:function(id,width,height,animate) {

            var container = document.getElementById(id);
            if(width!='auto') container.style.width = width+'px';
			if(height!='auto') container.style.height = height+'px';
			container.firstChild.style.height='100%';
            var items = container.getElementsByTagName('TD');
            for (var i = 0; i < items.length; i++) {
                var a = adriver(items[i].id);
				a.p.vAlign='top';
                if (a && a.reply && a.reply.bid != 1027281) {
                    a.TeaserBlock.draw(a,animate);
                }
            }
            return container
        }
    }
	if(!adriver.x)adriver.x = function(s){var D = document, B = document.body;var i=D.createElement('img');i.style.position='absolute';i.style.width=i.style.height='0px';i.src=s;i.onload=i.onerror=function(){B.removeChild(i)};B.insertBefore(i,B.firstChild)};
    adriver.Plugin(pluginName).loadComplete();
})("TeaserBlock.expert");