// Using jQuery's document.ready (faster than window/body onload as it doesn't wait for images to load)
$(document).ready(function() {
	// Apply the tracking code to document links
	applyDocLinkTracking();
});

function applyDocLinkTracking() {
	// Get all links which have an href attribute containing '.pdf'
	var pdflinks = $("A[href*='.pdf']");
	// Get all links which have an href attribute containing '.ppt'
	var pptlinks = $("A[href*='.ppt']");

	// Attach the tracking events to the links
	attachDocLinkTrackingEvents(pdflinks);
	attachDocLinkTrackingEvents(pptlinks);
}

function attachDocLinkTrackingEvents(links) {
	// Loop through all the links and attach the events to the links to call the tracking code
	links.each(function() {
		// Get the href value for this link
		var href = $(this).attr("href");
		// Bind a click event to each link, passing the href value as optional data
		$(this).bind("click", {destination:href}, function(e) {
			pageTracker._trackPageview(e.data.destination);
		});
		// Bind a keypress event to each link, passing the href value as optional data
		$(this).bind("keypress", {destination:href}, function(e) {
			pageTracker._trackPageview(e.data.destination);
		});
	});
}