function MShowAkce() {

    var ximageWidth = 0;
    var ximageHeight = 0;
    var ximageLoaded = false;
    var ximageDrawn = false;
    var bgElm;
    var imageElm;
    var skipElm;

    var windowWidth = 0;
    var windowHeight = 0;
    if (window.innerHeight) {
        windowWidth = window.innerWidth;
        windowHeight = window.innerHeight;
    } else if ((document.documentElement.clientHeight)&&(document.documentElement.clientHeight > 0)) {
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body.clientHeight) {
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    addEvent(window, 'resize', MShowAkceResize);
    addEvent(window, 'scroll', MShowAkceResize);
    InitElements();
    DisplayImage();

    function InitElements() {
        var xbody = document.getElementsByTagName('body')[0];
        bgElm = xCreateElement('div');
        //bgElm.style.width = windowWidth+'px';
        bgElm.style.width = '100%';
        bgElm.style.height = windowHeight+'px';
        bgElm.style.background = '#002866';
        bgElm.style.color = '#000000';
        bgElm.style.position = 'absolute';
        bgElm.style.top = '0px';
        bgElm.style.left = '0px';
        bgElm.style.zIndex = '1000';
        bgElm.style.opacity = 75/100;
        bgElm.style.filter = 'alpha(opacity=75)';
        bgElm.style.display ='block';
        xbody.insertBefore(bgElm,xbody.firstChild);
        imgContainerElm = xCreateElement('div');
        imgContainerElm.style.textAlign = 'center';
        imgContainerElm.style.fontSize = '0.9em';
        imgContainerElm.style.fontWeight = 'normal';
        imgContainerElm.style.fontFamily = '"Arial CE", Arial, "Lucida Grande CE", Lucida, "Helvetica CE", Helvetica, sans-serif';
        imgContainerElm.style.display ='block';
        xbody.insertBefore(imgContainerElm,xbody.firstChild);
        imageElm = xCreateElement('img');
        imageElm.style.cursor='pointer';
        
        imageElm.src='/akce.jpg';
        
        imageElm.style.display='block';
        imageElm.style.position='absolute';
        imageElm.style.zIndex='2500';
        imageElm.style.border='2px solid #FFFFFF';
        imageElm.onload = function() { ImageLoadComplete(this); }
        imageElm.onclick = function() { location.href='/akce.php'; }
        skipElm = xCreateElement('p');
        skipElm.appendChild(document.createTextNode(GetSkipText()));
        skipElm.style.cursor='pointer';
        skipElm.style.background='#FFFFFF';
        skipElm.style.color='#002866';
        skipElm.onclick = function() { location.href='/akce.php'; }
        skipElm.style.zIndex='2500';
        skipElm.style.position='absolute';
        skipElm.style.cursor='pointer';
        skipElm.style.fontWeight='bold';
        skipElm.style.fontSize='1.2em';
        skipElm.style.padding='4px 2px';
        skipElm.style.margin='0';
        skipElm.onclick = function() { Hide(); return false; }
        skipElm.style.textDecoration='underline';
        skipElm.onmouseover = function() { skipElm.style.color='#a61930'; return false;}
        skipElm.onmouseout = function() { skipElm.style.color='#002866'; return false;}
        PositionElements();
        elementsInitialized = true;
    }
    
     function GetSkipText() {
        var result = 'Skip advertisement';
        var xhtml = document.getElementsByTagName('html')[0];
        if (xhtml.attributes.getNamedItem('lang')) {
            if (xhtml.attributes.getNamedItem('lang').nodeValue == 'cs') {
                var result = 'Přeskočit reklamu';
            }
        }
        return result;
    }
    
    function PositionElements() {
        var xtop = GetScrollY();
        bgElm.style.top = xtop+0+'px';
        bgElm.style.width = windowWidth+'px';
        bgElm.style.height = windowHeight+'px';
    }
    
    function DisplayImage() {
        if (elementsInitialized) {
            if (ximageLoaded) {
                DrawImage();
            } else {
                ximageDrawn = false;
                imageLoadTimer = window.setInterval(ImageLoader,200);
            }
        }
    }
    
    function ImageLoadComplete(obj) {
        ximageLoaded = true;
    }
    
    function ImageLoader() {
        if (!ximageDrawn) {
            if (ximageLoaded||imageElm.complete) {
                ximageDrawn = true;
                window.clearInterval(imageLoadTimer);
                DrawImage();
            }
        }
    }
    
    function DrawImage() {
            var winx = windowWidth-16;
            var winy = windowHeight-100;
            if (ximageWidth == 0) {
                ximageWidth = imageElm.width;
                ximageHeight = imageElm.height;
            }
            var imgwidth = ximageWidth;
            var imgheight = ximageHeight;
            var winr = winx/winy;
            var imgr = imgwidth/imgheight;
            if (winr < imgr) {  //land2port
                if (imgwidth > winx) {
                    imgwidth = winx;
                    imgheight = Math.round(ximageHeight*winx/ximageWidth);
                }
            } else { //port2land
                if (imgheight > winy) {
                    imgwidth = Math.round(ximageWidth*winy/ximageHeight);
                    imgheight = winy;
                }
            }
            imageElm.width=imgwidth;
            imageElm.height=imgheight;
            var x = GetScrollX()+Math.round((winx-imgwidth)/2)+6;
            var y = GetScrollY()+Math.round((winy-imgheight)/2)+6;
            imageElm.style.left=x+'px';
            imageElm.style.top=y+'px';
            imgContainerElm.appendChild(imageElm);
            skipElm.style.width = imgwidth+'px';
            skipElm.style.left = x+'px';
            skipElm.style.top = (y+imgheight)+'px';
            imgContainerElm.appendChild(skipElm);
    }
    
    function GetScrollX() {
        var result = 0;
        if ( typeof( window.pageXOffset ) == 'number' ) {
            result = window.pageXOffset;
        } else if ( document.body && document.body.scrollLeft ) {
            result = document.body.scrollLeft;
        } else if( document.documentElement && document.documentElement.scrollLeft ) {
            //IE6 standards compliant mode
            result = document.documentElement.scrollLeft;
        }
        return result;
    }

    function GetScrollY() {
        var result = 0;
        if ( typeof( window.pageYOffset ) == 'number' ) {
            result = window.pageYOffset;
        } else if ( document.body && document.body.scrollTop ) {
            result = document.body.scrollTop;
        } else if( document.documentElement && document.documentElement.scrollTop ) {
            //IE6 standards compliant mode
            result = document.documentElement.scrollTop;
        }
        return result;
    }
    
    function MShowAkceResize() {
        if (window.innerHeight) {
            windowWidth = window.innerWidth;
            windowHeight = window.innerHeight;
        } else if ((document.documentElement.clientHeight)&&(document.documentElement.clientHeight > 0)) {
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        } else if (document.body.clientHeight) {
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
        }
        PositionElements();
        DisplayImage();
    }
    
    function Hide() {
        var xbody = document.getElementsByTagName('body')[0];
        xbody.removeChild(bgElm);
        xbody.removeChild(imgContainerElm);
    }
    
}

function xCreateElement(type) {
    var result = false;
    if (document.createElementNS) {
        result = document.createElementNS('http://www.w3.org/1999/xhtml','html:'+type);
    } else {
        result = document.createElement(type);
    }
    return result;
}

addEvent(window,'load',MShowAkce);