var loginmoved = false;
var logindiv = false;
var _loginlink;
var loginclicked = false;

function movelogin(there)
{
	if (loginmoved) return;
	logindiv = document.getElementById('login_hidden_div');
	move_el_to_el(logindiv,there,{x:-170,y:20});
	loginmoved = true;
	_loginlink = there;
	logindiv.onclick = function () { loginclicked = true; }
}

var login_shown=false;

function show_hide_login(there)
{
	movelogin(there);
	if (login_shown)
	{
		there.innerHTML = 'Είσοδος <small>▼</small>';
		logindiv.style.display = "none";
		login_shown = false;
	}
	else
	{
		there.innerHTML = 'Είσοδος <small>▲</small>';
		logindiv.style.display = "block";
		login_shown = true;
	}
	loginclicked = true;
}

var accountdiv=false;
var accountmoved=false;
var accountlink = false;
var accountclicked = false;

function moveaccount(there)
{
	if (accountmoved) return;
	accountdiv = document.getElementById('hidden_account');
	move_el_to_el(accountdiv,there,{x:-150,y:15});
	accountmoved = true;
	accountlink = there;
	accountdiv.onclick = function () { accountclicked = true; }
}

var account_shown = false;

var height;
var heighttoget = 0;
var addition = 20;
var interval=20;
function slide_down()
{
	heighttoget = accountdiv.offsetHeight;
	accountdiv.style.height="0px";
	height = 0;
	setTimeout("add_height()",interval)
}

function add_height()
{
	height += addition;
	if (height>heighttoget)
	{
		height = heighttoget;
	}
	else
	{
		setTimeout("add_height()",interval)
	}
	accountdiv.style.height = height+"px";
}

function show_hide_account(there)
{
	moveaccount(there);
	if (account_shown)
	{
		there.innerHTML = '▼';
		change_back_colors();
		accountdiv.style.display = "none";
		account_shown = false;
	}
	else
	{
		there.innerHTML = '▲';
		change_colors();
		accountdiv.style.display = "inline";
		account_shown = true;
		slide_down();
	}
	accountclicked = true;
}

function change_colors()
{
	document.getElementById('acc_li').style.background = "#b1ca35";
	document.getElementById('arr_li').style.background = "#b1ca35";
}

function change_back_colors()
{
	document.getElementById('acc_li').style.background = "";
	document.getElementById('arr_li').style.background = "";
}

function hide_divs()
{
	if (login_shown && loginclicked==false) show_hide_login(_loginlink);
	loginclicked=false;
	if (account_shown && accountclicked==false) show_hide_account(accountlink);
	accountclicked=false;
}


// Slide down/up anything

function toggle_up_down(id,interval,step,to,callbackup,callbackdown)
{
	var el = document.getElementById(id);
	var h = parseInt(el.style.height);
	if (isNaN(h) || h<=0)
	{
		slide_down_id(id,interval,step,to);
		callbackdown(id);
	}
	else
	{
		slide_up_id(id,interval,step);
		callbackup(id);
	}
}

function slide_up_id(id,interval,subtraction)
{
	setTimeout("subtract_height_id('"+id+"',"+interval+","+subtraction+")",interval)
}

function subtract_height_id(id,interval,subtraction)
{
	var el = document.getElementById(id);
	var h = parseInt(el.style.height)
	h-=subtraction;
	if (h<=0)
	{
		el.style.height = "0px";
	}
	else
	{
		el.style.height = h+"px";
		setTimeout("subtract_height_id('"+id+"',"+interval+","+subtraction+")",interval)
	}
}

function slide_down_id(id,interval,addition,to)
{
	var el = document.getElementById(id);
	el.style.height="0px";
	setTimeout("add_height_id('"+id+"',"+interval+","+addition+","+to+")",interval)
}

function add_height_id(id,interval,addition,htoget)
{
	var el = document.getElementById(id);
	var h = parseInt(el.style.height)
	h+=addition;
	if (h>=htoget)
	{
		el.style.height = htoget+"px";
	}
	else
	{
		el.style.height = h+"px";
		setTimeout("add_height_id('"+id+"',"+interval+","+addition+","+htoget+")",interval)
	}
}
