Ext.onReady(function(){

	Ext.QuickTips.init();

	var win;
    var button = Ext.get('logare');
	
    button.on('click', function(e){
		e.preventDefault();
		//return false;
        // create the window on the first click and reuse on subsequent clicks
        if(!win){
            win = new Ext.Window({
                //el:'hello-win',
                layout:'fit',
				modal: true,
                width:400,
                height:180,
                closeAction: 'hide',
                plain: true,
				closable: false,
                items: new Ext.FormPanel({
					id: 'login-form',
			        labelWidth: 110, // label settings here cascade unless overridden
			        url:'save-form.php',
			        frame: true,
					title: 'Formular de logare',
			        bodyStyle:'padding:5px 5px 0',
			        width: 330,
			        defaults: {width: 190},
			        defaultType: 'textfield',
					items: [{
			                fieldLabel: 'Nume utilizator',
							inputType: 'text',
			                name: 'data[User][username]',
			                allowBlank:false
			            },{
			                name: 'data[User][password]',
							inputType: 'password',
			                fieldLabel: 'Parola',
							allowBlank: false
			            }
					],
					
					buttons: [{
	                    text:'Intra!',
	                    disabled: false,
						scope: this,
						handler: submit
	                },{
	                    text: 'Inchide',
	                    handler: function(){
	                        win.hide();
	                    }
	                }]
			    })	
            });
		}
		
		function submit() {
			//console.dir(Ext.getCmp('login-form').getForm());
			Ext.getCmp('login-form').getForm().submit({
				url:'/users/login.json',
				waitMsg:'Autentificare in curs...',
				reset: true,
				success: function() { window.location = '/'; },
				failure: function() { Ext.DomHelper.append(error, '<span style="color: #ff0000; font-size:12px;">Utilizator/parola invalide!</span>', true)}
			});
		}
		
		win.show(this);
	});
	
	// newsletter tribute
	
	// Define global variable NATHANSMITHsearchText for portability
	// Used name in all-caps as pseudo-namespace to avoid collision
	window.newsletterText = 'Adresa ta de e-mail';

	// Add instructional text to the search field
	if(Ext.get('box_input')) {
		//console.info(Ext.get('box_input'));
		Ext.get('box_input').set({value: newsletterText});

		// Clear search field when focused
		Ext.get('box_input').on("focus", function(){
			if (Ext.get('box_input').getValue() === newsletterText)
			{
				Ext.get('box_input').set({value: ''});
			}
		}, this);

		// Replace phrase if search unused
		Ext.get('box_input').on("blur", function(){
			if (Ext.get('box_input').getValue() === '')
			{
				Ext.get('box_input').set({value: newsletterText});
			}
		}, this);
	}
	
	Shadowbox.init();
	
	/*
    var flash_els = [
        document.getElementById('flash1'),
        document.getElementById('flash2'),
        document.getElementById('flash3')
    ];

    Shadowbox.setup(flash_els, {
        gallery:        'Flash',
        continuous:     true,
        counterType:    'skip'
    });
	*/
});