// jQuery plugin for adding Google Analytics tracking handlers to links and forms
(function($){
	function getHRef(linkHref){
		var href = linkHref;
		if(linkHref.indexOf("javascript:") == 0){
			var hrefParts = linkHref.split("'");
			if(hrefParts.length > 1){
				href = hrefParts[1];
			}
		}
		
		return href;
	}
		  
	$.fn.gatLinks = function(){
		$(this).each(function(){
			if(typeof($(this).attr("href")) == 'string' && ($(this).attr("href").indexOf("http://") > -1 || $(this).attr("href").indexOf("https://") > -1)){
				$(this).click(function(){
					if(typeof(allTracker) == 'object'){
						allTracker._link(getHRef($(this).attr("href")));
						if(window.location.href.indexOf("debug") >= 0){
							alert(getHRef($(this).attr("href")));
						}
						return false;
					}
				});
			}
		});
	}
	
	$.fn.gatForms = function(){
		$(this).each(function(){
			if(typeof($(this).attr("action")) == 'string' && ($(this).attr("action").indexOf("http://") > -1 || $(this).attr("action").indexOf("https://") > -1)){
				$(this).submit(function(){
					if(typeof(allTracker) == 'object'){
						allTracker._linkByPost(this);
						if(window.location.href.indexOf("debug") >= 0){
							alert($(this).attr("action"));
						}
						return true;
					}
				});
			}
		});
	}
})(jQuery);