$(document).ready( function() {
	if (window.location.href.indexOf("#registration") != -1) {
		showRegistrationForm(false);
	}
	if (window.location.href.indexOf("#registrationUpdate") != -1) {
		showRegistrationForm(true);
	}

	try {
		UserAjax.isLogged(userInit);
  } catch(e) {
		return siteLoadingFailed();
	}
  
	if (obj('flash')) {
		UtilAjax.getLid(writeFlash);
	}
	
	$("#header .login FORM INPUT:image").click( function () {
		userLogin(this.parent);
		return false;
	});
	$("#header .logged A.cancel").click( function() {
		UserAjax.logout(showLoginForm)
		return false;
	});
	$("#header .login A.register").click( function() {
		if (showRegistrationForm(false)) {
			return false;
		}
	});
	$("#header .logged A.regupdate").click( function() {
		if (showRegistrationForm(true)) {
			return false;
		}
	});
	$("#registration .close A").click( function() {
		hideRegistrationForm();
		return false;
	});
	$("#registration INPUT:text[name='nick']").keyup( function(e) {
		/*
		var type = getTypeByName(this.name);
		setCounterValues(type, this.value);
		if (!counterWorking) {
			counterWorking = 1;
		*/
		if (this.value.length >= 5) {
			UserAjax.isNickExists(this.value, showNickExists);
		}
		//}
	});
	$("#registration INPUT:text[name='nick']").change( function() {
		if (this.value.length >= 5) {
			UserAjax.isNickExists(this.value, showNickExists);
		}
	});
	$("#registration INPUT:image.reset").click( function() {
		var form = new Form(getForm(this));
		form.reset();
		hideRegistrationError();
		hideRegistrationInfo();
		return false;
	});
	$("#registration .error A").mouseout( function () {
		$("IMG", this)[0].src = '/img/u/ok-error.gif';
	});
	$("#registration .error A").mouseover( function () {
		$("IMG", this)[0].src = '/img/u/ok-error-over.gif';
	});
	$("#registration .error A").click( function () {
		hideRegistrationError();
	});
	$("#registration .info A").mouseout( function () {
		$("IMG", this)[0].src = '/img/u/ok-info.gif';
	});
	$("#registration .info A").mouseover( function () {
		$("IMG", this)[0].src = '/img/u/ok-info-over.gif';
	});
	$("#registration .info A").click( function () {
		hideRegistrationForm();
	});
});