var LpOverlay = function (id, close, facebook) {
	this.overlay = new Overlay(id, {	width: '535px',
										draggable: true,
										visible: false,
										close: (close || facebook ? true : false),
										modal : true,
										zindex: 1500,
										fixedcenter: true,
										// fixedcenter: (facebook ? false : true),
										constraintoviewport: true
	});

	// Identifica un overlay a pił passi
	this.overlay.stepOverlay = true;
	
	this.overlay.onShow(function () {
		YAHOO.util.Cookie.remove("JSESSIONID", { domain: conf.domainUrl, path: '/' + (conf.env == 'pvt' ? 'MM3' : '') });
	});
	
	this.overlay.onClose(function () {
		YAHOO.util.Cookie.remove("JSESSIONID", { domain: conf.domainUrl, path: '/' + (conf.env == 'pvt' ? 'MM3' : '') });
	});
	
	this.show = function (anchorShow, text, anchorHide) {
		var fn = null;
		
		/*if(facebook) {
			this.overlay.addClass('facebook');
			
			try {
				var me = this.overlay;
				var fn = function () {
					me.setPosition(YAHOO.util.Dom.getX('profile_thumb') + 230, YAHOO.util.Dom.getY('profile_thumb'));
				}
			} catch (e) {}
		}*/	
		
		this.overlay.show(null, this.overlay.generateOverlay(text), null, fn);
	};
	
	this.firstStep = function (type, encryptedProfileId, params) {
		var epid = encryptedProfileId;
		var actionString = (encryptedProfileId ? ((encryptedProfileId.indexOf('-') < 0 ? 'profile-id=' : 'social_network=Facebook&ext-profile-id=') + epid) : '')
		
		if(params) {
			var tmp = new Array();
			for(var key in params)
				tmp[tmp.length] = key + '=' + params[key];
			if(actionString) actionString += '&';
			actionString += tmp.join('&');
		}
		
		this.overlay.scriptUrl = lpsUrls[type] + '?' + actionString;
		this.overlay.setContentByAjax('', null, null, this);
	};
	
	this.nthStep = function (formName, bname, bvalue, type) {
		this.overlay.scriptUrl = lpsUrls[type] + (this.encryptedProfileId ? '?profile-id=' + this.encryptedProfileId : '');
		var actionString = bname + '=' + bvalue;
		this.overlay.setContentByAjax(actionString, null, null, this, formName, true);
	};
};

OverlayConfiguration.lpNotClose = new LpOverlay("textOverlay"),
OverlayConfiguration.lpClose = new LpOverlay("textOverlay", true),
OverlayConfiguration.lpFacebook = new LpOverlay("textOverlay", false, true),
OverlayConfiguration.lp = {
	nthStep: function (formName, bname, bvalue, type) {
		if(type == 'freerider' || type == 'cc' || type == 'bundle')
			return OverlayConfiguration.lpClose.nthStep(formName, bname, bvalue, type);
		else if(type == 'image')
			OverlayConfiguration.genericMessage.showFormatted('genericMessage', 'overlay_manager/donne_gratis');
		else if(type == 'facebook')
			return OverlayConfiguration.lpFacebook.nthStep(formName, bname, bvalue, type);
		return OverlayConfiguration.lpNotClose.nthStep(formName, bname, bvalue, type);
	}
};
OverlayManager.lp = function (args) {
	if(args[0] == 'freerider' || args[0] == 'cc' || args[0] == 'bundle')
		OverlayConfiguration.lpClose.firstStep(args[0], args[1], args[2]);
	else if(args[0] == 'image')
		OverlayConfiguration.genericMessage.showFormatted('genericMessage', 'overlay_manager/donne_gratis');
	else if(args[0] == 'facebook')
		OverlayConfiguration.lpFacebook.firstStep(args[0], args[1], args[2]);
	else
		OverlayConfiguration.lpNotClose.firstStep(args[0], args[1], args[2]);
};