﻿function getPosTop(e)
{
    var t=e.offsetTop;
    while(e=e.offsetParent)
    { 
        t+=e.offsetTop;
    }
    return t;
}

function getPosLeft(e)
{
    var l=e.offsetLeft;    
    while(e=e.offsetParent)
    { 
        l+=e.offsetLeft;
    }
    return l;
}        

function resizeClip(obj, top,right,bottom,left)
{
    obj.style.clip = "rect(" + top + " " + right + " " + bottom + " " + left + ")";
}

function resizeIframe(obj, width, height)
{
    document.getElementById(obj).width=width; 
    document.getElementById(obj).height=height;
}

function expandBanner(divObj, iframeId, pos_top, pos_left, top, right, bottom, left)
{
    divObj.style.top = getPosTop(divObj) + parseInt(pos_top.replace("px", "")) + "px";
    divObj.style.left = getPosLeft(divObj) + parseInt(pos_left.replace("px", "")) + "px";
    resizeIframe(iframeId, parseInt(right.replace("px","")) - parseInt(left.replace("px","")) + "px", parseInt(bottom.replace("px","")) - parseInt(top.replace("px","")) + "px" );
    resizeClip(divObj, top, right, bottom, left);
}

function contractBanner(divObj, iframeId, top, right, bottom, left)
{
    divObj.style.top = "auto";
    divObj.style.left = "auto";
    resizeIframe(iframeId, parseInt(right.replace("px","")) - parseInt(left.replace("px","")) + "px", parseInt(bottom.replace("px","")) - parseInt(top.replace("px","")) + "px" );
    resizeClip(divObj, top, right, bottom, left);
}