var Login = Class.create (
{
	moving:false,
	visible:false,
	loginLayerId:'loginLayer',
	initialize: function()
	{

	},
	show : function ()
	{
		//basket auto hide 
		if (basket.visible)
		{
			basket.callback = function(){login.show()};
			basket.hide();
			return;
		}
		
		if (this.visible) return;	

		this.visible = true;
		this.moving = true;
		
		if(Prototype.Browser.IE)
		{
			$('menuBasketCount').hide();
		}
		else
		{
			Effect.Fade('menuBasketCount',{ duration: 0.3});
		}

	/*$('basketMenuItem').addClassName('selected');*/
	/*
	//schovanie active-x komponentov v IE6, aby neboli stale zobrazene
	isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
	if (isIE6)
	{
		$$('#product_list_filter select').each(function(e) {e.style.visibility='hidden';});	
	}
	*/
	Effect.SlideDown(this.loginLayerId,{ duration: 0.7, afterFinish: function() {
				  this.moving = false;		
				  basket.callback = function(){};
				  }.bind(this)});
	
	
	},
	hide : function ()
	{
		if (!this.visible) return;
		this.moving = true;
		
		/*$('basketMenuItem').removeClassName('selected');*/
		Effect.SlideUp(this.loginLayerId,{ duration: 0.7, afterFinish: function() {
					  this.visible = false;	
					  this.moving = false;	
					 	if(Prototype.Browser.IE)
						{
							$('menuBasketCount').show();
						}
						else
						{
							Effect.Appear('menuBasketCount',{ duration: 0.2});
						}
						if ($('loginLayer').hasClassName('error')) $('loginLayer').removeClassName("error");
						$('passwordInput').value = '';
						$('usernameInput').value = '';
						 /* //zobrazenie active-x komponentov v IE6, aby neboli stale zobrazene
						  isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
						  if (isIE6)
						  {
								$$('#product_list_filter select').each(function(e) {e.style.visibility='visible';});
						  }*/
					  }.bind(this)});
	
	
	},
	toogle :function ()
	{
		if (!this.moving && !this.visible)
		{
			this.show();
		}
		if (!this.moving && this.visible)
		{
			this.hide();
		}
	},
	submit:function(form)
	{
		var params = form.serialize(true); 		
		ajax("/login", params, "post",  this.onSuccessSubmit.bind(this));
	},
	onSuccessSubmit:function(transport)
	{
		var data = transport.responseJSON; 
		if (data['isLogged'])
		{
			window.location = data['rurl'];

		}
		else
		{
			if (!$('loginLayer').hasClassName('error'))  $('loginLayer').addClassName("error");
			if (!$('productReviewLogin').hasClassName('error'))  $('productReviewLogin').addClassName("error");
			
		}
	
	}
	


	


});

var login;
Event.observe(window, 'load', function() 
	{
		login = new Login();
	}
);