/* ----------- funkce pro ramecek ------------- */
var activeModule=null; /* právě aktivní modul */


var xContainer= document.getElementById('xContainer');

xContainer.innerHTML = 
    '<div id="xFrame">\n'
    +'<img class="xFrameIcon" src="../gfx/icons/expand-lt.png" border="0" width="20" height="20" alt="doleva-nahoru" style="top:0px;left:0px;" onclick="xStick(1)">\n'
    +'<img class="xFrameIcon" src="../gfx/icons/expand-rt.png" border="0" width="20" height="20" alt="doprava-nahoru" style="top:0px;right:0px;" onclick="xStick(2)">\n'
    +'<img class="xFrameIcon" src="../gfx/icons/expand-lb.png" border="0" width="20" height="20" alt="doleva-dolů" style="bottom:0px;left:0px;" onclick="xStick(3)">\n'
    +'<img class="xFrameIcon" src="../gfx/icons/expand-rb.png" border="0" width="20" height="20" alt="doprava-dolů" style="bottom:0px;right:0px;" onclick="xStick(4)">\n'
    +'<img class="xFrameIcon" src="../gfx/icons/close.png" border="0" width="24" height="24" alt="zavřít" style="top:-10px;right:30px;" onclick="xClose()">\n'
    +'<img class="xFrameIcon" src="../gfx/icons/help.png" border="0" width="24" height="24" alt="nápověda" style="top:-10px;right:60px" onclick="xHelp()">\n'
    +'<div id="xContent"></div>\n'
    +'<div id="xHelp" onclick="xHelp();"></div>\n'
    +'</div>\n';
    
/* elementy na ktere se opakovane odkazuje */
var xf = document.getElementById('xFrame');
var xHelpSpace = document.getElementById('xHelp');
var xContent= document.getElementById('xContent');

/* souradnice okna na obrazovce - pro zjisteni pozice mysi nad elementy */
var xX = 0;
var xY = 0;


var xHelpOn = false;

function xHelp() 
    {
    if(xHelpOn)
        { xHelpOn = false; xHelpSpace.innerHTML = ""; xHelpSpace.style.display="none";}
        else
        { xHelpOn = true;
          xHelpSpace.style.display="block";
          if(activeModule.help) {xHelpSpace.innerHTML = activeModule.help; }
        }
    }


function xOpen(module)
    {
    if(activeModule) { xClose(); }
    else
        {
        activeModule = module;
        xHelpOn = true;xHelp(); // schovej help ;]
        xContent.innerHTML = module.content();

        if(!fixedMenu.active) { // první spuštění fixedDivHacku
                    fixedMenu.init();
                    fixedMenu.active = true;
                    xStick(1);
                    }
        module.onShow();
        xShow();
        if(fixedRow) {activeModule.interactionHandler(fixedRow,1);}
        }

    }

function xClose()
    {
    activeModule.onHide();
    xHide();
    activeModule = null;
    xContent.innerHTML = "-";
    }


function xHide()
        {xf.style.display = "none";}
         

function xShow()
        {xf.style.display = "block";}


// prilepeni okna k okrajum obrazovky
function xStick(position)              
    {
    var h = (xf.offsetHeight+10).toString(); 
    var w = (xf.offsetWidth+10).toString();
    switch(position)
        {
        case 1:
            if (fixedMenu.menu.style.position=='fixed')
            {
            fixedMenu.menu.style.left='10px';
            fixedMenu.menu.style.top='10px';
            fixedMenu.menu.style.right='';
            fixedMenu.menu.style.bottom='';
            }
            else
            {
            fixedMenu.targetLeft=10;
            fixedMenu.targetTop=10;
            fixedMenu.targetRight='';
            fixedMenu.targetBottom='';
            }
            break;

        case 2:
            if (fixedMenu.menu.style.position=='fixed')
            {
            fixedMenu.menu.style.left='';
            fixedMenu.menu.style.top='10px';
            fixedMenu.menu.style.right=w+'px';
            fixedMenu.menu.style.bottom='';
            }
            else
            {
            fixedMenu.targetLeft='';
            fixedMenu.targetTop=10;
            fixedMenu.targetRight=w;
            fixedMenu.targetBottom='';
            }
            break;

        case 3:
            if (fixedMenu.menu.style.position=='fixed')
            {
            fixedMenu.menu.style.left='10px';
            fixedMenu.menu.style.top='';
            fixedMenu.menu.style.right='';
            fixedMenu.menu.style.bottom=h+'px';
            }
            else
            {
            fixedMenu.targetLeft=10;
            fixedMenu.targetTop='';
            fixedMenu.targetRight='';
            fixedMenu.targetBottom=h;
            }
            break;

        case 4:
            if (fixedMenu.menu.style.position=='fixed')
            {
            fixedMenu.menu.style.left='';
            fixedMenu.menu.style.top='';
            fixedMenu.menu.style.right=w+'px';
            fixedMenu.menu.style.bottom=h+'px';
            }
            else
            {
            fixedMenu.targetLeft='';
            fixedMenu.targetTop='';
            fixedMenu.targetRight=w;
            fixedMenu.targetBottom=h;
            }
            break;
        }
    }
    
    
    
    
/* ******************************** FIXED MENU **************************** */    
/* Script by: www.jtricks.com
 * Version: 20071127
 * Latest version:
 * www.jtricks.com/javascript/navigation/fixed_menu.html
 */
fixedMenuId = 'xContainer';

var fixedMenu = 
{
    active:false, // M.i.X!!!!
    
    hasInner: typeof(window.innerWidth) == 'number',
    hasElement: document.documentElement != null
       && document.documentElement.clientWidth,

    menu: document.getElementById
        ? document.getElementById(fixedMenuId)
        : document.all
          ? document.all[fixedMenuId]
          : document.layers[fixedMenuId]
};

fixedMenu.computeShifts = function()
{
    fixedMenu.shiftX = fixedMenu.hasInner
        ? pageXOffset
        : fixedMenu.hasElement
          ? document.documentElement.scrollLeft
          : document.body.scrollLeft;
    if (fixedMenu.targetLeft > 0)
        fixedMenu.shiftX += fixedMenu.targetLeft;
    else
    {
        fixedMenu.shiftX += 
            (fixedMenu.hasElement
              ? document.documentElement.clientWidth
              : fixedMenu.hasInner
                ? window.innerWidth - 20
                : document.body.clientWidth)
            - fixedMenu.targetRight
            - fixedMenu.menu.offsetWidth;
    }

    fixedMenu.shiftY = fixedMenu.hasInner
        ? pageYOffset
        : fixedMenu.hasElement
          ? document.documentElement.scrollTop
          : document.body.scrollTop;
    if (fixedMenu.targetTop > 0)
        fixedMenu.shiftY += fixedMenu.targetTop;
    else
    {
        fixedMenu.shiftY += 
            (fixedMenu.hasElement
            ? document.documentElement.clientHeight
            : fixedMenu.hasInner
              ? window.innerHeight - 20
              : document.body.clientHeight)
            - fixedMenu.targetBottom
            - fixedMenu.menu.offsetHeight;
    }
};

fixedMenu.moveMenu = function()
{
    fixedMenu.computeShifts();

    if (fixedMenu.currentX != fixedMenu.shiftX
        || fixedMenu.currentY != fixedMenu.shiftY)
    {
        fixedMenu.currentX = fixedMenu.shiftX;
        fixedMenu.currentY = fixedMenu.shiftY;

        if (document.layers)
        {
            fixedMenu.menu.left = fixedMenu.currentX;
            fixedMenu.menu.top = fixedMenu.currentY;
        }
        else
        {
            fixedMenu.menu.style.left = fixedMenu.currentX + 'px';
            fixedMenu.menu.style.top = fixedMenu.currentY + 'px';
        }
    }

    fixedMenu.menu.style.right = '';
    fixedMenu.menu.style.bottom = '';
};

fixedMenu.floatMenu = function()
{
    fixedMenu.moveMenu();
    setTimeout('fixedMenu.floatMenu()', 20);
};

// addEvent designed by Aaron Moore
fixedMenu.addEvent = function(element, listener, handler)
{
    if(typeof element[listener] != 'function' || 
       typeof element[listener + '_num'] == 'undefined')
    {
        element[listener + '_num'] = 0;
        if (typeof element[listener] == 'function')
        {
            element[listener + 0] = element[listener];
            element[listener + '_num']++;
        }
        element[listener] = function(e)
        {
            var r = true;
            e = (e) ? e : window.event;
            for(var i = 0; i < element[listener + '_num']; i++)
                if(element[listener + i](e) === false)
                    r = false;
            return r;
        }
    }

    //if handler is not already stored, assign it
    for(var i = 0; i < element[listener + '_num']; i++)
        if(element[listener + i] == handler)
            return;
    element[listener + element[listener + '_num']] = handler;
    element[listener + '_num']++;
};

fixedMenu.supportsFixed = function()
{
    var testDiv = document.createElement("div");
    testDiv.id = "testingPositionFixed";
    testDiv.style.position = "fixed";
    testDiv.style.top = "0px";
    testDiv.style.right = "0px";
    document.body.appendChild(testDiv);
    var offset = 1;
    if (typeof testDiv.offsetTop == "number"
        && testDiv.offsetTop != null 
        && testDiv.offsetTop != "undefined")
    {
        offset = parseInt(testDiv.offsetTop);
    }
    if (offset == 0)
    {
        return true;
    }

    return false;
};

fixedMenu.init = function()
{
    if (fixedMenu.supportsFixed())
        fixedMenu.menu.style.position = "fixed";
    else
    {
        var ob = 
            document.layers 
            ? fixedMenu.menu 
            : fixedMenu.menu.style;

        fixedMenu.targetLeft = parseInt(ob.left);
        fixedMenu.targetTop = parseInt(ob.top);
        fixedMenu.targetRight = parseInt(ob.right);
        fixedMenu.targetBottom = parseInt(ob.bottom);

        if (document.layers)
        {
            menu.left = 0;
            menu.top = 0;
        }
        fixedMenu.addEvent(window, 'onscroll', fixedMenu.moveMenu);
        fixedMenu.floatMenu();
    }
};


