$(document).ready(function() {
	/* Redirect to download form if new user */
	var lead = $.cookie('leadSubmitted');
	if (!lead) {
		$("a[rel=download]").each(function() {
			var fileURL = $(this).attr("href");
                        if (_gaq) {
                            _gaq.push(['_trackEvent','Files', 'Download', fileURL]);
                        }

                        var productName = $(".product-title div h2").text();
                        productName = encodeURI(productName);

			$(this).attr("href", "/download?file=" + fileURL + "&product=" + productName);

		});
	} else {
		$("a[rel=download]").click(function() {
                        if (_gaq) {
                            _gaq.push(['_trackEvent','Files', 'Download', this.href]);
                        }
			window.open(this.href);
			return false;
		});
	}
});
