FiatPopover = {
    placer: null,
    content: null,
    background: null,
    created: false,
    create: function() {
        var body = document.getElementsByTagName('body')[0];
        
        var placer = document.createElement('div');
        placer.id = 'fiat_placer';
        placer.style.display = 'none';

        var aligner = document.createElement('div');
        aligner.id = 'fiat_aligner';
        
        var background = document.createElement('div');
        background.id = 'fiat_background';
        background.onclick = FiatPopover.hide;

        var content = document.createElement('iframe');
        content.id = 'fiat_content';
        content.frameBorder = 0;
        //content.scrolling = 'no';
        
        var close = document.createElement('a');
        close.className = 'fiat_close';
        close.href = '#';
        close.onclick = FiatPopover.hide;

        body.appendChild(placer);
        body.appendChild(background);
        placer.appendChild(aligner);
        placer.appendChild(close);
        aligner.appendChild(content);
        
        FiatPopover.placer = placer;
        FiatPopover.content = content;
        FiatPopover.background = background;
        
        FiatPopover.placer.style.display = 'block';
        FiatPopover.background.style.height = body.offsetHeight + 'px';
        FiatPopover.placer.style.display = 'none';
        
        FiatPopover.created = true;
    },
    show: function(url) {
        FiatPopover.hideSelects();
        if(!FiatPopover.created) {
            FiatPopover.create();
        }
        FiatPopover.placer.style.display = 'block';
        FiatPopover.background.style.display = 'block';
        FiatPopover.content.src='/fiatpunto/formulier.html';
        document.getElementById('ad_placer').style.visibility = 'hidden';
        window.scrollTo(0,0);
        var image = document.createElement('img');
        image.src = url;
        document.getElementsByTagName('body')[0].appendChild(image);
    },
    hide: function() {
        FiatPopover.placer.style.display = 'none';
        FiatPopover.background.style.display = 'none';
        FiatPopover.showSelects();
        document.getElementById('ad_placer').style.visibility = 'visible';
        return false;
    },
    hideSelects: function() {
        var body = document.getElementsByTagName('body')[0];
        var className = body.className || '';
        var classNameParts = className.split(' ');
        classNameParts[classNameParts.length] = 'fiathideselects';
        body.className = classNameParts.join(' ');
    },
    showSelects: function() {
        var body = document.getElementsByTagName('body')[0];
        var className = body.className || '';
        var oldClassNameParts = className.split(' ');
        var newClassNameParts = new Array();
        for (var i = 1; i < oldClassNameParts.length; i++) {
            if (oldClassNameParts[i] != 'fiathideselects') {
                newClassNameParts[newClassNameParts.length] = oldClassNameParts[i];
            }
        }
        body.className = newClassNameParts.join(' ');
    }
}        
