var _oCurrentClosePanel = null;
var iRepeat = 25;
var iDirection = 0;
var iMove;
var _oHidePanelDropdownBoxes = null;


//window.setTimeout("SetClientHeight(document.all['q'])", 1000, 'javascript');

function SetClientHeight(oControl)
{
	
	oControl.parentElement.parentElement.style.height = parseInt(oControl.parentElement.clientHeight);
}

function CloseCurrentPanel()
{
	if (iDirection == 0)
	{
		if (_oCurrentClosePanel != null)
		{
			OpenClosePanel(_oCurrentClosePanel, _oHidePanelDropdownBoxes);
		}
	}
}

function OpenClosePanel(oControl, oHidePanelDropdownBoxes)
{	
	if (iDirection == 0)
	{
		_oCurrentClosePanel = oControl;
		
		if (parseInt(oControl.style.top) == 0)
		{
			iDirection = -1;
			//oControl.style.top = oControl.parentElement.clientHeight * -1;
			//oControl.parentElement.parentElement.style.height = 0;
			_oHidePanelDropdownBoxes = oHidePanelDropdownBoxes;
		}
		else
		{
			iDirection = 1;
			//oControl.style.top = 0;
			//oControl.parentElement.parentElement.style.height = oControl.parentElement.clientHeight;
			_oHidePanelDropdownBoxes = oHidePanelDropdownBoxes;
			if (oHidePanelDropdownBoxes != null)
			{
				HideShowDropDownBoxes(oHidePanelDropdownBoxes);
			}
		}
		
				
		//oControl.style.top = GetStep(parseInt(oControl.parentElement.clientHeight)) * iDirection;
		
		//oControl.parentElement.parentElement.style.height = parseInt(oControl.parentElement.clientHeight) - GetStep(parseInt(oControl.parentElement.clientHeight));
		var i = Math.abs(parseInt(oControl.style.top));
		
		if (iDirection == -1)
		{
			iMove = GetMoveValue(Math.abs(parseInt(oControl.parentElement.clientHeight) - i)) + 1;
		}
		else
		{
			iMove = GetMoveValue(Math.abs(parseInt(oControl.parentElement.clientHeight))) + 1;	
		}
		var iMul = (((Math.pow(iMove-1, 2) + iMove-1) / 2) * iDirection);
		
		if (iDirection == -1)
		{
			oControl.style.top = (parseInt(oControl.parentElement.clientHeight) + iMul) * iDirection;
			
			oControl.parentElement.parentElement.style.height = Math.abs(iMul);
		}
		else
		{
			oControl.style.top = (parseInt(oControl.parentElement.clientHeight) - (parseInt(oControl.parentElement.clientHeight) - iMul) )* -1;
			
			oControl.parentElement.parentElement.style.height = (parseInt(oControl.parentElement.clientHeight) - iMul) ;
			
		}
		iMove = iMove - 1;
		
		window.setTimeout("ClosePanel_Loop(true)", iRepeat, "JavaScript");
		
	}
	
}

function ClosePanel_Loop(bForce)
{
	var oControl = _oCurrentClosePanel;
	
	if (bForce | (parseInt(oControl.style.top) != 0) & (parseInt(oControl.style.top) != -1 * parseInt(oControl.parentElement.clientHeight)))
	{
		oControl.style.top = parseInt(oControl.style.top) + (iMove * iDirection);		
		
		oControl.parentElement.parentElement.style.height = Math.abs(parseInt(oControl.parentElement.parentElement.style.height) + (iMove * iDirection));	
		oControl.parentElement.style.clip = 'rect(0px auto ' + oControl.parentElement.parentElement.style.height + ' auto)';
		
		window.setTimeout("ClosePanel_Loop(false)", iRepeat, "JavaScript");
		iMove = iMove - 1;
		
	}
	else
	{
		if (iDirection == -1)
		{
			if (_oHidePanelDropdownBoxes != null)
			{
				HideShowDropDownBoxes(_oHidePanelDropdownBoxes);
				_oHidePanelDropdownBoxes = null;
			}
			_oCurrentClosePanel = null;
		}
		
		iDirection = 0;	
	}
}

function GetStep(x)
{
	
	var iDiv = Math.floor((Math.sqrt(((8 * x) + 1)) - 1) / 2);
	iDiv = iDiv - 1;
	return ((Math.pow(iDiv, 2) + iDiv)/2);	
}

function GetMoveValue(x)
{
	
	var iDiv = Math.floor((Math.sqrt(((8 * x) + 1)) - 1) / 2);
	return iDiv;
}

function FastCloseCurrentPanel(oPanel)
{
	if (iDirection == 0)
	{
		if (_oCurrentClosePanel != null)
		{
			if (_oCurrentClosePanel != oPanel)
			{
				_oCurrentClosePanel.parentElement.style.clip = 'rect(0px auto 0px auto)';
				_oCurrentClosePanel.style.top = -1;
				HideShowDropDownBoxes(_oHidePanelDropdownBoxes);
				_oHidePanelDropdownBoxes = null;
			}
		}
	}
}

function HideShowDropDownBoxes(oControl)
{
	
	var oControls = oControl.getElementsByTagName("SELECT");
	
	for (i = 0; i < oControls.length; i++)
	{
		var oC = oControls[i];
		
		if (oC.style.visibility == '')
		{
			oC.style.visibility = 'hidden';
		}
		else
		{
			oC.style.visibility = '';
		}
	}
	
}

// old menu:
var menu1top=46;
var menuleft=4;

// This number configures the length and the speed of the menu-movement. 
// Play around with it until you are satisfied.
var pace=31;

// Don't change the variables below.
var step;
var direction;
var pause=25;

var thismenu;
var CurrentDirectionmenu1=1;
var StartDirectionmenu1=1;
var init = 0;


var menuismoving="no";

function gotourl(thisurl) {
    alert("\n\nThis is only a demonstration.\nYou will not be linked to "+thisurl+".html.")
}

function inite() {
	init = 1;
	if (document.layers) {
	
        document.getElementById("menu1").left=menuleft;
        
        document.getElementById("menu1").top=menu1top;
        document.getElementById("menu1").posTop=menu1top;
        
	}	
	if (document.all) {	
        document.getElementById("menu1").style.posLeft=menuleft;
        
        document.getElementById("menu1").style.posTop=menu1top;
        
	}
}

function getmenuname(clickedmenu) {

	if (init == 0) inite();
    if (menuismoving=="no") {
	    if (document.layers) {
            thismenu=eval("document."+clickedmenu)
	    }	
	    if (document.all) {
            thismenu=eval("document.getElementById('"+clickedmenu+"').style")
	    }
	    
        step=pace;
        checkdirection();
	    movemenu();
    }
}

function checkdirection() {
	if (init == 0) inite();
	
	if (document.layers) {    
        if (thismenu==document.getElementById("menu1")){StartDirectionmenu1=StartDirectionmenu1*-1;CurrentDirectionmenu1=StartDirectionmenu1}
        
        
	}	
	
	if (document.all) {
        if (thismenu==document.getElementById("menu1").style){StartDirectionmenu1=StartDirectionmenu1*-1;CurrentDirectionmenu1=StartDirectionmenu1}
        
        
	}
    menuismoving="yes";
}

function movemenu() {

	if (init == 0) inite();
	if (document.layers) {
        if (step>=0) {
            thismenu.top+=step*CurrentDirectionmenu1
            step--
            var movetimer=setTimeout("movemenu()",pause)  
	    }
        else {
            menuismoving="no"
            clearTimeout(movetimer)
        }
	}	   
	
	if (document.all) {
        if (step>=0) {
            thismenu.posTop= thismenu.posTop + step*CurrentDirectionmenu1;
            
            step--
            var movetimer=setTimeout("movemenu()",pause)  
	    }
        else {
            menuismoving="no"
            clearTimeout(movetimer)
        }
    }
}
	
function HideShow(sControl)
{
    oControl = document.getElementById(sControl);
    
    if (oControl.style.display == 'none')
    {
        oControl.style.display = '';
    }
    else
    {
        oControl.style.display = 'none';
    }
}