
var gallery = true;
speed= 10;
pas=10;
ie6 = 0;


function positionSubMenus() {
    
        
    var divs= document.getElementsByTagName('div');
    var elt;
    var i;

    for(i=0;i<divs.length;i++) {
        elt=divs.item(i);
        if(elt.className=='sub-menu-box') {
            elt.style.left="0px";
                        elt.style.top="-200px";
                        elt.style.display="none";
        }

                if(elt.className=='visibility-menu-box') {
                    elt.style.position= "absolute";
                    elt.style.top="14px";
                }    
    }
}

function positionIE6() {
    
    var footer= document.getElementById('footer-background');
    footer.style.bottom= "0px";
    
}

function showSubMenu(menu) {

    
    var sub_menu= menu.getElementsByTagName('div')[1];
        if(sub_menu) {
            sub_menu.style.display="block"; 
            if(sub_menu.style.top=="-200px") sub_menu.style.top=-sub_menu.offsetHeight+"px";

            if(sub_menu.interval) clearInterval(sub_menu.interval);

            sub_menu.interval= setInterval(function () { move(sub_menu); },speed);
            if(!sub_menu.pas) {
                    if(document.all) sub_menu.pas=Math.floor(Math.pow(sub_menu.offsetHeight,1.3)/Math.pow(40,1.3));
                    else sub_menu.pas=Math.floor(Math.pow(sub_menu.offsetHeight,1.3)/Math.pow(15,1.3));
            }
            if(sub_menu.pas==0) sub_menu.pas=1;
            

            if(menu.className=="cache-select" && ie6) {
                    var divSearch = document.getElementById('search');
                    divSearch.style.visibility="hidden";
            }
    }
}

function hideSubMenu(menu) {

    var sub_menu= menu.getElementsByTagName('div')[1];
    if(sub_menu){
        if(sub_menu.interval) clearInterval(sub_menu.interval);
        sub_menu.interval= setInterval(function () { moveBack(sub_menu); },speed);
        if(menu.className=="cache-select" && ie6) {
                    var divSearch = document.getElementById('search');
                    divSearch.style.visibility="visible";
        }
    }

}

function move(sub_menu) {

    var top = parseInt(sub_menu.style.top);
    top+=sub_menu.pas;
    if(top>=0) {
        clearInterval(sub_menu.interval);
        top=0;
    }
   
    sub_menu.style.top=top+"px";
}

function moveBack(sub_menu) {
    var top=parseInt(sub_menu.style.top);
    top-=sub_menu.pas;
    if(top<=-sub_menu.offsetHeight) {
        clearInterval(sub_menu.interval);
        top=-sub_menu.offsetHeight;
        sub_menu.style.display="none";

    }
    
    
    sub_menu.style.top=top+"px";

}

function setHover() {

    var i;
    var j;
    var divs = document.getElementsByTagName('div');
    var elt;
    for(i=0;i<divs.length;i++) {
    
        elt= divs.item(i);
        if(elt.className=="menu-box" || elt.className=="cache-select" ) {
            elt.onmouseover = function() { showSubMenu(this); }
            elt.onmouseout = function() { hideSubMenu(this); }
        }
        
    }
}

function begin() {

    positionSubMenus();
    setHover();
    positionIE6();
    rotate();
//    if(gallery) {
//        selectFolder(0);
//        setAuto();
//    }

}


window.onload = begin;

window.onunload = function() { clearTimeout(image_interval); clearInterval(image_interval); }

