// Dynamic Breadcrumbs By Harry Love (http://harrylove.org/)
// License: http://creativecommons.org/licenses/by-sa/3.0/

function Breadcrumb() {
	// Begin customization
	this.homeLinkText = 	'Home'; 	// Text for the home link
	this.separator = 		' / ';		// Character(s) to use between breadcrumbs
	this.homeLinkPosition = 0;			// Where is home? 0 = domain, 1 = 1st directory, and so on ...
	this.attachTo = 		'#breadcrumbs';	// Attach breadcrumb to a tag or an ID: e.g., body, h1, div, #header, #breadcrumb
	this.replaceTheseCharacters = [		// You can replace any text with customized text
		[ "24-Bit" , "24-Bit" ],
		[ "alternative-energy-measurement" , "Alternative Energy" ],
		[ "Application Builder for Test and Measurement Systems - Measure Foundry" , "Application Builder for Test and Measurement Systems" ],
		[ "appnotes" , "Application Notes" ],
		[ "dataacquisition" , "Data Acquisition" ],
		[ "buy_now" , "Buy Now" ],
		[ "cd" , "CD" ],
		[ "channelpartners" , "Channel Partners" ],
		[ "company" , "Company" ],	
		[ " Data Acq " , "DAQ" ],
		[ " Data Acq. " , "DAQ" ],		
		[ "data-acquisition-modules" , "Data Acquisition" ],
		[ "data-acquisition-software" , "Data Acquisition Software" ],		
		[ "digital" , "Digital" ],
		[ "dsp" , "DSP" ],
		[ "dtmain" , "DT" ],		
		[ "emails" , "Emails" ],
		[ "environmental_control" , "Environmental" ],		
		[ "ethernet-temperature-and-voltage" , "Ethernet Temperature and Voltage" ],		
		[ "feeds" , "RSS Feeds" ],	
		[ "getacademic" , "Academic" ],
		[ " io" , "IO" ],
		[ "instrument_omni" , "Instrument Omni CD" ],
		[ "isa" , "ISA" ],
		[ "lowcost" , "Low Cost" ],		
		[ "Manufacturing - " , "" ],
		[ "MeasureFoundry" , "Measure Foundry" ],
		[ "measurefoundry" , "Measure Foundry" ],
		[ "Measure Foundry Brochure" , "Measure Foundry" ],
		[ "Measure Foundry: A Structured Introduction" , "A Structured Introduction" ],
		[ "Measure Foundry - Test and Measurement Software" , "Measure Foundry" ],
		[ "Multifunction USB Data Acquisition Modules" , "Multifunction" ],
		[ "Simultaneous High Speed USB Data Acquisition Modules" , "Simultaneous" ],
		[ "High Speed USB Data Acquisition Modules" , "High Speed" ],		
		[ "High Resolution USB Data Acquisition Modules" , "High Resolution" ],	
		[ "Analog Output USB Data Acquisition Modules" , "Analog Output" ],			
		[ "Digital I/O USB Data Acquisition Modules" , "Digital I/O" ],
		[ "Low Cost USB Data Acquisition Modules" , "Low Cost" ],
		[ "OEM Embedded USB Data Acquisition Modules" , "OEM Embedded" ],		
		[ "oem" , "OEM" ],
		[ "Online Store - " , "" ],
		[ "pci" , "PCI" ],
		[ "ISA Frame Grabbers" , "Frame Grabbers" ],	
		[ "multifunction" , "Multifunction" ],
		[ "PCI Frame Grabbers" , "Frame Grabbers" ],		
		[ "platinum" , "Platinum Support" ],
		[ "Platinum Support Request" , "Support Request" ],	
		[ "Product Marketing" , "Marketing" ],
		[ "Product Selection Chart - " , "" ],
		[ "productguide" , "Product Guide" ],
		[ "products", "Products" ],		
		[ "repfinder" , "Find Rep" ],
		[ "signal_conditioning" , "Signal Conditioning" ],
		[ "techref" , "Technical Reference" ],
		[ "temperature_uniformity" , "Temperature" ],
		[ "temppoint" , "TEMPpoint" ],
		[ "Technical Support - " , "" ],	
		[ "Test and Measurement Software - Measure Foundry" , "Measure Foundry" ],	
		[ "test-and-measurement-software" , "Test and Measurement Software" ],		
		[ "usb" , "USB" ],
		[ "usb_high_resolution" , "High Resoluton" ],
		[ "usb_high_speed_simultaneous" , "High Speed Simultaneous" ],
		[ "usb_multifunction" , "Multifunction" ],
		[ "usb_temperature" , "USB Temperature" ],		
		[ "usb_simultaneous" , "Simultaneous" ],
		[ "usb simultaneous" , "USB Simultaneous" ],		
		[ " USB DAQ Modules for Thermocouple Measurement" , "" ],
		[ "USB DAQ Modules - " , "" ],		
		[ "sound_vibration" , "NVH" ],
		[ "vibration" , "Vibration" ],
		[ "VOLTpoint - " , "" ],
		[ "voltpoint" , "VOLTpoint" ],		
		[ "whitepapers" , "White Papers" ],		
		[ " Data Acquisition Board " , "" ],
		[ " Frame Grabber" , "" ],	
		[ " from Data Translation" , "" ],
		[ " USB Data Acquisition Module" , "" ],
		[ " - Application Builder for Test and Measurement Systems - Test and Measurement Software" , "" ],
		[ " - Data Acquisition Products" , " " ],
		[ " - Data Acquisition Software" , "" ],		
		[ " - Data Acquisition Software - Data Translation" , "" ],
		[ " - Data Translation" , "" ],	
		[ " - Ethernet Data Acquisition" , "" ],
		[ " - Frame Grabber - Imaging Products" , "" ],
		[ " - Imaging Products" , "" ],
		[ " - Imaging Software" , "" ],
		[ " - ISA Frame Grabber" , "" ],	
		[ " - ISA Frame Grabbers" , "" ],
		[ " - PCI Frame Grabber" , "" ],	
		[ " - PCI Frame Grabbers" , "" ],
		[ " - Test and Measurement Software" , "" ],	
		[ " - Temperature and Voltage Measurement Solution" , "" ],		
		[ " - Ultra-Accurate Temperature Measurement Instruments" , "" ],
		[ " - Ultra-Accurate Temperature Measurement" , "" ],	
		[ " - USB Data Acquisition" , "" ],
		[ " - USB Data Acquisition Products" , "" ],
		[ " - USB Data Acquisition Modules" , "" ],
		[ " - USB DAQ - Data Acquisition Products" , " " ],
		["_", " "], // Replace underscores with spaces
		// ["-", " "], // Replace underscores with spaces		
	['','']];
	// End customization

	this.output = writeHTML;
	var homeText = this.homeLinkText;
	var sep = this.separator;
	var position = this.homeLinkPosition;
	var tag = this.attachTo;
	var replacements = this.replaceTheseCharacters;
	var d = document, text = url = d.location.href.split('//')[1];
	var title = d.title;
	url = url.split('/');
	if(url[url.length-1] == '') {url.pop();}
	url.pop();
	for (var i=0; i < replacements.length; i++) {
		rex = new RegExp(replacements[i][0], "g");
		text = text.replace(rex,replacements[i][1]);
		title = title.replace(rex,replacements[i][1]);
	}
	text = text.split('/');
	
	function createBreadcrumbs() {
		var href = '', a, div = d.createElement('div');
		div.setAttribute('id', 'breadcrumbs');
		for (var i = 0; i < url.length; i++) {
			href += url[i] + '/';
			if (i < position) {continue;}
			if (i == position) {text[i] = homeText;}
			text[i] = text[i].charAt(0).toUpperCase() + text[i].substr(1);
			a = d.createElement('a');		
			a.setAttribute('href', 'http://' + href);
			a.appendChild(d.createTextNode(text[i]));
			div.appendChild(a);
			div.appendChild(d.createTextNode(sep));
		}
		div.appendChild(d.createTextNode(title));
		return div;
	}
	
	function writeHTML() {
		tag = tag.match('#') ? d.getElementById(tag.substring(1)) : d.getElementsByTagName(tag)[0];
		if (tag) {
			tag.appendChild(createBreadcrumbs());
		}
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

addLoadEvent(function() {
	var crumb = new Breadcrumb();
	crumb.output();					  
});
// -->
