$(document).ready(function()
{
	var hostname = location.hostname;

	if (hostname == "www.manchester.ac.uk" || hostname == "manchester.ac.uk")
	{
		var currentPath = location.pathname;

		var bodyClass = $("body").prop("class");

		switch (bodyClass)
		{
			case "home":
			case "leader":

				bodyClass = bodyClass[0].toUpperCase() + bodyClass.slice(1);

				$("#leaderfeature #main-photo-slider .panelContainer .panel .container h2 > a").each(function() {
					$(this).attr("onclick", "_gaq.push(['b._trackEvent', '" + bodyClass + " - featurebox - title', '" + currentPath + "', '" + getLinkText($(this)) + " - " + $(this).attr("href") + "']);");
				});

				$("#leaderfeature #main-photo-slider .panelContainer .panel .container .strapline > a").each(function() {
					$(this).attr("onclick", "_gaq.push(['b._trackEvent', '" + bodyClass + " - featurebox - strapline', '" + currentPath + "', '" + getLinkText($(this)) + " - " + $(this).attr("href") + "']);");
				});

				$("#leaderfeature #main-photo-slider .panelContainer .panel .container .context > a").not(".playvideo").each(function() {
					$(this).attr("onclick", "_gaq.push(['b._trackEvent', '" + bodyClass + " - featurebox - custom HTML', '" + currentPath + "', '" + getLinkText($(this)) + " - " + $(this).attr("href") + "']);");
				});

				$("#movers-row a").each(function() {
					$(this).attr("onclick", "_gaq.push(['b._trackEvent', '" + bodyClass + " - featurebox - navigation', '" + currentPath + "', '" + $("span.nav-thumb", this).text() + "']);");
				});

				$(".leaderbox:not(.onhover, .videobox, .newsbox) h2 > a").each(function() {
					$(this).attr("onclick", "_gaq.push(['b._trackEvent', '" + bodyClass + " - promobox - title', '" + currentPath + "', '" + getLinkText($(this)) + " - " + $(this).attr("href") + "']);");
				});

				$(".leaderbox:not(.onhover, .videobox, .newsbox) .strapline > a").each(function() {
					$(this).attr("onclick", "_gaq.push(['b._trackEvent', '" + bodyClass + " - promobox - strapline', '" + currentPath + "', '" + getLinkText($(this)) + " - " + $(this).attr("href") + "']);");
				});

				$(".leaderbox.onhover h2 > a").each(function() {
					$(this).attr("onclick", "_gaq.push(['b._trackEvent', '" + bodyClass + " - promobox hover - title', '" + currentPath + "', '" + getLinkText($(this)) + " - " + $(this).attr("href") + "']);");
				});

				$(".leaderbox.videobox a").each(function() {
					$(this).attr("onclick", "_gaq.push(['b._trackEvent', '" + bodyClass + " - promobox video - play video', '" + currentPath + "', '" + getLinkText($(this)) + " - " + $(this).attr("href") + "']);");
				});

				$(".leaderbox.newsbox ul a").each(function() {
					$(this).attr("onclick", "_gaq.push(['b._trackEvent', '" + bodyClass + " - promobox news - story', '" + currentPath + "', '" + getLinkText($(this)) + " - " + $(this).attr("href") + "']);");
				});

				$(".leaderbox.newsbox p a").each(function() {
					$(this).attr("onclick", "_gaq.push(['b._trackEvent', '" + bodyClass + " - promobox news - more news', '" + currentPath + "', '" + getLinkText($(this)) + " - " + $(this).attr("href") + "']);");
				});

				break;
			default:
				$("div.tab a").each(function() {
					$(this).attr("onclick", "_gaq.push(['b._trackEvent', 'Link - content - primarynavigation', '" + currentPath + "', '" + getLinkText($(this)) + " - " + $(this).attr("href") + "']);");
				});

				$("div.bar a").each(function() {
					$(this).attr("onclick", "_gaq.push(['b._trackEvent', 'Link - content - secondarynavigation', '" + currentPath + "', '" + getLinkText($(this)) + " - " + $(this).attr("href") + "']);");
				});

				$("li.nav-secondary-breadcrumb > a,li.nav-secondary-sectionheader > a").each(function() {
					$(this).attr("onclick", "_gaq.push(['b._trackEvent', 'Link - content - verticalnavigation', '" + currentPath + "', '" + getLinkText($(this)) + " - " + $(this).attr("href") + "']);");
				});

				$("ul.nav-secondary-sectionmenu > li > a").each(function() {
					$(this).attr("onclick", "_gaq.push(['b._trackEvent', 'Link - content - sectionnavigation', '" + currentPath + "', '" + getLinkText($(this)) + " - " + $(this).attr("href") + "']);");
				});

				$("div.relatedlinks a").each(function() {
					$(this).attr("onclick", "_gaq.push(['b._trackEvent', 'Link - content - relatednavigation', '" + currentPath + "', '" + getLinkText($(this)) + " - " + $(this).attr("href") + "']);");
				});

				$("#middle-centre a").each(function() {
					$(this).attr("onclick", "_gaq.push(['b._trackEvent', 'Link - content - inpagecontent', '" + currentPath + "', '" + getLinkText($(this)) + " - " + $(this).attr("href") + "']);");
				});
		}
	}
});

function addSlashes(string)
{
	string = string.split("'").join("\\'");
	string = string.split("\"").join("\\\"");
	return string;
}

function getLinkText(thisLink)
{
	var linkText = $.trim($(thisLink).text());

	if (linkText == "")
	{
		linkText = $.trim($(thisLink).children("img").attr("alt"));
	}

	return addSlashes(linkText);
}

function strip(html)
{
	var tmp = document.createElement("DIV");
	tmp.innerHTML = html;
	return tmp.textContent||tmp.innerText;
}

