var EventTagger = Class.create(
{	
	initialize : function(page_definition)  {
		this.page_definition = page_definition;
		this.flexReferer = '';
	},
	
	tag : function(event_str) {
		if (this.page_definition)
		{
			this.NIEventDataRemoval();
			this.pure_tag('lc='+ this.page_definition + event_str);
			this.NIDataReset();
		}
	},
	
	pure_tag : function(event_str) {
		
		ntptEventTag(event_str);
		//var pic1 = new Image(1,1);
		
	},
	
	
	NICamClickEvent : function(stockListID) {
		// cam icon ClickTagging
		this.tag('UVL_CAMERACLICK/SearchResults/&CAMERACLICK='+ stockListID);
	}, 
	
	NIWalkaroundClickEvent : function(stockListID) {
		// walkaround ClickTagging
		this.tag('UVL_VIDEOCLICK/SearchResults/&VIDEOCLICK='+ stockListID);
	}, 
	
	NIDescriptorView : function(stockListID, descriptorID) {
		// Descriptor mouseovers
		//this.tag('UVL_Descriptor/'+ descriptorID +'/&VEHICLE='+ stockListID);
	}, 
	
	NIWarrantyClickEvent : function() {
		// Warranty click
		this.tag('WARRANTY/&WARRANTYCLICK=1');
	},
	
	NIWarrantyBrochureClickEvent : function(){
		this.tag('WARRANTY/&WARRANTYBROCHURE=1');
	},
	
	
	NIRichExperienceClickEvent : function() {
		// richexperience click
		this.tag('RICHEXPERIENCE/&RICHEXPERIENCECLICK=1');
	}, 
	
	NIRichExperienceAvailEvent : function() {
        // richexperience click
        this.tag('RICHEXPERIENCE/&RICHEXPERIENCEAVAIL=1');
    }, 
	
	NIRichExperienceAvailable : function() {
		// richexperience is available
		this.tag('RICHEXPERIENCE/&RICHEXPERIENCEAVAIL=1');
	},
	
	NISimilarSearchEvent : function() {
		// similar search click
		this.tag('UVL_VEHICLEDETAILS/&SIMILARSEARCHCLICK=1');
	}, 
	
	NIContactDealerClickEvent : function() {
		// dealer contact click
		this.tag('UVL_FORMSEND/formsend/&UVL_FORMSEND=contactDealer&WHICHFORM=CLD');
	},
	
	NIThumbnailClickEvent : function(targetMedium, shotType) {
		// image thumbnail click
		this.tag('UVL_THUMBNAILCLICK/'+ targetMedium+'/&SHOTTYPE='+shotType);
	},
	
	NIMARSClickEvent : function(assetID) {
		// MARS thumbnail click
		this.tag('UVL_MARSTHUMBCLICK/MARSCLICK/&MARS_ASSETID='+ assetID);
	}, 
	
	NIMARSFindOutMoreClickEvent : function(assetID) {
		// MARS more Info click
		this.tag('MARS_BTNCLICK/findOutMore/&MARS_BTNCLICK=findOutMore&MARS_ASSETID='+assetID);
	},
	
	NIVehicleDetailTabClickEvent : function(whichTab, movingImages) {
		// Vehicle details click
		var concat_str = whichTab + movingImages;
		var eventString = 'UVL_TABCLICK/'+ concat_str +'/&UVL_TABCLICK='+ concat_str;
		if (movingImages == 'Moving')
			eventString +='Moving';
		else
			eventString +='Static';
		this.tag(eventString);
	},
	
    NIPrintList : function() {
        // vehicle details print click
        this.tag('UVL_PRINTLIST/1/&UVL_PRINTLIST=1');
    },
    	
	
	NIVehicleDetailsPrint : function() {
		// vehicle details print click
		this.tag('UVL_PRINTCLICK/1/&UVL_PRINTCLICK=1');
	},
	
	NIPrintCurrentPageClickEvent : function() {
		// vehicle results list current page print
		this.tag('UVL_PRINTCURRENTPAGE/1/&UVL_PRINTCURRENTPAGE=1');
	},
	
	NIPrintTopResultsClickEvent : function(num) {
		// vehicle results list top X print
		this.tag('UVL_PRINTTOPX/1/&UVL_PRINTTOPX=' + num + '&RESULTSFOUND=' + num);
	},
	
    NIVehicleSavedPrint : function() {
        // vehicle compare print
        this.tag('UVL_PRINTSAVED/1/&UVL_PRINTSAVED=1');
    },	
	
	NIVehicleComparePrint : function() {
		// vehicle compare print
		this.tag('UVL_PRINTCOMPARE/1/&UVL_PRINTCOMPARE=1');
	},
	
	NIBackButtonClickEvent : function() {
		// back button
		this.tag('UVL_BACKCLICK/1/&UVL_BACKCLICK=1');
	}, 
    
    NISavedClickEvent : function() {
        // back button
        this.tag('UVL_SAVEDCLICK/1/&UVL_SAVEDCLICK=1');
    }, 	
	
    NISortClickEvent : function(sortData) {
        this.tag('UVL_SORTCLICK/1/CRITERIA_SORTBY=' + sortData);
    }, 
	
    NINewSearchClickEvent : function() {
        this.tag('UVL_NEWSEARCHCLICK/1/&NEWSEARCH=1');
    }, 	
	
    NIRefineSearchClickEvent : function() {
        this.tag('UVL_REFINESEARCHCLICK/1/&REFINEDSEARCH=1');
    },  
	
    NICoUkClickEvent : function() {
        this.tag('UVL_CoUkCLICK/1/&UVL_CoUkCLICK=1');
    },  
	
    NIPagedResultsClickEvent : function(pagenum,totalresults) {
        this.tag('RESULTSFOUND=' + totalresults + '&RESULTSPAGE=' + pagenum);
    },  
       	
	
	NIFlexTagging : function(paramString, getCurrentLC) {
		// flex Tagging
		this.pure_tag('rf='+ this.flexReferer +'&lc='+ getCurrentLC +'&' + paramString);	
		this.flexReferer = getCurrentLC;
	},
	
	/*
	 * function used to remove data that we do not want to tag for ANY of our event tagging.
	 * 
	 * We need this becasue the page definition is set on page load, at which point it needs to tag all
	 * data. However if this is an NIEvent tag we only want to log a subset of that data.
	 * 
	 * This function will be used in all the above events to modify the NTPT_PGEXTRA as this is what 
	 * dictates what variables are sent over in the tagging HTTP request.
	 * */
	 
	NIEventDataRemoval : function()
	{	
		// Set up locals
		var cleanData = new Array()
		var valuesToRemove = new Array()
		var urlTermsArray = new Array();
		var unwantedMatchCount = 0;
		
		//Populate an Array of values that we do not want to be tagged
		valuesToRemove[0] = "CRITERIA_POSTCODE";
		valuesToRemove[1] = "CRITERIA_PRICETO";
		valuesToRemove[2] = "CRITERIA_PRICEFROM";
		valuesToRemove[3] = "CRITERIA_DISTANCE";
		valuesToRemove[4] = "CRITERIA_TRANSMISSION";
		valuesToRemove[5] = "CRITERIA_MILEAGE";
		valuesToRemove[6] = "CRITERIA_MODELSELECT";
		valuesToRemove[7] = "CRITERIA_MODELGROUPID";
		valuesToRemove[8] = "CRITERIA_COLOUR_INCLUSIVE";
		valuesToRemove[9] = "CRITERIA_COLOUR";
		valuesToRemove[10] = "CRITERIA_VARVARIANT";
		valuesToRemove[11] = "CRITERIA_FUEL";
		valuesToRemove[12] = "CRITERIA_MATERIAL";
		valuesToRemove[13] = "CRITERIA_APPROVED";
		valuesToRemove[14] = "CRITERIA_MODELGROUPNAME";
		valuesToRemove[15] = "CRITERIA_MODELS";
	
		//Populate array with page landing tagging values. 
		urlTermsArray=NTPT_PGEXTRA.split("&");
			
		// Loop over 'complete' tagging values
		for (i=0;i<urlTermsArray.length;i++)
		{
			var tagThisTerm = true;
			
			//Loop over unwanted tagging values
			for(x=0;x<valuesToRemove.length;x++)
			{
				//we dont want to loop if we have already matched everything in out unwanted list
				if(valuesToRemove.length > unwantedMatchCount)
				{
					//if we find a match we do not want to tag this,
					if(urlTermsArray[i].toLowerCase().indexOf(valuesToRemove[x].toLowerCase()) != -1)
					{
						var tagThisTerm = false;
						unwantedMatchCount++;
					}		
				}
			}
			
			// populate the clean array if there was not a match found
			if(tagThisTerm)
			{
				cleanData.push(urlTermsArray[i])
			}
			
			//Manipulate the NTPT_PGEXTRA variable to contain our 'clean' string, 
			//this is what is used by net tracker to store user defined variables
			NTPT_PGEXTRA = cleanData.join('&');
		}
	},

	/*
	* Reset the NTPT_PGEXTRA back to the initial page landing value
	*/
	NIDataReset: function()
	{	
		NTPT_PGEXTRA = NTPT_PGEXTRA_STORE;	
	},
	
	NISplashScreenPath : function (choice){
		this.tag('COMPATIBLE/&COMPATIBLE='+ choice);
	}	
}
);

