Ext.onReady(function() {

	// solve the z-index weird problem
	Ext.query('h1 a')[0].style.zIndex = 9999;

	
	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 : 160,
				closeAction : 'hide',
				plain : true,
				closable : false,
				items : new Ext.FormPanel({
					id : 'login-form',
					labelWidth : 105,
					url : 'save-form.php',
					frame : true,
					title : 'Login Form',
					bodyStyle : 'padding:5px 5px 0',
					width : 310,
					defaults : {
						width: 190
					},
					defaultType : 'textfield',

					items : [{
						fieldLabel : 'Username',
						name : 'data[User][username]',
						allowBlank : false
					}, {
						fieldLabel : 'Password',
						name : 'data[User][password]',
						inputType : 'password',
						allowBlank : false
					}],

					buttons : [{
						text : 'Login!',
						disabled : false,
						scope : this,
						handler : submit
					}, {
						text : 'Close',
						handler : function() {
							win.hide();
						}
					}]
				})
			});
		}

		function submit() {

			Ext.getCmp('login-form').getForm().submit({
				url : '/users/login.json',
				waitMsg : 'Please wait...',
				reset : true,
				success : function() {
					window.location = '/';
				},
				failure : function() {
					Ext.DomHelper.append(error, '<span style="color: #ff0000; font-size:12px;">Username/password invalid!</span>', true);
				}
			});
		}

		win.show(this);
	});

	/*

	var shadow = Ext.get('carousel');
	if (shadow != null) {

		var options = {
			loadingImage : '/img/loading.gif',
			resizeLgImages : true,
			displayNav : true,
			handleUnsupported : 'remove',
			flvPlayer : '/swf/flvplayer.swf',
			continuous : true,
			keysClose : ['c', 27], // c or esc
			text : {
				of : 'din',
				loading : 'Incarcare',
				cancel : 'Anuleaza',
				close : 'Inchide',
				next : 'Urmatoarea',
				prev : 'Precedenta'
			}
		};

		Shadowbox.init(options);

	}
	*/

	/*
	var flash_els = [
	document.getElementById('flash1'),
	document.getElementById('flash2'),
	document.getElementById('flash3')
	];

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