if (window.disqus === undefined) {
	var disqus = {};
}

(function () {

	disqus.showLoginBox = function(el) {
		$.facebox.settings.opacity = 0.9;
		$.get('/auth/login.html', function(data) {
			var service;
			if(context.forumUrl === undefined) {
				service = 'profile';
			} else {
				service = 'comments';
			}

			var app = (context.forumUrl === undefined) ? 'dp' : 'dc';
			$.facebox('<h3>Log into <img src="' + context.mediaUrl + '/images/v3/logo/' + (service == 'profile' ? 'dp' : 'dc') + '-inline.gif" /></h3>' + data);
			// Set redirect url if provided, otherwise redirect to current page
			var next = (utils.query().next) ? utils.query().next : window.location;
			$('form#login-form').attr('action', '/' + service + '/login/?next=' + next);
			$('form#login-form input[type=text]')[0].focus();
			$('form#login-form').append('<br/><a href="/' + service + '/register/">No account? Sign up, free.</a>');
			$.facebox.settings.opacity = 0; // Reset opacity
		});
	};

	// turn off autogrow. it sucks.
	disqus.autogrow = function (object) {
		return;
	};

})();

$(document).ready(function () {

	// Set login link
	$('a[rel=login]').click(function () {
		disqus.showLoginBox(this);
		return false;
	});
});
