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

(function () {
	disqus.showSelectForumBox = function(el) {
		// Show lightbox
		$.facebox($('#select-forum').html());

		// Set selection action
		$('.select-action a').click(function () {
			disqus.selectForum(this.rel, el.href);
			return false;
		});
	};

    disqus.selectForum = function(forum, target) {
        if(target.slice(-1) == '#') { // if the href was "#"
            window.location = window.location.toString().replace('http://' + context.forumUrl + '.', 'http://' + forum + '.');
        } else {
            var i = target.indexOf('/admin/');
            if (i == -1) {
                i = target.indexOf('/comments/');
            }
            target = target.substring(i);
            window.location = 'http://' + forum + '.' + context.disqusDomain + target;
        }
    };
    
})();

$(document).ready(function () {

	// Close the /comments/login lightbox
	$('#lightbox-login a[rel=signup]').click(function () {
		$('#lightbox-login, #facebox_overlay').remove();
		return false;
	});


	// Site-select
	if(!window.XMLHttpRequest) {
		// IE6
		$('#site-select').click(function () {
			if(!$(this).hasClass('hover')) {
				$(this).addClass('hover');
			} else {
				$(this).removeClass('hover');
			}

			return false;
		});
	} else {
		$('#site-select a.site-select-link').click(function () {
			return false;
		});
	}

	// Set the select-forum for navigation with multiple forums
	$('#navigation li a[rel=selectforum]').click(function () {
		disqus.showSelectForumBox(this);
		return false;
	});

	// Set the select-forum for switch-link links
	$('a[rel=switchsite]').click(function() {
		disqus.showSelectForumBox(this);
		return false;
	});


});

