$(document).ready(function() {//create the nameValueCollection used to store the client data dictionary items$.glossary = new NameValueCollection();//populate the datadictionarypopulateglossary();//insert any glossary wrappers that are neededinsertGlossaryTags($(document));});//function used to populate the glossary nameValueCollection
function populateglossary() {$.glossary.add('FULL TIME SYMETRICAL ALL-WHEEL DRIVE','This unique system sees the transmission, transfer and rear differential in a straight line behind the engine for bilateral balancing and outstanding handling');$.glossary.add('HILL HOLDER CLUTCH','The Hill Holder Clutch is a mechanical system that holds the vehicle for as long as your foot is on the clutchProdrive Performance Packs combine an ECU upgrade with a modified exhaust system to provide both an increase in power and torque');$.glossary.add('ISOFIX CHILD SEAT MOUNTINGS','ISOFIX anchors allow the easy and firm installation and removal of child and baby seatsFlagship MPV blends opulence and driveability');$.glossary.add('MULTI MODE DRIVERS CONTROL CENTRE ','It is an electromagnetic system that determines how “stiff” the centre differential is. The centre differential determines how much of the torque and power is transmitted to the front and rear wheels. DCCD can be used to favour straight line stability (on poor driving conditions) or enhance agility on winding roads');$.glossary.add('PPP','Prodrive Performance Packs combine an ECU upgrade with a modified exhaust system to provide both an increase in power and torque');$.glossary.add('Proven','<p>Proven cars, purchased from any participating Subaru dealer, will be prepared to the same exacting standards that have helped Subaru and its dealers deliver award-winning standards of customer care, again and again and again.</p><h2>All Subaru Proven vehicles have:</h2><p><span>- Rigorous pre-sales inspection </span><br /><span>- Minimum of 1 years comprehensive warranty</span><br /><span>- 12 months extendable home &amp; roadside assistance </span><br /><span>- 1 years Subaru European assistance </span><br /><span>- Full provenance check </span><br /><span>- Vehicle mileage certificate </span><br /><span>- A thorough road test, prior to hand-over </span><br /><span>- 30 day / 1000 mile exchange commitment. Conditions apply </span><br /><span>- No more than 80,000 miles on the clock (or less than 7 years old)</span><br /></p>');$.glossary.add('ProvenExtended','<p>Proven cars, purchased from any participating Subaru dealer, will be prepared to the same exacting standards that have helped Subaru and its dealers deliver award-winning standards of customer care, again and again and again.</p><h2>All Subaru Proven vehicles have:</h2><p><span>- Rigorous pre-sales inspection </span><br /><span>- Minimum of 1 years comprehensive warranty </span>&gt;<br /><span>- 12 months extendable home &amp; roadside assistance </span><br /><span>- 1 years Subaru European assistance </span><br /><span>- MOT Insurance</span><br /><span>- Full provenance check </span><br /><span>- Vehicle mileage certificate </span><br /><span>- A thorough road test, prior to hand-over </span><br /><span>- 30 day / 1000 mile exchange commitment. Conditions apply </span><br /><span>- No more than 80,000 miles on the clock (or less than 7 years old)</span><br /></p>');$.glossary.add('SI DRIVE','Choose from three modes to suit your driving style. "Intelligent" provides the best economy, "Sport" delivers a linear response in the widest range of conditions and "Sport Sharp" is the choice for instant throttle');$.glossary.add('Six Star','The Six Star Approved mark guarantees that this vehicle has received a comprehensive mechanical and electrical pre delivery check and will be supplied with at least a year’s ALL MECHANICAL and ELECTRICAL parts included warranty. Six Star Approved – round the clock protection for the road ahead. <br /><br /><strong>All Six Star Approved vehicles benefit from:<br /></strong>Minimum of 12 months extendable warranty <br />Rigorous pre-sale inspection <br />Thorough Road Test Prior to Handover <br />Vehicle Mileage Check <br />Optional home, roadside recovery &amp; assistance');$.glossary.add('SportShift','SportShift is a transmission system designed by Prodrive. It is a fully automatic gearbox that can be used in manual mode allowing the driver to select the appropriate gear manually by pushing or pulling on the gear lever');$.glossary.add('Subaru Direct Stock','<div>This vehicle is currently with Subaru (UK) Ltd and can be purchased (subject to availability) from any authorised Subaru Direct Dealer of your choice.</div><br /><div>Your supplying Dealer will prepare all cars to Proven standards as detailed on this website.</div>');$.glossary.add('Forester','Subarus stylish SUV perfectly blends form and function');$.glossary.add('Impreza','Safe, practical and with a choice of body styles. Engine sizes from 1.5 to 2.5 litre turbo');$.glossary.add('Justy','Nippy, economical and chic');$.glossary.add('Legacy Saloon','Luxurious comfort plus outstanding ride and handling');$.glossary.add('Legacy Sports Tourer','Fantastic load-lugging plus a superb drive and high specification');$.glossary.add('Outback','Increased ground clearance for go-anywhere performance');$.glossary.add('Tribeca','Flagship MPV blends opulence and driveability');$.glossary.add('SUBARU VEHICLE DYNAMICS CONTROL ','A three mode system which integrates Vehicle Dynamics, Traction and ABS to assist when driving in hazardous conditionsThis unique system sees the transmission, transfer and rear differential in a straight line behind the engine for bilateral balancing and outstanding handling');    
}//function used to insert our glossary tags
function insertGlossaryTags(container) {container.find('.pe-glossary-finder').each(function() {for(var i=0;i<$.glossary.names.length;i++) {//ok we need to switch this based on whether there are any html tags present//if theres no inner html then this is a simple string match, if there is html//present we need to be more careful as we need to ensure that we dont match the//text within any html attributesvar containsHtml = ($(this).html().search('<.[^>]*>') > -1);	//regex to match html tagsvar index;if(containsHtml) {index = $(this).html().search('>[^<]*' + escapeGlossaryName($.glossary.names[i]) + '[^<]*<');if(index > -1) {var middleIndex = index + $(this).html().substring(index).indexOf($.glossary.names[i]);var glossaryLength = $.glossary.names[i].length;var html = addInGlossary(middleIndex,glossaryLength,$(this).html());$(this).html(html);}}else {index = $(this).html().search('[^<]*' + $.glossary.names[i] + '[^<]*');if(index > -1) {var glossaryPosition = $(this).html().indexOf($.glossary.names[i]);var glossaryLength = $.glossary.names[i].length;var html = addInGlossary(glossaryPosition,glossaryLength,$(this).html());$(this).html(html);}}}		});
}//function used to escape the glossary names to form valids regex
function escapeGlossaryName(rawval) {var retval = rawval;retval = retval.replace('(','[(]');retval = retval.replace(')','[)]');return retval;
}//function used to return some glossaryized html
function addInGlossary(glossaryPosition, glossaryLength, html) {	// Encapsulate '()'svar gPos, gLen;gPos = new Number(glossaryPosition);gLen = new Number(glossaryLength);if ((html.substring(glossaryPosition-1,glossaryPosition)=='(') &&(html.substring(glossaryPosition + glossaryLength,glossaryPosition + glossaryLength+1)==')')){gPos--;gLen++;}var preHtml = html.substring(0,gPos);var postHtml = html.substring(gPos + gLen);var glossaryTerm = html.substring(gPos,gPos + gLen);return preHtml + '<span class="help glossary-term">' + glossaryTerm + '</span>' + postHtml;	
}