$(document).ready(function(){
	$("a").mousedown(function(){
		var textPressed = trim($(this).text());
		textPressed = textPressed.substring(0, Math.min(textPressed.length, 30));
		//console.log(textPressed);
		sendFakePageView(getCurrentPage(), textPressed);
	});

});

function getCurrentPage()
{
	var currentPage = document.location.href;
	currentPage = currentPage.substring(currentPage.lastIndexOf("/")+1);
	currentPage = currentPage.length > 1 ? currentPage : "index.php";
	return currentPage;
}


function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function sendFakePageView(i_FromPage, i_ContentPressed)
{
	var pageToSend = '/fp/?page='+i_FromPage+'&ContentClicked='+i_ContentPressed;
    _gaq.push(['_trackPageview',pageToSend]);
}
