/**
 * jQuery Google Analytics Event Tracker wrapper Plugin
 * Gaet 1.0 - By Creuna (http://www.creuna.se)
 *
 * Gaet Copyright (c) 2009 Creuna.
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/

(function($) {
	$.fn.extend({
		gaTrack: function(options) {
		    var defaults = {
			       category: "Undefined", //The name you supply for the group of objects you want to track.
			       action: "Undefined", //A string that is uniquely paired with each category, and commonly used to define the type of user interaction for the web object.
			       label: null, //An optional string to provide additional dimensions to the event data.
			       value: null, //An integer that you can use to provide numerical data about the user event.
			       triggerClick: false //Trigger self click after track event has been added. Use if there's already a cklick function defined.
			};
			
			var options = $.extend(defaults, options);
            var category        = options.category;
            var action          = options.action;
            var label           = options.label;
            var value           = options.value;
            var triggerClick    = options.triggerClick;
            
            var m = new RegExp("[\\?|&]" + "gaMode" + "=(.*?)($|&|#)").exec(document.location);	            
		    
		    return this.each(function() {
	            var obj = $(this);
	            if(m !=null && m[1] === "test"){
	                obj.css("outline", "3px dotted blue");
	                obj.attr("title", category +", "+action +", "+label +", "+value);
                } else {
                    if(triggerClick){
                        pageTracker._trackEvent(category, action, label, value);
                    } else {
                        obj.click(function() {
	                        pageTracker._trackEvent(category, action, label, value);
                        });
                    }
                }
            });
		}
	});
})(jQuery);

var gaGetFileName = function(path) {
    return path.substr(path.lastIndexOf("/")+1,path.length);
};
