/*
 * jQuery code that adds Google Analytics tracking code for links to files and external pages
 *
 * Author: Nick Schoonens <nick@marketing-results.com.au>
 * Date: 26/06/2008
 * Version: 1.1
 */


var fileTypes = ['doc','docx','xls','xlsx','ppt','pdf','mov','wav','mp3','jpg','gif','png','mp3'];
$(document).ready(function() {
	$('a').each(function() {
		var $a = $(this);
		var href = $a.attr('href');
		if (href != undefined) {
			var hrefArray = href.split('.');
			var extension = hrefArray[hrefArray.length - 1];
			if ( (href.match(/^http/)) && (! href.match(document.domain)) ) {
				// if so, add the GA tracking code
				$a.click(function() {
					pageTracker._trackPageview('/outgoing/' + href);
				});
			} 
			else if ($.inArray(extension,fileTypes) != -1) {
				$a.click(function() {
					// get the post title if there is one
					// and add it to the string for tracking
					pageTracker._trackPageview('/documents/' + href);
				});
			}
		}
	});
	$('input:submit').each(function() {
		var $button = $(this);
		var value = $button.attr('value');
		if (value != undefined) {
			//var valueArray = href.split('.');
			//var extension = hrefArray[hrefArray.length - 1];
			//if ( (href.match(/^http/)) && (! href.match(document.domain)) ) {
				// if so, add the GA tracking code
				$button.click(function() {
					pageTracker._trackPageview('/form/' + value + '#' + document.URL);
				});
			//} 
		}
	});
});