$(document).ready(
	function() {
	//function used to update the selected model count shown to the user
	
	var peListControl = $("div.mp-list-control");
	var peControlData = peListControl.children("select")[0];
	var container = $("div.container-model-items.mp-list-control");
	var selectedModelsCount = 0;	

	for(var i=0; i < container.find("div.item-model").length; i++)
	{
		for(var j=1; j < peControlData.options.length;j++) 
		{
			var optionText = peControlData.options[j].text;
			//var divTitle = container.find("div.item-model")[i].title;
			var divTitle = container.find("div.item-model")[i].title.replace(/Fiat /g,"");						
			//if(divTitle.indexOf(optionText) > 0)
			if(optionText == divTitle)
				peControlData.options[j].selected = true;
			//if(divTitle.)
		}			
	}
	
	var newpeControlData = peListControl.children("select")[0];

	
	if(typeof(newpeControlData) != "undefined")
	{
		//Loop through each of our options and set the state of our checked/unchecked element.
		for(var i=1; i < newpeControlData.options.length;i++) 
		{
			if(newpeControlData.options[i].selected) 
				selectedModelsCount++;		
		}
	}
	
	//update the selected models count
	$('li.selected-models h3 a span').html('(' + selectedModelsCount + ')');
	
	//Update the alt text on vehicle images
	var divItem = $("div.search-result-item");
		var imgAnchor = divItem.find("a.vehicle-image-link");
		
		for(var i=0; i<imgAnchor.length; i++)
		{
			if(imgAnchor[i].title.indexOf('front') < 0)
			imgAnchor[i].title += ' front image';
		}

	
	});
