function PopupWindow(title, css) {
    var oThis = this;
    
    this.html = new String();
    this.win = null;
    this.main_cont = null;
    this.msg_cont = null;
    this.buttons_cont = null;
    this.getContent = null;
    this.getButtons = null;
    this.position_type = 'center';
    this.timeOut = null,
    this.wait_image = null;
    
    this.setContentFunction = function (getContent) {
        this.getContent = getContent;
    }
    
    this.setButtonFunction = function (getButtons) {
        this.getButtons = getButtons;
    }
    
    this.removeButtons = function () {
        this.buttons_cont.innerHTML = '';
    }
    
    this.addButton = function (button) {
        this.buttons_cont.appendChild(button.get());
    }
    
    this.init = function () {
        this.win = document.createElement('div'); // Samo za pozicionirane
        this.main_cont = document.createElement('div');
        this.msg_cont = document.createElement('div');
        this.buttons_cont = document.createElement('div')
        
        var wraper = document.createElement('div'),
            title_h = document.createElement('h2'),
            cont = document.createElement('div'),
            body = document.createElement('div'),
            clear = document.createElement('div');
        
        if(title != '') {
            title_h.appendChild(document.createTextNode(title));
            this.main_cont.appendChild(title_h);
        }
        
        body.className = 'dialog-body';
        body.appendChild(this.getContent());
        
        this.msg_cont.className = 'messages';
        this.msg_cont.style.display = 'none';
        this.msg_cont.appendChild(document.createElement('p'));
        body.appendChild(this.msg_cont);
        
        clear.className = 'clear';
        var buttons = this.getButtons();
        for(var i=buttons.length-1; i>=0; i--) {
            this.buttons_cont.appendChild(buttons[i].get());
        }
        this.buttons_cont.appendChild(clear);
        this.buttons_cont.className = 'dialog-buttons';
        
        
        this.main_cont.className = 'dialog-win';
        
        cont.className = 'dialog-content';
        cont.appendChild(body);
        cont.appendChild(this.buttons_cont);
        
        
        this.main_cont.appendChild(cont);
        
        wraper.className = 'dialog-wrap';
        wraper.appendChild(this.main_cont);
        
        this.win.className = css;
        this.win.appendChild(wraper);
    }
    
    this.showWait = function() {
        if (!this.wait_image) {
            this.wait_image = document.createElement('span');
            this.wait_image.className = 'dialog-wait-small';
            
            this.buttons_cont.insertBefore(this.wait_image, this.buttons_cont.lastChild);
        } else {
            show(this.wait_image);
        }
    }
    
    this.hideWait = function() {
        if (this.wait_image) {
            hide(this.wait_image);
        }
    }
    
    this.showError = function (msg) {
        show(this.msg_cont);
        setOpacity(this.msg_cont, 100);
        
        this.msg_cont.firstChild.innerHTML = msg;
        this.msg_cont.firstChild.className = 'error';
        
    }
    
    this.showMessage = function (msg) {
        show(this.msg_cont);
        setOpacity(this.msg_cont, 100);
        
        this.msg_cont.firstChild.innerHTML = msg;
        this.msg_cont.firstChild.className = 'message';
        setTimeout(function () {fadeOut(oThis.msg_cont, 100);}, 4000);
    }
    
    this.display = function (parent_cont, content_f, buttons_f, position) {
        
        this.setContentFunction( content_f );
        this.setButtonFunction( buttons_f );
        
        this.init();
        this.show();
        parent_cont.appendChild(this.get());
        this.position(position);
    }
    
    this.show = function () {
        this.win.style.display = 'block';
        window.onscroll = function () {oThis.move()};
    }
    
    this.hide = function () {
        window.onscroll = null;
        this.win.parentNode.removeChild(this.win);
        this.win.style.display = 'none';
        
        return true;
    }
    
    this.move = function () {
        var scroll = getScrollXY(),
            win_size = windowSize(),
            to_pos = (scroll.y + (win_size.height - oThis.main_cont.clientHeight) / 3);
        
        oThis.win.style.top = to_pos + 'px';
    }
    
    this.position = function (type) {
        var scroll = getScrollXY(),
            win_size = windowSize();
        
        this.position_type = type;
        switch (type) {
            default: case 'center':
                this.win.style.top = (scroll.y + (win_size.height - this.main_cont.clientHeight) / 3 ) + 'px';
                
            break;
        }
    }
    
    this.get = function () {
        return this.win;
    }
}