﻿var n = 30;
//var iDirection = 0;	//1=open, -1=close.
var AboutTeaDirection = 0;  //hack.
var MenuDirection = 0;

function expandMenuList(objMenu, nObjHeight)
{
    var obj_id = objMenu.id + "List";
    var obj = document.getElementById(obj_id);
	n = parseInt( parseInt(nObjHeight)/4 );
    
    if(navigator.userAgent.toLowerCase().indexOf("msie") >= 0)
    {
        //obj.style.left = (getLeft(objMenu))+"px";
        obj.style.top = (parseInt(getTopLeft(objMenu).split(',')[0]) + 19) +"px";
        obj.style.left = (parseInt(objMenu.offsetLeft)+111) + "px";
        //obj.style.top = (parseInt(objMenu.offsetTop) + parseInt(objMenu.offsetHeight)) +"px";
    }
    else //if(navigator.userAgent.toLowerCase().indexOf("firefox") >= 0)
    {
        obj.style.left = getLeft(objMenu)+"px";
        obj.style.top = (parseInt(getTopLeft(objMenu).split(',')[0]) + 18) +"px";
    }

    
    //iDirection = 1;
    switch(objMenu.id) //hack
    {
        case "menuAboutTea":
            AboutTeaDirection = 1;
            break;
        case "menuMenu":
            MenuDirection = 1;
            break;
    }
    changeHeight(obj_id, nObjHeight); 
}

function collapseMenuList(obj_id, nObjHeight)
{
	var obj = document.getElementById(obj_id);
	n = parseInt( parseInt(nObjHeight)/4 );
	//iDirection = -1;
    switch(obj_id) //hack
    {
        case "menuAboutTeaList":
            AboutTeaDirection = -1;
            break;
        case "menuMenuList":
            MenuDirection = -1;
            break;
    }


	changeHeight(obj_id, nObjHeight);
}

function changeHeight(obj_id, nObjHeight)
{
    var iDirection = 0;
    switch(obj_id) //hack
    {
        case "menuAboutTeaList":
            iDirection = AboutTeaDirection;
            break;
        case "menuMenuList":
            iDirection = MenuDirection;
            break;
    }
	var obj = document.getElementById(obj_id);
	if(iDirection < 0)
	{
		if( parseInt(obj.style.height)-n > 0)
		{
			obj.style.height = (parseInt(obj.style.height) - n) + "px";
			window.setTimeout("changeHeight('"+obj_id+"',"+nObjHeight+");", 125);
		}
		else
		{
			obj.style.height = "0px";
			obj.style.display = "none";
			return;
		}
	}
	else
	{
		if(obj)
		{
		    obj.style.display = "block";
			if(parseInt(obj.style.height) < nObjHeight)
			{
				obj.style.height = (parseInt(obj.style.height) + n) + "px";
			    window.setTimeout("changeHeight('"+obj_id+"',"+nObjHeight+");", 125);
			}
			else
			{
				obj.style.height = (nObjHeight) + "px";
				return;
			}
		}
	}
}

function getLeft(objMenu)
{
    var obj = objMenu.offsetParent;
    var left = parseInt(objMenu.offsetLeft) + parseInt(obj.offsetLeft);
    while(obj.offsetParent)
    {
        left += parseInt(obj.offsetParent.offsetLeft);
        obj = obj.offsetParent;
    }
    return left;
}
function getTopLeft(objMenu)
{
    var obj = objMenu.offsetParent;
    var top = parseInt(objMenu.offsetTop) + parseInt(obj.offsetTop);
    var left = parseInt(objMenu.offsetLeft) + parseInt(obj.offsetLeft);
    while(obj.offsetParent)
    {
        top += parseInt(obj.offsetParent.offsetTop);
        left += parseInt(obj.offsetParent.offsetLeft);
        obj = obj.offsetParent;
    }
    return top + "," + left;
}