////////////////////////////////////////////////////////////////////////////////////////////////////////////
// determines what server we are on so as to call the proper google code 

var thisServer  = window.location.hostname;

var googleCert = '';

if (thisServer == 'lexus2.freeflight.it.devlin.ca') {
	googleCert = 'ABQIAAAAShc3sokCAXRlI2avqYje-BTR3YC8Dq74MfUkhPB3pRPdqO956hRZXbDY4KGa6RyTOrikvsgZo6S5eA';

} else if (thisServer == 'lexus1.freeflight.it.devlin.ca') {
	googleCert = 'ABQIAAAAShc3sokCAXRlI2avqYje-BQ9x9XyPX1VOlRSbz6sQFpVle-VChTfgU-CStgUkC9U62oxcoX7pzOA2w';

}else if (thisServer == 'mnt.lexus.seth.it.devlin.ca') {
	googleCert = 'ABQIAAAAShc3sokCAXRlI2avqYje-BRXKpRJwOeX_vyAsCd_jgp_gXLT9BT135qtIfhOPnmuwyU_mP-DT3PGPQ';
	
}else if (thisServer == 'pubmnt.staging.lexus.ca') {
	googleCert = 'ABQIAAAAShc3sokCAXRlI2avqYje-BRgKWPc00xFr_mkXrTuRGalc0mdtBQltajAW67NwecAiK4PWM9N7e-hiQ';
	
}else if (thisServer == 'www.lexus.ca') {
	googleCert = 'ABQIAAAAShc3sokCAXRlI2avqYje-BTyp2hKK9Q84EL266Pnauhb_cnWUxTNFLZnCztq25PH0Lw82ZENl7qmsg';
	
}else if (thisServer == 'www.lexus.ca') {
	googleCert = 'ABQIAAAAShc3sokCAXRlI2avqYje-BTyp2hKK9Q84EL266Pnauhb_cnWUxTNFLZnCztq25PH0Lw82ZENl7qmsg';
	
}else if (thisServer == 'ali.lexus.ca') {
	googleCert = 'ABQIAAAAcL9DwNJe8pvaIAdxwrPCoRRu6mNaNCL3sJ2rvykH3hyA4NPrXhT0RvKW_XEhRc0lZSw_QSgaLBDw_Q';
	
}	

// this script calls the appropriate code from Google for the base address
var googleCodeCall = '<scr'+ 'ipt src="http://maps.google.com/maps?file=api&amp;v=2&amp;&sensor=true&amp;key=' + googleCert + '"  type="text/javascript"></scr' + 'ipt>';

// constract and return Lexus icon for google map marker
function getLexusGMIcon() {
			
	var toyIcon = new GIcon();
	toyIcon.image = "/images/gmaps/icon_logo.png";
	toyIcon.shadow = "/images/gmaps/icon_shadow.png";
	toyIcon.iconSize = new GSize(29, 31);
	toyIcon.shadowSize = new GSize(38, 31);
	toyIcon.iconAnchor = new GPoint(15, 31);
	toyIcon.infoWindowAnchor = new GPoint(15, 1);
	
	return toyIcon;
			
}

	function pinPointOnMap(dealer,address,language) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
           /*   alert(address + " not found"); */
            } else {
             
              var marker = new GMarker(point, getLexusGMIcon());
              map.addOverlay(marker);
              GEvent.addListener(marker, "click", function() {
			  marker.openInfoWindowHtml(createGoogleMapToolTip(dealer,language));
              });
            }
          }
        );
      }
    }
	
	function createGoogleMapToolTip(dealer,language){
		var moreinfo,tohere,fromhere,getdirection;
		if (language == 'en' ) {moreinfo='more info';tohere='To here'; fromhere='From here'; getdirection='Directions:';}
	else {moreinfo="Plus d'info"; fromhere="À partir d'ici"; tohere="Vers ce lieu";getdirection='Directions:';}
		var content = "<table width='470'><tr valign='top'><td width='200'>" +
			"<p align='left'><br/>" +
			"<b>" + dealer.name + "</b>" +
			"<br/>" + dealer.street +
			"<br/>" + dealer.city + ", " + dealer.province + " " + dealer.postalcode +
			"<br/>" + dealer.phone + 
			"<br/><a href='" + dealer.url + "'>" + moreinfo +
			"</p></td>" +
			"<td width='270'><img src='" + dealer.logo + "'/></td></tr></table>" + 
			"<br/>" +
			"<p align='left'>" + getdirection +
			"<a href='http://maps.google.com/maps?saddr=&amp;daddr=" + dealer.address + "' target='_blank'>" + tohere + "</a>" +
			" - " +
			"<a href='http://maps.google.com/maps?daddr=&amp;saddr=" + dealer.address + "' target='_blank'>" + fromhere + "</a>" +
			"</p>";
		
		return content;
	}
	
	
	function getProvinceLatLang(province){
			if (province == 'bc'){
			return new GLatLng(51.80861475198521, -122.2998046875);
		}else if (province == 'ab'){
			return new GLatLng(53.93021986394, -116.5869140625);
		}else if (province == 'sk'){
			return new GLatLng(54.1109429427243, -106.0400390625);
		}else if (province == 'mb'){
			return new GLatLng(53.74871079689897, -98.8330078125);
		}else if (province == 'on'){
			return new GLatLng(47.87214396888731, -82.2216796875);
		}else if (province == 'qc'){
			return new GLatLng(49.66762782262192, -66.796875);
		}else if (province == 'vav'){
			return new GLatLng(49.26421999734763, -123.02833557128906);
		}else if (province == 'son'){
			return new GLatLng(42.819580715795915, -80.9747314453125);
		}else if (province == 'gta'){
			return new GLatLng(43.71354951931429, -79.5684814453125);
		}else if (province == 'otw'){
			return new GLatLng(45.424479725192086, -75.65803527832031);
		}else if (province == 'mon'){
			return new GLatLng(45.50249699389712, -73.5919189453125);
		}else if (province == 'qbc'){
			return new GLatLng(46.81556855321453, -71.20582580566406);
		}else if (province == 'eon'){
			return new GLatLng(44.866236875162335, -76.4044189453125);
		}else {
			return new GLatLng(45.29034662473613, -62.9296875);
		}
	}
	
	


