function _KepesUser() { 
	$(function() {
		/* _ku_openlink(ek!) megkeresese es belinkelese */
		$('._ku_openlink').click(function() {
			_ku_.showBox();		
			return false;
		});	
		// widget inditasa
		_ku_.callAjax('initwidget',{ dummy: 1});
	});
}
_KepesUser.prototype.site;
_KepesUser.prototype.root;
_KepesUser.prototype.loggedin;
_KepesUser.prototype.size = 1;
_KepesUser.prototype.style = 'default';
_KepesUser.prototype.setSite = function(site) {
	this.site = site;
}
_KepesUser.prototype.setRoot = function(root) {
	this.root = root;
}
_KepesUser.prototype.setLoggedin = function(loggedin) {
	if (!loggedin) this.loggedin = 0;
	else this.loggedin = loggedin;
}
_KepesUser.prototype.setStyle = function(style) {
	this.style = style;
}
_KepesUser.prototype.setSize = function(size) {
	this.size = size;
}
_KepesUser.prototype.showBox = function() {
	var box = document.getElementById('_ku_box');
	box.style.display = "inline";
}
_KepesUser.prototype.hideBox = function() {
	var box = document.getElementById('_ku_box');
	box.style.display = "none";
}
_KepesUser.prototype.callAjax = function(action,params) {
	$.ajax({
    	    url: "http://"+this.root+"/jsonp.php",	
	        crossDomain: true,
    	    dataType: "jsonp",
			type: "POST",
			data: { action: action, params: params, env: { site: this.site, selfurl: encodeURI(window.location.href), 
				size: this.size, loggedin: this.loggedin } 
			},
        	processData: true,
	        success: function(data) {	// amiket varunk: data.cookie (key,value,delete); data.redirect (string:url); data.msg (string:popup string)
				// cookie: always first!
				if (typeof(data._ku_token) != "undefined") {
					var url = location.href;
					url += (url.split('?')[1] ? '&':'?') + '_ku_token=' + data._ku_token;
					location.href = url;
				}
				// widget html second
				if (data.widget != "") $('#_ku_widget').html(data.widget);
				// "popup" third
				if (data.popup != "") $('#_ku_popup').html(data.popup);
				// msg alert first...
				if (data.msg != "") {
					alert(data.msg);
					$('#_ku_msg').text(data.msg);
				}
				// redirect last!
				if (data.redirect != "") {
					if (data.redirect == "self") {
						document.location.reload();
					} else {
						document.location = data.redirect;
					}
				} 
        	}
	});
}

_KepesUser.prototype.login = function() {
	var efi = $('#_ku_email_field').val();
	var pfi = $('#_ku_password_field').val();

	this.callAjax('login',{ email: efi, password: pfi});
}

_KepesUser.prototype.logout = function() {
	this.callAjax('logout',{ dummy: 1 });
}

_KepesUser.prototype.display = function() {
	if ((this.root != 'devel.kepesuser.com')&&(this.root != 'kepesuser.com')) {
		alert('Wrong call to setSite: '+this.root);
		return;
	}

//	var baseurl = 'http://'+this.root;	
//	var url = 'http://'+this.root+'/widget.php?site='+this.site+'&loggedin='+this.loggedin;
//	url = url+'&style='+this.style+'&domain='+window.location.host+'&selfurl=';
//	url = url + encodeURI(window.location.href);

	document.write(
	'<div id="_ku_widget">'+
//	'<div style="display:inline;position:static;">'+
//		'<div>'+
//			'<div style="position:absolute;padding:2px;text-align:center;font-family:arial,helvetica;font-size:14px;font-weight:bold;" id="_ku_widget">'+
//			'...'+
//			'</div>'+
//		'</div>'+
	'</div>');	
}
_KepesUser.prototype.loginToken = function(token) {
	this.token = token;
}
/* Regisztracio, belepes link letrehozasa, atadott szoveg alapjan. */
_KepesUser.prototype.writeLink = function(text) {
	document.write('<a href="#" onClick="javascript:_ku_.signalOpen();return false;">'+text+'</a>');
}


/* kesobb ez meg jo lehet valamire (ha hasznalunk majd iframe-et, amit egyszer elvileg majd fogunk...
_KepesUser.prototype.signalOpen = function() {
	var iframe = document.getElementById('_ku_iframe');
	var src = iframe.src;
	var hashpos = src.indexOf('#');
	if (hashpos < 0) {
		iframe.src = src+'#open';
	} else {
		var src = iframe.src.substring(0,hashpos);
		iframe.src = src+'#open';
	}
}
*/
_ku_ = new _KepesUser();
// egy id-vel adott element frissitese AJAX-bol, JSON-on at
// csomo parametert atadunk amit a _ku_ tud (KepesUser instance)



