
function AdSlot(){

    /*public variables*/
    this.adDivID = null;
    this.locationElements = null;
    
    /*private variables*/
    var widestElementWidth = null;
    var widestElementCoords = null;
    var BANNER_TOP_POSITION = 10;
    
    var that = this;
    
    /*private methods*/
    var GetLocationElementsParams = function(){
        
        var coordsElement = GetWidestElement();
        
        if (coordsElement != 'undefined' && coordsElement != null)
        {
            widestElementWidth = coordsElement.clientWidth;
            widestElementCoords = FindCoords(coordsElement)
        }
    }

    var GetWidestElement = function(){
       
        var elements = that.locationElements;
        
        var elemIds = elements.split(',');
        var maxWidth = 0;
        var widestElement;
        for (var i = 0; i < elemIds.length; i ++)
        {
            var elem = document.getElementById(elemIds[i].replace(' ', ''));
            if (elem != 'undefined' && elem != null)
            {
                if (elem.clientWidth >= maxWidth)
                {
                    maxWidth = elem.clientWidth;
                    widestElement = elem;
                }
            }
        }
        return widestElement;
    }
    
    var FindCoords = function(obj){
    
        var curleft = curtop = 0;
        if (obj.offsetParent) {
            do {
                curleft += obj.offsetLeft;
                curtop += obj.offsetTop;
            } while (obj = obj.offsetParent);
        }
        return [curleft,curtop];
    }
    
    /* public methods */
    this.SetADCoords = function(side)
    {
        GetLocationElementsParams();
        
        if (widestElementWidth != null && widestElementCoords != null)
        {
            var elementToLoad = that.adDivID; 
            var bannerDiv = document.getElementById(elementToLoad);
            
            if (bannerDiv != 'undefined' && bannerDiv != null)
            {
                bannerDiv.style.position = 'absolute';
                bannerDiv.style.top = BANNER_TOP_POSITION;
                
                if (side == 'left')            
                    bannerDiv.style.right = widestElementCoords[0] + widestElementWidth;  
                if (side == 'right')
                    bannerDiv.style.left = widestElementCoords[0] + widestElementWidth; 
                    
                if (that.adDivID != null)
                {
                    var Banner_Div = document.getElementById(that.adDivID);
                    if (Banner_Div != 'undefined' && Banner_Div != null)
                    {
                        Banner_Div.style.display = 'block';
                    }
                }
            }
        } 
          
    }
}



