
function MBanner(element, options)
{
    this.options = options == null ? { } : options;
    this.listId = options.listId == null ? 0 : options.listId;
    this.count = options.count == null ? 1 : options.count;
    this.itemClass = options.itemClass == null ? "" : options.itemClass;

    if (typeof(element) == "string")
    {
        this.element = document.getElementById(element);
    }
    else
    {
        this.element = element;
    }

    if (typeof(options.clickArea) == "string")
    {
        this.clickArea = document.getElementById(options.clickArea);
    }
    else
    {
        this.clickArea = options.clickArea;
    }
}

MBanner.prototype.load = function ()
{
    jQuery.getJSON("/index.aspx?p=GetBanner&lst=" + this.listId + "&count=" + this.count, null, this.createLoadResponse());
}

MBanner.prototype.createLoadResponse = function ()
{
    var elem = this;
    return function (data) { elem.load_Response(data); };
}

MBanner.prototype.createLoad = function ()
{
    var elem = this;
    return function (data) { elem.load(); };
}

MBanner.prototype.load_Response = function(data)
{
    var items = data.i;   
    
    if (items.length > 0)
    {
        if (items[0].pt > 0)
        {
            setTimeout(this.createLoad(), (items[0].pt * 1000));
        }

        var banners = "";
        for (var i = 0; i < items.length; i++)
        {
            banners += "<div class=\"" + this.itemClass + "\">"
            if (items[i].e == ".swf")
            {                               
                banners += "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" width=\""+ items[i].w  + "\" height=\""+ items[i].h  + "\" id=\"eskema_software\" align=\"middle\">"
	                + "<param name=\"allowScriptAccess\" value=\"sameDomain\" />"
	                + "<param name=\"allowFullScreen\" value=\"false\" />"
	                + "<param name=\"wmode\" value=\"transparent\" />"
	                + "<param name=\"flashvars\" value=\"clickTAG=%2Findex.aspx%3Fp%3DClickBanner%26BnId%3D" + items[i].id + "%26PrntId%3D" + items[i].pi + "%26token%3D" + items[i].tk + "%26url%3D" + items[i].l + "\"/>" 
	                + "<param name=\"movie\" value=\"/images/m_banners_images/"+ items[i].f  + "\" /><param name=\"quality\" value=\"high\" /><param name=\"bgcolor\" value=\"#ffffff\" />"
	                + "<embed flashvars=\"clickTAG=%2Findex.aspx%3Fp%3DClickBanner%26BnId%3D" + items[i].id + "%26PrntId%3D" + items[i].pi + "%26token%3D" + items[i].tk + "%26url%3D" + items[i].l + "\" wmode=\"transparent\" src=\"/images/m_banners_images/"+ items[i].f  + "\" quality=\"high\" bgcolor=\"#ffffff\" width=\""+ items[i].w  + "\" height=\""+ items[i].h  + "\" name=\"eskema_software\" align=\"middle\" allowScriptAccess=\"sameDomain\" allowFullScreen=\"false\" type=\"application/x-shockwave-flash\" pluginspage=\"https://www.macromedia.com/go/getflashplayer\" />"
		            + "</object>";  
            }
            else
            {
                if (items[i].l == "1")
                    banners += "<a target=\"_blank\" href=\"/index.aspx?p=ClickBanner&BnId=" + items[i].id + "&PrntId=" + items[i].pi + "&token=" + items[i].tk + "&url=" + items[i].l + "\">";
                
                banners += "<img height=\"" + items[i].h + "\" width=\"" + items[i].w + "\" src=\"/images/m_banners_images/" + items[i].f + "\">";
                
                if (items[i].l == "1")
                    banners += "</a>";
            }
            banners += "</div>"

            if (this.clickArea != null)
            {
                this.clickArea.href = "/index.aspx?p=ClickBanner&BnId=" + items[i].id + "&PrntId=" + items[i].pi + "&token=" + items[i].tk + "&url=" + items[i].l + "&lstId=" + items[i].lst;
            }
        }
        this.element.innerHTML = banners;
    } 
    else
    {
        this.element.innerHTML = "";
        if (this.clickArea != null)
        {
            this.clickArea.href = "#";
        }
    }                  
}
