/**
* googleTrackFile class
* adds google tracker functions to track files or events (e.q. downloads of files or flash action events) within Google Analytics
* you can do this automatically for file downloads (run init() once by onload), or manual by a event (call trackManual on a event)
*
* author:		Niels Boogaard
* methods:  	init(), trackManual()
* properties:	none
*/

var googleTrackFile = {
	
	/**
	* attach the google trackPageview function to the onclick event of each A-tag which points to a document
	* @param element: id of the element which contains all A-tags (usually 'maintable')
	*/
	init:function (element) {
		if (/\/admin\//.test(document.location))
			return false;
		
		element = document.getElementById(element) || document.body;
		if (!element)
			return false;

		var loc, el, querystring, type, a = element.getElementsByTagName('A');
		loc = new RegExp ('^' + document.location.protocol + '\/\/' + document.location.host,'i');
		type = new RegExp ('\.(' + this.types + ')$', 'i');
		
		for (el=0;el<a.length;el++) {
			
			querystring = a[el].href.replace(loc, '');
			try {
				arrQS = querystring.split(".")
				extension = arrQS.pop();
				if (extension.length == 3 || extension.length == 4) {
					a[el].onclick = function() {
						querystring = this.href.replace(loc, '');
						pageTracker._trackPageview(querystring);
					}
				}
			
			} catch (e) {}
			
		}
	},
	
	/**
	* run the google trackPageview function manually (e.g. on an event of a flashmovie)
	* @param pagename: virtual pagename which will appear in Google Analytics
	*/
	trackManual:function (pagename) {
		if (!pagename)
			return false;
		
		pageTracker._trackPageview(pagename);
	}
	
}
