﻿Ext.onReady(function() {
    var doc = this.document;

    Ext.select('.linkarea .link').hover(function(el) {
        Ext.fly(this).replaceClass('link-area', 'link-area-hover');
    }, function(el) {
        Ext.fly(this).replaceClass('link-area-hover', 'link-area');
    });


    Ext.select('.offer .short h1 > a').each(function(el) {
        var innerHTML = Ext.fly(this).dom.innerHTML;
        var parentEl = this.parent('h1', true);
        this.remove();
        parentEl.innerHTML = innerHTML;
    });

    Ext.select('.offer .short').on('click', function(el) {
        Ext.get(this).select('a:has(img)').each(function(el) {
            doc.location = Ext.fly(el).dom.href;
        });
    }).on('mouseover', function(e, t) {
        Ext.get(t).setStyle('cursor', Ext.isIE ? 'hand' : 'pointer');
    });


    Ext.fly('searchbox').on("keypress", function(e) {
        var v = e.getCharCode();
        if (v == 13) {
            new Ext.util.DelayedTask(function() {
                //  alert(Ext.get('searchbox').dom.value);
                this.document.location = "?aid=9077505&box9077506argument=[arg]".replace('[arg]', Ext.get('searchbox').dom.value);

            }).delay(5);
        }
    }, this);


    var boxEls = Ext.select('#rightbar .newsletterbox');
    var boxWidth = 0;
    var boxHeight = 0;

    boxEls.each(function(item, i) {
        var borderTemplate = new Ext.Template('<div class="box-border box-border-{pos}"><img src="im/trans.gif" height="1" width="1"/></div>')
        var boxWrapper = document.createElement('div');
        var boxEl = new Ext.Element(item);
        boxWrapper.className = 'box-wrapper';
        Ext.fly('rightbar-b').appendChild(boxWrapper);
        var topEl = borderTemplate.append(boxWrapper, { pos: 'top' });
        Ext.fly(boxWrapper).appendChild(boxEl);
        var botEl = borderTemplate.append(boxWrapper, { pos: 'bottom' });

        boxHeight = Ext.fly(item).getHeight();
        boxWidth = Ext.fly(item).getWidth();

        Ext.fly(boxWrapper).setHeight(boxHeight + 16);
        Ext.fly(boxWrapper).setWidth(boxWidth);

        Ext.fly(topEl).setWidth(boxWidth);
        Ext.fly(topEl).setTop(0);

        Ext.fly(botEl).setWidth(boxWidth);
        Ext.fly(botEl).setTop(boxHeight + 8);



    });

    var rightbarHeight = Ext.fly('rightbar').getHeight();
    var mainHeight = Ext.fly('main').getHeight();
    if (rightbarHeight > mainHeight)
        Ext.fly('main').setHeight(rightbarHeight + 20);




});
