﻿var MyLightbox = {
    show: function(width, height, iframe) {
        if (!this._isCreated) {
            var _body = document.getElementsByTagName('BODY')[0];
            var _firstChild = _body.childNodes[0];
            var _container = document.createElement('div');
            var _bg = document.createElement('div');
            _bg.id = 'mylightbox-bg';
            _bg.style.display = 'none';
            var _box = document.createElement('div');
            _box.id = 'mylightbox';
            _box.style.display = 'none';
            var frame = document.createElement('iframe');
            frame.id = 'lightbox_iframe';
            frame.frameBorder = 0;
            frame.scrolling = 'no';
            frame.style.width = '100%';
            _box.appendChild(frame);
            _container.appendChild(_bg);
            _container.appendChild(_box);
            _body.insertBefore(_container, _firstChild);
            this._isCreated = true;
        }
        var _mylightbox = document.getElementById('mylightbox');
        this.lightbox = _mylightbox;
        var _mylightbox_bg = document.getElementById('mylightbox-bg');
        this.lightboxBg = _mylightbox_bg;
        var _iframe = document.getElementById('lightbox_iframe');
        /*
        var _fullWidth = this.fullWidth(), _fullHeight = this.fullHeight();
        var center = this.center(_width, _height);
        */
        var _width = width ? width : 500;
        var _height = height ? height : 500;
        var _center=Utils.Position.center(_width,_height,window);
        _mylightbox.style.left = _center[0] + 'px';
        _mylightbox.style.top = _center[1] + 'px';
        _mylightbox.style.width = _width + 'px';
        _mylightbox.style.height = _height + 'px';
        var _xy_scroll=Utils.Position.scrollXY(window);
        var _vp=Utils.Position.viewport(window);
        _mylightbox_bg.style.width =Utils.Position.f_clientWidth()+ 'px';
        _mylightbox_bg.style.height = Utils.Position.f_clientHeight() + 'px';
        _mylightbox_bg.style.display = '';
        _mylightbox.style.display = '';
        _iframe.src = iframe;
        _iframe.style.height = _height + 'px';

        /*
        var _xy_scroll = Utils.Position.scrollXY(window);
        var _vp = Utils.Position.viewport(window);
        alert(_xy_scroll + ',' + _vp);
        */
    },
    _isCreated: false,
    hide: function() {
        this.lightbox.style.display = 'none';
        this.lightboxBg.style.display = 'none';
    }
    /*
    fullHeight: function() {
        if (window.innerHeight != window.undefined) return window.innerHeight;
        if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight;
        if (document.body) return document.body.clientHeight;
        return window.undefined;
    },
    fullWidth: function() {
        if (window.innerWidth != window.undefined) return window.innerWidth;
        if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth;
        if (document.body) return document.body.clientWidth;
        return window.undefined;
    },
    center: function(width, height) {
        var theBody = document.getElementsByTagName('BODY')[0];
        var scTop = this.scrollTop();
        var scLeft = this.scrollLeft();
        var fullHeight = this.fullHeight();
        var fullWidth = this.fullWidth();
        var _top = scTop + ((fullHeight - (height + 20)) / 2);
        return [
            scLeft + ((fullWidth - width) / 2),
            _top < 0 ? scTop : _top
        ];
    },
    scrollTop: function() {
        if (document.documentElement && document.documentElement.scrollTop) return document.documentElement.scrollTop;
        else return document.body.scrollTop;
    },
    scrollLeft: function() {
        if (document.documentElement && document.documentElement.scrollLeft) return document.documentElement.scrollLeft;
        else return document.body.scrollLeft;
    }
    */
};