BR = function(container)
{
	this.container = container ? container : "#content-container";
}

// callback function for callback links
BR.prototype.callback = function(e)
{
	var me = this;
	
	me.loadUrl(e.target.href);
	e.preventDefault();
}

// initializes links in the specified element
BR.prototype.init = function(element)
{
	var me = this;
	
	if (!element)
	{
		element = document;
	}
	
	$("#sidebar").find(".pagenav > ul").treeview({ collapsed: true, unique: true, persist: "location" });
	$(element).find("a[rel='lightbox']").colorbox();
	$(element).find("a[rel='callback']").click(function(e)
	{
		me.callback(e);
	});
}

// loads the specified URL into the page
BR.prototype.loadUrl = function(url)
{
	var me = this;
	
	$.get(url, { callback: true }, function(data)
	{
		var container = $(me.container);
		var i = url.indexOf('/', url.indexOf("://") + 3) + 1;
		
		container.html(data);
		container.each(function(i) { me.init(this) });
	});
}

// initializes any links with the rel attribute set to 'callback'
$(document).ready(function()
{
	window.br = new BR();
	window.br.init();
});

window.GotoAnchor = function()
{
	window.location.hash = "content-container";
}

window.ShowContent = function(url)
{
	if (!window.br)
	{
		window.br = new BR();
	}
	
	window.br.loadUrl(url);
}
