if(document.getElementById && document.createElement) {
	function initLogin() {
		createLoginBox('webmail', 'http://webmail.5star.se/?_action=login');
		createLoginBox('controlpanel', 'http://customer.5star.se/action.php?act=log_in');
	}
	
	Event.observe(window, 'load', initLogin, false);
	
	function createLoginBox(id, action) {
		var el = $(id);
		if(!el) {
			return false;
		}
		var links = el.getElementsByTagName('a');
		for(var i = 0; i < links.length; i++) {
			Event.observe(links.item(i), 'click', toggleLogin.bind(el), false);
		}
		
		var loginForm = el.appendChild(document.createElement('form'));
		loginForm.setAttribute('action', action);
		loginForm.setAttribute('method', 'post');
		var box = loginForm.appendChild(document.createElement('div'));
		Element.hide(box);
		box.setAttribute('id', id + '-box');
		box.className = 'login-box';
		var stripes = box.appendChild(document.createElement('div'));
		stripes.className = 'stripes';
		var headline = box.appendChild(document.createElement('h2'));
		var headlineImg = document.createElement('img');
		headlineImg.setAttribute('src', baseURL + 'images/navigation/login/' + id + '/' + language + '.gif');
		headline.appendChild(headlineImg);
		var loginLabel = box.appendChild(document.createElement('label'));
		loginLabel.appendChild(document.createTextNode(t(id + '-login')));
		loginLabel.setAttribute('for', id + '-login');
		var login = document.createElement('input');
		login.setAttribute('type', 'text');
		login.setAttribute('id', id + '-login');
		login.setAttribute('name', 'login');
		box.appendChild(login);
		
		var passwordLabel = box.appendChild(document.createElement('label'));
		passwordLabel.appendChild(document.createTextNode(t(id + '-password')));
		passwordLabel.setAttribute('for', id + '-password');
		var password = document.createElement('input');
		password.setAttribute('type', 'password');
		password.setAttribute('id', id + '-password');
		password.setAttribute('name', 'password');
		box.appendChild(password);
		
		var button = document.createElement('input');
		button.setAttribute('type', 'submit');
		button.setAttribute('value', 'OK');
		button.className = 'login-submit';
		box.appendChild(button);
		stripes = box.appendChild(document.createElement('div'));
		stripes.className = 'stripes';
	}
	
	function toggleLogin(evt) {
		Event.stop(evt);
		var el = $(this.getAttribute('id') + '-box');
		if(el.style.display == 'none') {
			showLoginBox.bind(el)();
		}
		else
		{
			hideLoginBox.bind(el)();
		}
	}
	
	function showLoginBox() {
		Element.hide((this.getAttribute('id') == 'controlpanel-box' ? 'webmail' : 'controlpanel') + '-box');
		Element.show(this);
		/*var inputs = this.getElementsByTagName('input');
		inputs.item(0).focus();*/
		return false;
	}
	
	function hideLoginBox() {
		Element.hide(this);
		return false;
	}
}
