var queryStr = (window.location.search).replace(/^\?anchor=/, "");
if(queryStr != "")
{
	window.location.replace(window.location.protocol + "//" + window.location.host + window.location.pathname + "#" + queryStr);
}

function external_links()
{
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=anchors.length-1; i>=0; i--)
	{
		var anchor = anchors[i];
		if (anchor.href && anchor.href.substr(0,7) == "http://")
		{
			anchor.target = "_top";
		}
	}
}

// Change links so they use the McCuneCollection.org domain instead of the AbsoluteAnime.com domain.
function fix_links()
{
	if (!document.getElementsByTagName) return;
	var links = document.getElementsByTagName('a');
	for (var i=0; i<links.length; i++)
	{
		if(typeof(links[i].href) == "undefined" || links[i].href == "") continue;
		//links[i].href = links[i].href.replace(/http:\/\/mccune\.localhost/i, "http://www.McCuneCollection.org");
		links[i].href = links[i].href.replace(/http:\/\/www\.absoluteanime\.com\/McCuneCollection\.org/i, "http://www.McCuneCollection.org");
		links[i].href = links[i].href.replace(/(\.com\/\/)/g, ".com/");
		links[i].title = links[i].href;
	}
}

function restrictSidebarWidth()
{
	windowWidth = $(window).width();
	cageWidth = $('.cage').innerWidth();
	diff = (cageWidth) ? Math.round((windowWidth - cageWidth + 128) / 2) : 0; //120 = left-margin of #wrap, 128 = left margin of body
	diff = (diff && diff > 128) ? diff : 128;
	$('#sidebar-navigation').css('max-width', diff+'px');
	//$('title').html('window.width = ' + windowWidth + ', .cage.innerWidth() = ' + cageWidth + ', diff = ' + diff);
}

$(window).resize(function() {
	restrictSidebarWidth();
});

$(document).ready(function(){
	restrictSidebarWidth();
});
