var intervalSpeed = 3;
var easing = 7;

var elemHeight = 0;


// ie doesnt recognize the method indexOf()
function checkIndexOf()
{
	if (!Array.indexOf) 
	{
		Array.prototype.indexOf = function (obj, start) 
		{
			for (var i = (start || 0); i < this.length; i++) 
			{
				if (this[i] == obj)
				{
					return i;
				}	
			}
		}
	}
}

// border for the captcha
function borderCaptcha()
{
	if (!document.getElementById("captcha")) return false;
	var captcha = document.getElementById("captcha");
	var imgs = captcha.getElementsByTagName("img");
	for(var i=0; i<imgs.length; i++)
	{
		imgs[i].style.border = "1px solid #BBB";
	}
}

// set values for heights and answers in arrays
function prepareForm()
{
	if (!document.getElementById) return false;
	var theForm = document.getElementById("pseudo_form");
	var formString = theForm.getAttribute("id");
	elemHeight = theForm.offsetHeight;
	
	moveElement(formString, 0, 0, intervalSpeed);
}

function toggleIn()
{
	var theForm = document.getElementById("pseudo_form");		
	var formString = theForm.getAttribute("id");
	moveElement(formString, 0, 0, intervalSpeed);
}

// activate faqs on click
function toggleForm()
{
	if (!document.getElementById) return false;
	if (!document.getElementById("reageerHead")) return false;
	if (!document.getElementById("pseudo_form")) return false;
	
	var theForm = document.getElementById("pseudo_form");		
	var headerTxt = document.getElementById("reageerHead");
	var formString = theForm.getAttribute("id");
	theForm.style.display = "block";
	
	elemHeight = theForm.offsetHeight;
	theForm.style.height = "0px";
	
	headerTxt.style.cursor = "pointer";
	
	headerTxt.onclick = function()
	{
		if(theForm.style.height == "0px")
		{
			moveElement(formString, elemHeight, elemHeight, intervalSpeed);
		}	
		else 
		{	
			moveElement(formString, 0, 0, intervalSpeed);
		}
	}
}


// 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+", "+interval+")";
	elem.movement = setTimeout(repeat,interval);
}

addLoadEvent(checkIndexOf);
addLoadEvent(toggleForm);
addLoadEvent(borderCaptcha);
addLoadEvent(toggleIn);