(function(jQuery){

	// declaring an TT namespace for functions
	if(!jQuery.TT) jQuery.TT = {};

	// helper function to convert an object literal to an array
	// do not use this for anything else as it may have undesired effects
	jQuery.TT.makeArrayFromObject = function (object) {
		var array = [];
		for(var key in object) {
			array.push(object[key]);
		}
		return array;
	};



	// function used to call the GoogleAnalytics function with
	jQuery.TT.GoogleAnalytics = function (options) {

		// we expect an object literal to be given
		options = jQuery.TT.makeArrayFromObject(options);

		// call the GoogleAnalytics _trackEvent method, do not throw errors
		if (pageTracker && typeof(pageTracker._trackEvent) == 'function') {
			pageTracker._trackEvent.apply(pageTracker, options);
		}
	};


	// default options set for the GoogleAnalytics function
	jQuery.TT.GoogleAnalytics.options = {
		category:null,
		action:null,
		label:null,
		value:null
	};

	// method to assign onclick event handlers for GoogleAnalytics on internally stored set of elements
	jQuery.fn.GoogleAnalytics = function (options) {
		this.each(function(index){

			// extend an empty object to ensure all handlers have their own not further referenced options object
			jQuery.extend ({}, jQuery.TT.GoogleAnalytics.options, options);

			// create a label when none is given
			options.label = options.label || $(this).text();

			$(this)[options.action] (function(event){
				jQuery.TT.GoogleAnalytics(options);
			});
		});
	};

})(jQuery);