Facebook = {
	url : '',
	userAction : false,
	login : function()
	{
		var url = this.url;
		if (this.userAction)
		{
			url += '?auto=true';
		}
		window.location.href = url;
	},
	loginButton : function()
	{
		this.userAction = true;
		FB.login(function(response){ Facebook.login();}, {perms:'email'});
		return false;		
	}
};
Google = {
		url : '',
		uid : '',
		userAction : false,
		loginForm : function()
		{
			var url = this.url + '?uid=' + this.uid;
			if (this.userAction)
			{
				url += '&auto=true';
			}
			window.location.href = url;
		},
		loginButton : function()
		{
			this.userAction = true;
			window.open(this.url + '/login', 'gauth','width=600,height=400,location=1');
			return false;
		},
		close : function() {window.close();}
};
Page = {
	loggedIn : true,
	xhrUrl : '/xhr',
	display_mode : 'page',
	cancel : function()
	{
		if (this.display_mode == 'page')
		{
			history.back();
		}
		else
		{
			top.$().colorbox.close();
		}
		return false;
	},
	initLightBox : function(selector)
	{
		$(selector).colorbox({
			href: function() {return this.href + '?__template=popup'; },
			iframe:true,
			innerWidth:780,
			innerHeight:450,
			overlayClose:false
		});
	},
	initLightBoxPage : function()
	{
		this.display_mode = 'iframe';
		if (window.parent.$ && window.parent.$.colorbox)
		{
			if (parent.$('#cboxTitle').html())
			{
				parent.$('#cboxTitle').html(document.title);
			}
			$('a, form').each(function()
			{
				if (!this.target || this.target == '_self')
				{
					var curUrl = $(this).url();
					if (curUrl.is('external'))
					{
						this.target = '_parent';
					}
					else if (curUrl.toString() && curUrl.toString() != '#')
					{
						curUrl.param('__template', 'popup');
					}

				}

			});
		}
		else
		{
			$(document).url().param('__template', '');
		}
		$(window).load(function ()
				{
					if (window.parent.$ && window.parent.$.colorbox)
					{
						var y = $('body').height() + 50;
						if (y > 450)
						{
							window.parent.$.colorbox.resize({innerHeight:y});
						}
					}
		});
	}
};

function debug(o)
{
	var s = '';
	for ( p in o )
	s += p + ' - ' + o[p] + '\r\n';
	return s;
}
