﻿if (typeof AutoOneMedia == "undefined")
    var AutoOneMedia = new Object();

AutoOneMedia.IFramePopup = function(href, width, height, image, offset, background, disableBackground)
{
    if (!document.getElementById)
        return;

    if (!image || image == '')
        image = "http://services.dealerpro.net/Images/CMS/popup-bar-01.jpg";

    if (!offset || offset == '')
        offset = "-160px";

    if (!background || background == '')
        background = "http://services.dealerpro.net/Images/CMS/black70.png";
    
    if (!disableBackground || disableBackground == '')
        disableBackground = false;

    this.href = href;
    this.width = width;
    this.height = height;
    this.image = image;
    this.offset = offset;
    this.background = background;
    this.isBackgroundDisabled = disableBackground;
    this.element = null;
};

AutoOneMedia.IFramePopup.prototype = 
{
    Open:function()
    {
        var d1 = document.createElement("div");
        var d2 = document.createElement("div");
        var d3 = document.createElement("div");
        var i1 = document.createElement("iframe");
        var scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
        var scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
        var clientWidth = 0;
        var clientHeight = 0;
        var position = "fixed";
        var barHeight = 24;
                
        if (navigator.userAgent.indexOf(' MSIE ') > -1)
        {
            clientWidth = document.documentElement.clientWidth;
            clientHeight = document.documentElement.clientHeight;
            position = "absolute";
        }
        else if (navigator.userAgent.indexOf(' Safari/') > -1)
        {
            clientWidth = window.innerWidth;
            clientHeight = window.innerHeight;
        }
        else if (navigator.userAgent.indexOf('Opera/') > -1)
        {
            clientWidth = Math.min(window.innerWidth, document.body.clientWidth);
            clientHeight = Math.min(window.innerHeight, document.body.clientHeight);
        }
        else
        {
            clientWidth = Math.min(window.innerWidth, document.documentElement.clientWidth);
            clientHeight = Math.min(window.innerHeight, document.documentElement.clientHeight);
        }

        if (!this.isBackgroundDisabled)
        {
            d1.style.background = "url(" + this.background + ")";
            d1.style.height = Math.max(Math.max(document.documentElement.scrollHeight, document.body.scrollHeight), clientHeight) + "px";
            d1.style.width = Math.max(Math.max(document.documentElement.scrollWidth, document.body.scrollWidth), clientWidth) + "px";
            d1.style.position = "absolute";
            d1.style.left = "0px";
            d1.style.top = "0px";
            d1.style.zIndex = 100000;
        }

        d2.style.backgroundColor = "#fff";
        d2.style.height = this.height + "px";
        d2.style.width = this.width + "px";
        d2.style.position = position;
        d2.style.left = scrollLeft + ((clientWidth - this.width) / 2) + "px";
        d2.style.top = scrollTop + ((clientHeight - this.height) / 2) + barHeight + "px";
        d2.style.zIndex = 1000001;
        
        d3.style.height = barHeight + "px";
        d3.style.width = this.width + "px";
        d3.style.background = "url(" + this.image + ") no-repeat " + this.offset + "px 0px";
        d3.onclick = this.Close;
        
        i1.src = this.href;
        i1.border = 0;
        i1.frameBorder = 0;
        i1.width = this.width;
        i1.height = this.height;
        i1.style.width = this.width + "px";
        i1.style.height = this.height + "px";
        
        d2.appendChild(d3);
        d2.appendChild(i1);
        d1.appendChild(d2);
        document.body.insertBefore(d1, document.body.firstChild);
        
        this.element = d2;
    },

    Close:function()
    {
        document.body.removeChild(document.body.firstChild);
    }
};
