
var ajaxLogin = {
	json : new JsonRequest(),
	html : new HtmlRequest(),
	popup : new PopupMaker(function(d){ ajaxLogin.hijack(d); }, [300,150], 'fadeLayer'),
	dd : new DragDrop(),


	showForm : function(callback){
		var that = this;
		if (!this.popup.template){
			this.html.makeRequest('templates/popup/login.tpl', 0, function(template){
				that.popup.template = template;
				that.showForm(callback);
			});
			return false;
		}
		
		if (callback)
			this.onLogin = callback;
		
		this.popup.build({});
		
	},
	
	hijack : function(div){
		var that = this;
		base2.DOM.bind(div);
		this.dd.addElements(div);
		div.querySelector('form').addEventListener('submit', function(e){
			if (!formCheck.check(this, 0, [0,10]))
				return killEvent(e);
			else {
				return !actions.submitForm(this, function(data){
					if (data.response && data.response.type == 'pos'){
						that.popup.destroy();
						if (that.onLogin){
							that.onLogin(data);
							that.onLogin = null;
						}
					}
				}) || killEvent(e);
			}
		}, 1);
	},

	login : function(u, p){
		ajaxLogin.json.makeRequest(this.url, 'username=' + u + '&password=' + p);
	}/*,


	callback : function(data){
		//console.log(data);
		if (data.login){
			this.mbox.showMessage(data.message, 'pos', 5);
			// this.successCallback(data);
			alert(this.onLogin);
		}
		else {
			this.mbox.showMessage(data.message, 'neg', 5);
		}
	}
	*/
};
