var running = false;
window.addEvent('domready', function()
{
	
	
	if ($('authorize') != null)
    {
        $('authorize').addEvent('click', function(e)
        {
            e.preventDefault();

            if (running != true)
            {
                running = true;

                this.set('morph',
                {
                    duration: 150,
                    transition: 'expo:out'
                })
                .morph(
                {
                    top: -this.getSize().y
                });

                new Request.HTML(
                {
                    url: this.href,
                    onSuccess: function(a,b,html)
                    {
                        var parent = this.getParent().addClass('opened');
                        var login  = parent.getNext()
                        var content = new Element('div.content',
                        {
                            styles:
                            {
                                top: -320
                            },
                            morph:
                            {
                                duration: 200,
                                transition: 'expo:out'
                            },
                            'html': html
                        }).inject(login);
						
                        login.getElement('.close').addEvent('click', function(e)
                        {
                            e.preventDefault();
                            parent.removeClass('opened');
                            login.getElement('.content').destroy();

                            this.set('morph',
                            {
                                duration: 250,
                                transition: 'expo:out'
                            })
                            .morph(
                            {
                                top: 0
                            });

                        }.bind(this))

                        content.morph(
                        {
                            top: 40
                        });

                        running = false;
						
						var complete = function()
						{
							jsValidation = new jsValidationScript();
							jsValidation.init();
						}
						
						new Dialog($('reminderLink'),
						{
							events:
							{
								complete: complete
							}
						});
	
						
                    }
                    .bind(this)
                })
                .get(
                {
                    block: 'login'
                });
            }
        });
    }
});
