/* uses jquery on Ning, wrapped as x$ */


x$(document).ready(function() {

	// add body class to desired pages
	var bClass = addBodyClass();
	if (bClass) {
		x$("body").addClass(bClass);
	}
	
	makeBreadcrumb();
	
	// update account profile link
	accountProfileLink();
	
	// make misc. blog fixes (stupid Ning htmls)
	blogLayout();
	
	// add legalese to discussion boards
	addLegalese();
	
	
});


function accountProfileLink() {
	//var profileLink = x$("#xg_tab_profile a").attr("href");
	var profileLink = x$("#xn_username").attr("href");
	x$("#xg_module_account h2").wrapInner('<a href="'+profileLink+'"></a>');
}

function blogLayout() {
	x$(".xg_blog .xg_module_body").each(function() {
		x$(this).find("p.small").eq(0).appendTo(x$(this).find("h3"));
	});
	x$(".xg_blog .xg_module_body:last").css("border","none");
	
	x$(".blog ul.navigation").eq(0).prepend('<li><a href="/profiles/blog/list?promoted=1">All Editors\' Blog Posts</a></li>');
	// x$(".blog ul.navigation").fadeIn();
	
	
	x$("#xg_body .module_blog").each(function() {
		x$(this).find("p.small").eq(0).appendTo(x$(this).find("h3"));
	});
	
}

function addBodyClass() {
	
	var u = window.location.href;
	var bClass;
	if (u.indexOf("/group") != -1) {
		bClass = "group";
		if (u.indexOf("/actionplan") != -1) {
			bClass += " wbap";
		}
	}

	if (u.indexOf("/forum") != -1) {
		bClass = "forum";
	}
	
	if (u.indexOf("/blog") != -1) {
		bClass = "blog";
		if (u.indexOf("?promoted=1") != -1) {
			bClass += " editor-blog";
		}
	}

	if (bClass != "") {
		return bClass;
	}
	
	return false;
	
}

function makeBreadcrumb() {
	var current = x$("#xg_body h1").eq(0).text();
	if (current != "") {
		x$("#ms-global-breadcrumbs").append(' <span class="separator">&raquo; <span id="ms-global-breadcrumbs-youarehere" class="ms-global-breadcrumbs-youarehere">'+current+'</span>');
		x$("#ms-global-breadcrumbs-youarehere").text(current);
	} else {
		x$("#ms-global-breadcrumbs #community-home-link").remove();
		x$("#ms-global-breadcrumbs").append('<span class="ms-global-breadcrumbs-youarehere" id="ms-global-breadcrumbs-youarehere">Community</span>');
	}
}

function addLegalese() {
	var legal =  ''
		legal += '<div class="xg_module bs-legalese">'
		legal += '<div class="xg_module_body categories">'
		legal += '<h3>Legal Fine Print</h3>';
		legal += '<p class="legal">This site\'s content is provided for informational purposes only, and is not intended to be a substitute for professional medical care, advice, diagnosis, or treatment. Always seek the advice of your physician or other qualified health-care professional before relying on the site content. Reliance on any information published on this site is solely at your own risk. Please review MSLO <a href="http://www.wholeliving.com/terms-of-use">terms of use</a>.</p>'
		legal += '</div>'
		legal += '</div>';
	
	x$("body.forum .xg_span-5").eq(0).append(legal);
	
}
