// default event: link click pageTitle
// file extension grabbed for content
// class based actions from agreed list
// Gets page title
// if the link has a name add name as well
// if class 'no_js': don't add tracking code
(function($){

$.fn.extend({ 
  		jtrack: function() {
 		
 		this.live('click', function(e) {
 		
// get page title
var pageTitle = $("title").text();

// set default action as 'click'
// set default action as the clicked element type
	var action = "click";
	var content = this.tagName;

// list of allowed actions
	var allowact = new Array('download', 'play', 'click', 'skip', 'previous', 'next', 'pause', 'stop' );
// get list of classes	
	var classList = $(this).attr('class').split(' ');
// for each item in classList do something	
	$.each( classList, function( index, value){
// check to see if each item is in allow act
		if ($.inArray(value, allowact) >= 0) {
// if it is then make it the action
		action = value;
		};
	});

	
if ($(this).attr("href")) {
// get the file extension from the href
	var ext = $(this).attr("href").split('.').pop().toLowerCase();
// allowed filetypes/extensions
	var allow = new Array('xml', 'xlsx', 'xls', 'wks', 'vcf', 'sql', 'sdf', 'sdb', 'pptx', 'ppt', 'pps', 'mdb', 'dll', 'db', 'dat', 'csv', 'accdb', '123', 'wps', 'wpd', 'txt', 'rtf', 'pages', 'msg', 'log', 'docx', 'doc', 'wma', 'wav', 'ra', 'mpa', 'mp3', 'midi', 'mid', 'm3u', 'iff', 'aif', 'aac', 'qxp', 'qxd', 'pdf', 'indd', 'pln', 'dwg', '3dmm', 'svg', 'ps', 'eps', 'dxf', 'drw', 'ai', 'tif', 'thm', 'psp', 'psd', 'png', 'jpg', 'gif', 'bmp', 'pct', 'sys', 'lnk', 'key', 'drv', 'dmp', 'cur', 'cpl', 'cab', 'xll', 'plugin', '8bi', 'ttf', 'otf', 'fon', 'fnt', 'xhtml', 'rss', 'php', 'jsp', 'js', 'html', 'htm', 'css', 'asp', 'wmv', 'vob', 'swf', 'rm', 'mpg', 'mp4', 'mov', 'flv', 'avi', 'asx', 'asf', '3gp', 'pl', 'java', 'cpp', 'c', 'uue', 'mim', 'hqx', 'bin', 'zipx', 'zip', 'sitx', 'sit', 'rar', 'pkg', 'gz', 'deb', '7z', 'ws', 'vb', 'pif', 'exe', 'com', 'cgi', 'bat', 'app', 'prf', 'ini', 'cfg', 'yps', 'torrent', 'part', 'msi', 'sav', 'rom', 'nes', 'gam', 'vcd', 'toast', 'iso', 'dmg', 'tmp', 'ori', 'gho', 'bup', 'bak' );
// if the extension is in allowed extensions
	if(jQuery.inArray(ext, allow) >= 0) {
// make content the file extension
    var content = ext;
	};
};


// if there is attribute name 
if ($(this).attr("name")) {
	var name = $(this).attr("name");
};


// if you have the class 'no_js' then nothing happens to that link otherwise it tracks the click
	if (!$(this).hasClass("no_js")) {
		pageTracker._trackEvent(content, action, pageTitle, name);
	};

// if a link is clicked - allow default behaviour (follow link)	
	if($(e.target).is('a')){
            return true;
        } else {
	return false
	}
	
 });
 
}
	});

})(jQuery);

jQuery(document).ready(function($) {  
	$("*").jtrack();
});
