/*

Fabio_P 

here some js func to populate and
apply simple effects to the Category Tree menu.

*/

// to remove , not more used
function pboxinit(){
    $('pbox').onmouseout = doBlindUp
    var ar_domain = String(document.location).split('/')    
    new Ajax.Request(ar_domain[0]+'//'+ar_domain[2]+'/getTreeCategories.html',{
	method:'get',
	onSuccess: function(response){$('pbox').innerHTML = response.responseText}
    })
    
}

function doBlindUp(e){
var pbox = $('pbox')
if (!e) var e = window.event;
    var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
    while (reltg.tagName != 'BODY'){
        if (reltg.id == pbox.id)
            return
        reltg = reltg.parentNode;
    }
    pbox.style.display='none'
}

function doBlindDown(pboxid,blindTo){  

    // attach doBlinbdUp on mouseout
    if ($(pboxid).addEventListener)
        $(pboxid).addEventListener("mouseout", doBlindUp, false);
    else if ($(pboxid).attachEvent)
        $(pboxid).attachEvent("onmouseout", doBlindUp);

    // set the correct left position 
    $(pboxid).style.left = $('Tabella_01').offsetLeft+'px'
    
    var mgk = new MagicBox(pboxid)
    mgk.maxHeight = blindTo
    mgk.BlindDown()
}


MagicBox = function (objid)
{
    this._init (objid);
}
MagicBox.prototype._init = function (objid)
{
    this.obj = $(objid);
    this.maxHeight = 0
    this.timeOut = 2
    this.step = 20
}
MagicBox.prototype.BlindDown =  function ()
{
    if(this.obj.style.display=='none'){	
	this.obj.style.height='0px'
	this.obj.style.display=''	
	this.stepHeight()
    }
}
MagicBox.prototype.stepHeight =  function ()
{
    var h = parseInt(this.obj.style.height.replace('px',''))
    if(h >= this.maxHeight)
	return
    this.obj.style.height = (h + this.step) + 'px'
    setTimeout((function(){this.stepHeight()}).bind(this),this.timeOut)
}
