$(document).ready(function () {
	$('.trackedlink').click(function() {
		var clickedName = $(this).attr('rel');
		if (clickedName != '') {
			var cookievals = ($.cookie("trackedclicks") == null) ? '' : $.cookie("trackedclicks").split("|");
			var output = '';
			var match = false;
			if (cookievals == '') {
				output = clickedName + '=1|';
			}
			else {
				$.each(cookievals, function(key, entry) {
					if (entry.split("=")[0] == clickedName) {
						output += clickedName + "=" + (parseInt(entry.split("=")[1]) + 1) + '|';
						match = true;
					}
					else {
						output += entry + '|';
					}
				});
				if (!match) {
					output += clickedName + "=1|"; 
				}
			}
			output = output.slice(0, -1);
			$.cookie("trackedclicks", output, {path: '/'});
		}
	});
});
