﻿var deb = false;
var norHei = -27;
function InitSlide(divOutid,divInid,inTblid,spnId){
    var incomp = document.getElementById(divInid);
    var outcomp = document.getElementById(divOutid);
    var inTbl = document.getElementById(inTblid);
    if(incomp && outcomp && inTbl){
        incomp.style.top = norHei + "px";
        incomp.outcomp = outcomp; 
        if(deb)incomp.spn = document.getElementById(spnId);        
        incomp.onmouseover = function(){
            this.status = "over";
            SlideIn(this.id , 10, 5);
        }
        incomp.onmouseout = function(){
            this.status = "out";
            var key = "out" + Math.random();
            this.expand = key;
            setTimeout("SlideOutStarter('"+ this.id +"', 10, 2,'" + key + "');", 10);
        }
    }
}

function SlideOutStarter(compid, speed, step,key)
{
    var comp = document.getElementById(compid);
    if(comp.expand == key){
        SlideOut(compid, speed, step);
    }
}

function show(ctl){
    if(deb)alert(ctl.innerHTML);
}

function SlideIn(compid, speed, step){    
    var comp = document.getElementById(compid);
    if(comp){
        clearTimeout(comp.timeid);
        if(comp.status == "out") return "";
        comp.expand = "in";
        var minT = - parseFloat(comp.style.height);
        var curT = getNum(comp.style.top) - step;
        if(curT > minT){
            comp.style.top = curT + "px";
            comp.timeid = setTimeout("SlideIn('"+ compid +"',"+ speed +","+ step +");",speed);
        }else{
            comp.style.top = minT + "px";
        }
    }
}

function SlideOut(compid, speed, step){    
    var comp = document.getElementById(compid);
    if(comp){
        clearTimeout(comp.timeid);
        if(comp.status == "over") return "";
        comp.expand = "out";
        var maxT = norHei;
        var curT = getNum(comp.style.top) + step;
        if(curT < maxT){
            comp.style.top = curT + "px";
            comp.timeid = setTimeout("SlideOut('"+ compid +"',"+ speed +","+ step +");",speed);
        }else{
            comp.style.top = maxT + "px";
        }
    }
}

function getNum(st){
    return parseInt(new String(st).replace("px",""));
}

/*function SlideIn(compid, speed, step){
    var comp = document.getElementById(compid);
    if(comp){
        if(!comp.expand){
            comp.minEx = 27;
            comp.maxEx = parseFloat(comp.style.height);
            comp.currEx = comp.minEx;
        }
        comp.expand = "in";
        clearTimeout(comp.timeid);
        if(comp.currEx<comp.maxEx){
            comp.currEx += step;
            comp.style.top = (parseFloat(comp.outcomp.style.height) - comp.currEx) + "px";
            comp.timeid = setTimeout("SlideIn('"+ compid +"',"+ speed +","+ step +");",speed);
        }else{
            comp.currEx = comp.maxEx;
            comp.style.top = (parseFloat(comp.outcomp.style.height) - comp.maxEx) + "px";
        }
    }
}

function SlideOut(compid, speed, step){
    var comp = document.getElementById(compid);
    if(comp){
        if(!comp.expand){
            comp.minEx = 27;
            comp.maxEx = parseFloat(comp.style.height);
            comp.currEx = comp.maxEx;
        }
        comp.expand = "out";
        clearTimeout(comp.timeid);
        if(comp.currEx>comp.minEx){
            comp.currEx -= step;
            comp.style.top = (parseFloat(comp.outcomp.style.height) - comp.currEx) + "px";
            comp.timeid = setTimeout("SlideOut('"+ compid +"',"+ speed +","+ step +");",speed);
        }else{
            comp.currEx = comp.minEx;
            comp.style.top = (parseFloat(comp.outcomp.style.height) - comp.minEx) + "px";
        }
    }
}*/