	var opts = {
		trackurl: 	null,
		vpath:		'/track',
		external:	'/external/',
		mailto:		'/mailtos/',
		download:	'/downloads',
		bookmark:	'/bookmarks',
		statuscode: 	200,
		emaillinks:	true,
		extlinks:	true,
		bookmarklinks:	false,
		customvar:	null,
		addTrans:	null,
		addItems:	null,
		extensions: [
				'pdf','doc','xls','csv','jpg','gif', 'mp3',
				'swf','txt','ppt','zip','gz','dmg','xml', 'js'		
		]
	};	
	
	function decorateLink(u){
		var trackingURL = '';

		// determine type of link
		linktype = 0;
		if (u.indexOf('http://') == 0) {		// http:// type external link
			linktype = 1;
		}
		else {
			if(u.indexOf('mailto:') == 0){		// mailto link
				linktype = 2;
			}
			else {
				if(u.indexOf('#') == 0){	// bookmark link
					linktype = 3;
				}
				else {
					linktype = 4;
				}
			}
		}
		switch(linktype) {
		case 1: //ext link
			// complete URL - check domain
			if (opts.extlinks) {	// track extlinks enabled ??
				var regex = /([^:\/]+)*(?::\/\/)*([^:\/]+)(:[0-9]+)*\/?/i;
				var linkparts = regex.exec(u);
				var urlparts = regex.exec(location.href);					
				if(linkparts[2] != urlparts[2]) trackingURL = opts.vpath + opts.external + linkparts[2];
			}
			break;
		case 2: //mailto link
			if (opts.emaillinks) {	// track mailto links enabled ??
				var emailaddr = u.substring(7);
				if (emailaddr.indexOf('?') > 0) {
					emailaddr = emailaddr.substring(0, emailaddr.indexOf('?'));
				}
				trackingURL = opts.vpath + opts.mailto + emailaddr;
			}
			break;
		case 3: // bookmark links
			if (opts.bookmarklinks) {	// track bookmark links enabled ??
				trackingURL = opts.vpath + opts.bookmark + document.location.pathname + '/' + u;
			}
			break;
		case 4:
			// no protocol or mailto - internal link - check extension
			var ext = u.split('.')[u.split('.').length - 1];			
			var exts = opts.extensions;

			for(i = 0; i < exts.length; i++){
				if(ext == exts[i]){	// matches one of recognised download filetypes
					trackingURL = opts.vpath + opts.download + u;
					break;
				}
			}
			break;
		}
		// go back with pseudo url representing this click event
		return trackingURL;
	}

	// custom:: examine every link in the page
	jQuery('a').each(function(){
		var u = jQuery(this).attr('href');

		if(typeof(u) != 'undefined'){
			var newLink = decorateLink(u);

			// if it needs to be tracked manually,
			// bind a click event to call GA with
			// the decorated/prefixed link
			if(newLink.length){
				jQuery(this).click(function(){
					pageTracker._trackPageview(newLink);
				});
			}
		}
	});		

