/**
	Simple Download jQuery Plugin
*/


(function($) { 
 
$(function() {
	$.JSONService().add("Download", "/netsmartz_v3/services/downloads.asmx");
	$("a[href^='http://cdn.netsmartz.org']").click(function() {
		var url = $(this).attr("href");
		var i = url.lastIndexOf("/");
		var name = url.substr(i + 1);
		
		_gaq.push(['_trackEvent', 'Download', name]);
		$.JSONService("Download").ok(null).call("track", {id:url, name:name});
	});
});

//Init
/*
$(function() {
	$.JSONService().add("Download", "/netsmartz_v3/services/downloads.asmx");
	$("a[href^='/sitecore/content/Common/']").each(function() {
		var cb = (function(t) { 
			return function(info) {
				if(info.IsProtected) {
					throw new Error(info.Path + " is a protected resource");
				}
				if(info.Formats["en filename"] === undefined) {
					throw new Error(info.Path + " is missing 'EN Filename'");
				}
				$(t)
					.attr("href", info.Formats["en filename"])
					.click(function() {
						var url = $(this).attr("href");
						var i = url.lastIndexOf("/");
						var name = url.substr(i + 1);
						
						_gaq.push(['_trackEvent', 'Download', name]);
						$.JSONService("Download").ok(null).call("track", {id:url, name:name});
					});
			};
		}(this));
		
		
		var h = decodeURI( $(this).attr("href").toLowerCase() );
		var i = h.indexOf("/sitecore/content/common/");
		h = h.substr(i);
		$.JSONService("Download")
			.ok(cb)
			.call("info", {path:h});
	});
});
*/
}(jQuery));

