var tm = 0;
var dialogHandler = {

    shift_x: null,
    shift_y: null,
    popupWidth: null,
    popupHeight: null,
    windowWidth: null,
    windowHeight: null,
    
    FloatingItem: null,
	
	FloatingItemNormal: null,
	FloatingItemPromo: null,
	FloatingItemEvhonlapja: null,
	
    OverlayItem: null,
    hasElement: null,
    hasInner: null,
    
    defaultDialogWidth: 500,
    nextFunc: null,
    
    initialize: function()
    {
        bod = document.getElementsByTagName('body')[0];
        overlay = document.createElement('div');
        overlay.id = 'overlay';
        lb = document.createElement('div');
        lb.id = 'Dialog';
        
        bod.appendChild(overlay);
        bod.appendChild(lb);
        
		$('#Dialog').html('<div><a href="javascript:void(0);" onclick="dialogHandler.deactivate()" class="closebutton">&nbsp;</a><a href="http://www.azevhonlapja.hu/index.php?option=com_evhonlapja&view=palyazat&palyazatId=3827" target="_blank" class="gobutton1">&nbsp;</a><a href="http://www.azevhonlapja.hu/index.php?option=com_evhonlapja&view=palyazat&palyazatId=3794" target="_blank" class="gobutton2">&nbsp;</a><a href="http://www.baloghekszer.hu" target="_blank" class="godisplay1">&nbsp;</a><a href="http://sales-akademia.hu/" target="_blank" class="godisplay2">&nbsp;</a></div>');
        dialogHandler.FloatingItemEvhonlapja = $('#EvhonlapjaDialog');
		
		
		dialogHandler.FloatingItemNormal = $('#Dialog');
        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'
            });
        });
    },

    showDialogBox: function()
    {
       
        $(dialogHandler.OverlayItem).css({
            display: 'block',
            height: dialogHandler.getPageSize().pageHeight + 'px',
            width: dialogHandler.getPageSize().pageWidth + 'px',
            backgroundColor: '#000000',
            opacity: '.7',
            filter: 'alpha(opacity=70)'
        });
        
        $(dialogHandler.FloatingItem).css('display', 'block');        
        dialogHandler.computePositon();
    },
	

    
    deactivate: function()
    {
        dialogHandler.displayBox('none');
		clearTimeout(tm);
    },
    
    computePositon: function()
    {
        PS = dialogHandler.getPageSize();
        POPS = {
            width: $(dialogHandler.FloatingItem).outerWidth(),
            height: $(dialogHandler.FloatingItem).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;
                }
        
        // for small pages with total height less then height of the viewport
        if (yScroll < windowHeight) 
        {
            pageHeight = windowHeight;
        }
        else 
        {
            pageHeight = yScroll;
        }
        
        
        // for small pages with total width less then width of the viewport
        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();
	
	if (OpenEvhonlapja == true)
	{
		dialogHandler.showDialogBox();	
	}	
});

