/* Contains javascript functionality available
 * for _all_ webpages deployed on the system.
 *
 * @author Kim A. Betti <kim.betti@gmail.com>
 */

$(document).ready(function() {
	$(":input:visible:enabled:first").focus();
	addS3DownloadEventTracking();
	enableCommentForms();
});

/**
 * Event tracking for S3 downloads
 */
function addS3DownloadEventTracking() {
	if (typeof _gaq !== "undefined") {
		$("a[href^='http://pc-webpagesystem-public.s3.amazonaws.com/']").click(function() {
			var href = $(this).attr("href");
			href = href.replace("http://pc-webpagesystem-public.s3.amazonaws.com/", "")
			try {
				_gaq.push(['_trackEvent', 'S3', 'Download', null, href]);
			} catch (err) { }
		});
	}
}

/**
 * Enables comment forms hidden from spam bots.
 */
function enableCommentForms() {
	var container = $(".commentFormContainer");
	$(container).show();
	$("form", container).attr("action", "/comment/submit");
}
