function getElementsByClass( searchClass, domNode, tagName) {
		if (domNode == null) domNode = document;
		if (tagName == null) tagName = '*';
		var el = new Array();
		var tags = domNode.getElementsByTagName(tagName);
		var tcl = " "+searchClass+" ";
		for(var i=0, j=0; i<tags.length; i++) {
			var test = " " + tags[i].className + " ";
			if (test.indexOf(tcl) != -1)
				el[j++] = tags[i];
		}
		return el;
	}
	
	function getLocTxt(locClass, parentObj){
		var els = new Array();
		els = getElementsByClass(locClass, parentObj);
		if(els.length > 0) {
			var elsObj = els[0];
			elsText = elsObj.firstChild.nodeValue; 
		} else {
			elsText = false;
		}
		return elsText;
	}
	
	function makeMapLink(obj) {
		var baseURL = "http://maps.yahoo.com/dd?";
		var addr = obj.street;
		var strReplaceAddr = addr;
		var intIndexOfMatch = strReplaceAddr.indexOf( " " );
		// Loop over the string value replacing out each matching substring.
		while (intIndexOfMatch != -1) {
			// Relace out the current instance.
			strReplaceAddr = strReplaceAddr.replace( " ", "+" )
			// Get the index of any next matching substring.
			intIndexOfMatch = strReplaceAddr.indexOf( " " );
		}
		var baseAddr = "taddr="+strReplaceAddr;
		var baseCsz = "&tcsz="+obj.city;
		if(obj.state) baseCsz += "%2C+"+obj.state;
		if(obj.zip) baseCsz += "+"+obj.zip;
		if(obj.country) {
			var baseCountry = "&tcountry="+obj.country;
		} else {
			var baseCountry = "";	
		}
		var mapLink = baseURL+baseAddr+baseCsz+baseCountry;
		return mapLink
	}
	
	function setMapLink(linkURL) {
		var mapA = document.getElementById('maplink');
		if(mapA) mapA.setAttribute("href",linkURL);
	}
	
	function locale(loc) { // pass ID of div that contains location; assumes one vcard div per location
		if(!document.getElementById) return false;
		var locObj = document.getElementById(loc);
		var vcards = new Array(); 
		vcards = getElementsByClass('vcard', locObj, 'div');
		if(vcards) {
			var vcard = vcards[0];
		} else {
			return false;
		}
		this.title = getLocTxt('fn', vcard);
		this.street = getLocTxt('street-address', vcard);
		this.street2 = getLocTxt('extended-address', vcard);
		this.city = getLocTxt('locality', vcard);
		this.state = getLocTxt('region', vcard);
		this.zip = getLocTxt('postal-code', vcard);
		this.country = getLocTxt('country-name', vcard);
		//evaluate if mappable
		if((!this.state && !this.zip) || (!this.state && !this.country)) return false;
		// get address string for mapping
		var addressTxt;
		if(this.street) addressTxt = this.street+", ";
		if(this.city) addressTxt += this.city+", ";
		if(this.state) addressTxt += this.state+" ";
		if(this.zip) addressTxt += this.zip;
		if(this.country) addressTxt += " "+this.country;
		this.address = addressTxt;
		// get work telephone AND fax text - checks all instances of tel elements for type 'work' and 'fax'
		var tels = new Array();
		tels = getElementsByClass('tel', vcard);
		if(tels.length > 0) {
			var telsObj;
			var telType;
			for(n=0; n<tels.length; n++) {
				telsObj = tels[n];
				telType = getLocTxt('type', telsObj);
				if (telType == 'Work' || telType == 'work') {
					this.tel = getLocTxt('value', telsObj);
					break;
				} else {
					this.tel = false;
				}
			}
			for(n=0; n<tels.length; n++) {
				telsObj = tels[n];
				telType = getLocTxt('type', telsObj);
				if (telType == 'Fax' || telType == 'fax') {
					this.fax = getLocTxt('value', telsObj);
					break;
				} else {
					this.fax = false;
				}
			}
		} else {
			this.tel = "";
		}
	}
	
	function initMap() {
		var mapEl = document.getElementById('map');
		var mapw = 420; // map dimensions
		var maph = 420;
		mapEl.style.display = "block";
		mapEl.style.width = mapw+"px";
		mapEl.style.height = maph+"px";
		var loc1 = new locale('loc1');
		// Create a Map that will be placed in the "map" div
		if(loc1) var map = new YMap(mapEl);
		startMap = function() {
			// Add the ability to change between Sat, Hybrid, and Regular Maps
			map.addTypeControl(); 	
			// Add the zoom control. Long specifies a Slider versus a "+" and "-" zoom control
			map.addZoomLong();    		
			// Add the Pan control to have North, South, East and West directional control
			map.addPanControl();  
			// Specifying the Map starting location and zoom level
			map.drawZoomAndCenter(loc1.address, 3);
			// Add an event to report to our Logger
			YEvent.Capture(map, EventsList.onEndGeoCode, setMarker);
			
			function setMarker(){
				var mapGeoCenter = map.getCenterLatLon();
				var newMarker= new YMarker(mapGeoCenter, createCustomMarkerImage(),'mapMarker');
				newMarker.addAutoExpand('<h2 class="markerTxt">'+loc1.title+'</h2>');
				var markerMarkup = '<div id="balloon">';
				markerMarkup += '<h3>'+loc1.title+'</h3>';
				markerMarkup += '<img src="../../images/map/mapthumb.jpg" height="40" width="40" />';
				markerMarkup += '<p>'+loc1.street+'<br />';
				if(loc1.street2) markerMarkup += loc1.street2+'<br />';
				markerMarkup += loc1.city;
				if(loc1.state) markerMarkup += ', '+loc1.state;
				if(loc1.zip) markerMarkup += ' '+loc1.zip;
				if(loc1.country) markerMarkup += ' '+loc1.country;
				if(loc1.tel) markerMarkup += '<br />Tel. '+loc1.tel;
				if(loc1.fax) markerMarkup += '<br />Fax '+loc1.fax;
				markerMarkup += '</p></div>';
				YEvent.Capture(newMarker, EventsList.MouseClick, 
					function(){
						newMarker.openSmartWindow(markerMarkup);
					});
				map.addOverlay(newMarker);
			}
			
			function createCustomMarkerImage(){
				var myImage = new YImage();
				myImage.src = '../../images/map/ct-marker.png';
				myImage.size = new YSize(30,33);
				myImage.offsetSmartWindow = new YCoordPoint(0,0);
				return myImage;	
			}
		}
		startMap();
		// Create map link
		if(loc1) var mapURL = makeMapLink(loc1);
		if(mapURL) setMapLink(mapURL);
	}
	
	window.onload =	initMap;