/*
    Popup menu used for cuisebasket page
*/


function setOpacity(obj, value) {
    /*obj.style.opacity = value/10;
    obj.style.filter = 'alpha(opacity=' + value*10 + ')';
    obj.opacity = value*/
}
function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft,curtop];
}


function showSubMenuPopUp( cell ){
    var opacity = 8

    if(cell.timer) clearTimeout(cell.timer)

    if(!cell.div){
        showSubMenuPopUp.cells.push(cell)

        var div = cell.getElementsByTagName("DIV")[0]   
        if (div){
            cell.removeChild(div)      
            document.body.appendChild(div)                  
            cell.div = div
            
            div.onmouseover = function(){
                if(cell.div) clearTimeout(cell.timer)
            }
            div.onmouseout = function(){
                cell.onmouseout()
            }
            setOpacity(div, opacity)
        }
        
        cell.close = function(){
            if(cell.div) cell.div.style.display = 'none'
            cell.className = ""
            setOpacity(cell, 10)
        }
        
        cell.show = function(){
            for(var i=0;i<showSubMenuPopUp.cells.length;i++){
                if(showSubMenuPopUp.cells[i] != cell)
                    showSubMenuPopUp.cells[i].close()
            }
            
            if(cell.div){
                var pos = findPos(cell)
                div.style.left = pos[0] + "px"
                div.style.top = (pos[1] + cell.scrollHeight) + "px"
                sibling = cell.nextSibling
                while(sibling){
                    if(sibling.nodeType == 1) break;
                    sibling = sibling.nextSibling
                }
                if(sibling == null){
                    // get the table width
                    var parent = cell.parentNode
                    while(parent){
                        if(parent.tagName == "TABLE") break;
                        parent = parent.parentNode
                    }
                    div.style.width = (findPos(parent)[0] + parent.scrollWidth - pos[0]) + "px";
                }else{
                    div.style.width = (findPos(sibling)[0] - pos[0]) + "px";
                }
                cell.div.style.display = 'block'
                
            }
            cell.className = "hover"
            setOpacity(cell, opacity)
        }                          
        cell.onmouseout = function(){
            cell.timer = setTimeout(cell.close, 500)                  
        }

    }
    cell.show()
}
showSubMenuPopUp.cells = []

