var intervalSpeed = 3;
var easing = 5;

// add a new function
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}

function toggleIn()
{
	var theForm = document.getElementById("pseudoForm");		
	var formString = theForm.getAttribute("id");
	moveElement(formString, 0, 0, intervalSpeed);
}

var isVisible = false;

// activate faqs on click
function toggleForm()
{
	if (!document.getElementById) return false;
	if (!document.getElementById("pseudoForm")) return false;
	
	var theForm = document.getElementById("pseudoForm");
	var formString = theForm.getAttribute("id");
	theForm.style.display = "block";	
	elemHeight = 90;
	theForm.style.height = "0px";
	
	var anchors = document.getElementsByTagName('a');
	for (var i=0; i<anchors.length; i++)
	{
		if(anchors[i].className.indexOf('openForm') != -1) {
		    anchors[i].onclick = function ()
		    { if (isVisible) { moveElement(formString, 0, 0, intervalSpeed); } else { moveElement(formString, elemHeight, elemHeight, intervalSpeed); } isVisible = !isVisible; }
		}
		
		if(anchors[i].className.indexOf('closeForm') != -1) {
			anchors[i].onclick = function()
			{ moveElement(formString, 0, 0, intervalSpeed); isVisible = false;}
		}
	}
}


// method for animation
function moveElement(elementID, final_y, elementHeight, interval)
{
	if(!document.getElementById) return false;
	if(!document.getElementById(elementID)) return false;
	
	var elem = document.getElementById(elementID);
	if (elem.movement)
	{
		clearTimeout(elem.movement);
	}
	if (!elem.style.height)
	{
		elem.style.height = elementHeight + "px";
	}
	var ypos = parseInt(elem.style.height);
	if (ypos == final_y)
	{
		return true;
	}
	if (ypos < final_y)
	{
		var dist = Math.ceil((final_y - ypos)/easing)
		ypos += dist;
	}
	if (ypos > final_y)
	{
		var dist = Math.ceil((ypos - final_y)/easing)
		ypos -= dist;
	}
	elem.style.height = ypos + "px";
	var repeat = "moveElement('" + elementID + "', " + final_y + ", " + elementHeight + ", " + interval + ")";
	elem.movement = setTimeout(repeat,interval);
}

addLoadEvent(toggleForm);
//addLoadEvent(toggleIn);
