
// ============================================
googleAnalytics = function(){

	// ============================================
    // private variables
	
	// ============================================
    // private functions
	
	
	// ============================================
    // public space
    return {
		// ============================================
        // public properties, e.g. strings to translate
		
		
 		// ============================================
        // public methods
		
        init: function(pSelectors){
			//loop through the selectors array past in
			for(var i=0; i<pSelectors.length; i++){
				
				// ============================================
				var labelValue = "";
				var _self = this;
				var selectorData = pSelectors[i];
				
				// ============================================
				$(selectorData.selector).click({category:selectorData.category, action:selectorData.action, label:selectorData.label, val:selectorData.value}, function(e){
					
					// ============================================
					//work out the label value, if it is a string doesn't starts @, use the string as label value
					var labelString = e.data.label;
					if(labelString.charAt(0) == "@"){
						if(labelString == "@text"){
							//this is a text
							labelValue = $(this).text();
						}else{
							//attributes value
							var slectorAttribute = labelString.substr(1);
							labelValue = $(this).attr(slectorAttribute);
						}
					}else{
						labelValue = labelString;
					}
					
					// ============================================
					//is it web page or event to track
					if(e.data.action == "pageView"){
						_self.TrackPageview(labelValue);
					}else{
						_self.TrackEvent(e.data.category, e.data.action, labelValue, e.data.val);
					}
				});
				
			}
			
		},
		
	
		TrackEvent: function(pCategory, pAction, pLabel, pVal){
			if(pLabel == undefined) pLabel = "";
			if(pVal == undefined) pVal = 0;
			try{
				_gaq.push(['_trackEvent', pCategory, pAction, pLabel, pVal])
				//alert(pCategory + " - " + pAction + " - " + pLabel);
			}catch(err){}
			
		},
		
		TrackPageview: function(pHref){
			try{
				_gaq.push(['_trackPageview', pHref])
				//pageTracker._trackPageview(href);
			}catch(err){}
		}
	
	};
}; 

