YAHOO.namespace('profiles.ad');

// Return true if el is visible, and is at least (w0 x h0) pixels,
// and has upper corner within [0, x1] and [0, y1].
// x1 is adjusted by the browser window width.
YAHOO.profiles.ad.visible = function (el, w0, h0, x1, y1) {
    var r = YAHOO.util.Dom.getRegion(el);

    if (!r) {
        return false;
    }
    if ( _proxy_jslib_handle(r, 'top', '', 0, 0) === undefined) {
        return false;
    }
    if (r.right - r.left < w0) {
        return false;
    }
    if (r.bottom -  _proxy_jslib_handle(r, 'top', '', 0, 0) < h0) {
        return false;
    }

    var vw = YAHOO.util.Dom.getViewportWidth();
    x1 = Math.max(x1, vw - w0);
    if (r.left < 0 || r.left > x1) {
        return false;
    }
    if ( _proxy_jslib_handle(r, 'top', '', 0, 0) < 0 ||  _proxy_jslib_handle(r, 'top', '', 0, 0) > y1) {
        return false;
    }
    return true;
};

YAHOO.profiles.ad.lrec = function (root_id, base_url) {
    var container =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(root_id);
    if (!container) {
        return;
    }
    var divs = YAHOO.util.Dom.getElementsByClassName(
        'async-ad', 'div', container);
    if (!divs[0]) {
        return;
    }
    if (!YAHOO.profiles.ad.visible(divs[0], 280, 280, 200, 500)) {
        return;
    }
    base_url += "&ad=" + divs[0].id;

    var el = document.createElement('iframe');
     _proxy_jslib_handle(el, 'setAttribute', '', 1, 0)('height', '270px');
     _proxy_jslib_handle(el, 'setAttribute', '', 1, 0)('width', '300px');
     _proxy_jslib_handle(el, 'setAttribute', '', 1, 0)('src', base_url);
     _proxy_jslib_handle(el, 'setAttribute', '', 1, 0)('allowTransparency', 'true');
     _proxy_jslib_handle(el, 'setAttribute', '', 1, 0)('frameBorder', 0);
     _proxy_jslib_handle(el, 'setAttribute', '', 1, 0)('scrolling', 'no');
     _proxy_jslib_handle(el, 'setAttribute', '', 1, 0)('marginwidth', 0);
     _proxy_jslib_handle(el, 'setAttribute', '', 1, 0)('marginheight', 0);
    divs[0].appendChild(el);
};
 ;
_proxy_jslib_flush_write_buffers() ;