var tm = 0;
var dialogHandler = {

    shift_x: null,
    shift_y: null,
    popupWidth: null,
    popupHeight: null,
    windowWidth: null,
    windowHeight: null,
    
    FloatingItem: null,
    OverlayItem: null,
    hasElement: null,
    hasInner: null,
    
    defaultDialogWidth: 581,
    nextFunc: null,
    
    initialize: function()
    {
        bod = document.getElementsByTagName('body')[0];
        overlay = document.createElement('div');
        overlay.id = 'overlay';
        lb = document.createElement('div');
        lb.id = 'Dialog';
        lb.innerHTML = '';
        
        lb.innerHTML = '<div class="dialog-content"><a class="dialog-more" href="/hu/befektetesi-alapok/dialog-expander-szarmaztatott-befektetesi-alap/12">&nbsp;</a>' +
			'<a href="javascript:void(0);" onclick="dialogHandler.deactivate();" class="dialog-close"></a></div>';


        bod.appendChild(overlay);
        bod.appendChild(lb);
        
        dialogHandler.FloatingItem = $('#Dialog');
        dialogHandler.OverlayItem = $('#overlay');
        
		$(dialogHandler.OverlayItem).click( function () {
			dialogHandler.deactivate();
		});
        dialogHandler.hasElement = document.documentElement && document.documentElement.clientWidth;
        dialogHandler.hasInner = typeof(window.innerWidth) == 'number';
        
        dialogHandler.windowHeight = dialogHandler.getPageSize().windowHeight;
        dialogHandler.windowWidth = dialogHandler.getPageSize().windowWidth;
        
        $(window).resize(function()
        {
            dialogHandler.windowHeight = dialogHandler.getPageSize().windowHeight;
            dialogHandler.windowWidth = dialogHandler.getPageSize().windowWidth;
            
            $(dialogHandler.OverlayItem).css({
                height: dialogHandler.getPageSize().pageHeight + 'px',
                width: dialogHandler.getPageSize().pageWidth + 'px'
            });
        });

        dialogHandler.showDialogBox();
    },

    showDialogBox: function()
    {
        
        $(dialogHandler.OverlayItem).css({
            display: 'block',
            height: dialogHandler.getPageSize().pageHeight + 'px',
            width: dialogHandler.getPageSize().pageWidth + 'px',
            backgroundColor: '#0d0d0d',
            opacity: '.4',
            filter: 'alpha(opacity=40)'
        });
        
        $(dialogHandler.FloatingItem).css({
            display: 'block'
        });
        
        dialogHandler.computePositon();
    },
       
    deactivate: function()
    {
        dialogHandler.displayBox('none');
		clearTimeout(tm);
    },
    
    computePositon: function()
    {
        PS = dialogHandler.getPageSize();
        POPS = {
            width: $('#Dialog').outerWidth(),
            height: $('#Dialog').outerHeight()
        };
        
        if (navigator.appVersion.search(/MSIE 6.0/) != -1) 
        {
            dialogHandler.shift_x = dialogHandler.hasInner ? pageXOffset : dialogHandler.hasElement ? document.documentElement.scrollLeft : document.body.scrollLeft;
            dialogHandler.shift_x += ((PS.windowWidth - POPS.width) / 2);
            
            dialogHandler.shift_y = dialogHandler.hasInner ? pageYOffset : dialogHandler.hasElement ? document.documentElement.scrollTop : document.body.scrollTop;
            dialogHandler.shift_y += ((PS.windowHeight - POPS.height) / 2);
        }
        else 
        {
            dialogHandler.shift_x = ((PS.windowWidth - POPS.width) / 2);
            dialogHandler.shift_y = ((PS.windowHeight - POPS.height) / 2);
        }
        
        $(dialogHandler.FloatingItem).css({
            left: dialogHandler.shift_x + 'px',
            top: dialogHandler.shift_y + 'px'
        });

		tm = setTimeout('dialogHandler.computePositon()', 2);
    },
    
    getPageSize: function()
    {
    
        var xScroll, yScroll;
        
        if (window.innerHeight && window.scrollMaxY) 
        {
            xScroll = window.innerWidth + window.scrollMaxX;
            yScroll = window.innerHeight + window.scrollMaxY;
        }
        else if (document.body.scrollHeight > document.body.offsetHeight) 
		{ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		}
		else 
		{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
	
        var windowWidth, windowHeight;
        
        if (self.innerHeight) 
        { // all except Explorer
            if (document.documentElement.clientWidth) 
            {
                windowWidth = document.documentElement.clientWidth;
            }
            else 
            {
                windowWidth = self.innerWidth;
            }
            windowHeight = self.innerHeight;
        }
        else if (document.documentElement && document.documentElement.clientHeight) 
		{ // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		}
		else if (document.body) 
		{ // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
        
        if (yScroll < windowHeight) 
        {
            pageHeight = windowHeight;
        }
        else 
        {
            pageHeight = yScroll;
        }
        
        if (xScroll < windowWidth) 
        {
            pageWidth = xScroll;
        }
        else 
        {
            pageWidth = windowWidth;
        }
        
        return {
            'windowHeight': windowHeight,
            'pageWidth': pageWidth,
            'pageHeight': pageHeight,
            'windowWidth': windowWidth
        };
    },
    
    displayBox: function(display)
    {
        $(dialogHandler.OverlayItem).css('display', display);
        $(dialogHandler.FloatingItem).css('display', display);
    }
};

$(document).ready(function()
{
    dialogHandler.initialize();
});
