hld_documentReady("vehicleRangeTracking");
function vehicleRangeTracking()
{
	// expects the enclosing page specifies the hld_vehicle javascript variable
	var modelName = hld_vehicle;

	if(modelName==null){
		// only if hld_vehicle is not specified do we use this hack
		modelName = whiteSpace($(".breadcrumbs > ul > li:last").html());
	}
	shoppingToolsAnalytics(modelName); // depends on shoppingTools.js
	promotionTracking(modelName);
	 
	addGoogleClickEvent(".breadcrumbs > ul > li > [@href$='/home']", "Homepage", "Breadcrumb Navigation", modelName);
	addGoogleClickEvent(".breadcrumbs > ul > li > [@href$='/vehicles']", "Vehicle Showroom", "Breadcrumb Navigation", modelName);
	
	// The models themselves
	$(".modelTileLast > a").click(function()
	{
		vehicleModelTrackingClick(this, modelName);
	});
	
	$(".modelTile > a").click(function()
	{
		vehicleModelTrackingClick(this, modelName);
	});
}

function vehicleModelTrackingClick(object, modelName)
{
	var arr = $(object).children("img:first").attr('alt');
	hld_trackEventClick(arr, modelName.replace(' Range', ''), "");
	var thisClass = $(object).attr('class');
	if(thisClass.indexOf("externalPopup") > -1) // This is a special case for the cruze, remove once in CMS
	{
		showInPopupWindow(object.href);
		return false;
	}else
		return true;
}

function whiteSpace(value)
{
     value = value.replace(/^\s*|\s*$/g,'');
	 return value;
}


