var curpoint=null;
function centerAndZoom()
{
	map.setCenter(new GLatLng(lalo[defaultLoc].lat,lalo[defaultLoc].lng), defaultZoom,0);
	plotRed(defaultZoom)
}

function centerMap()
{
	map.setCenter(new GLatLng(lalo[defaultLoc].lat,lalo[defaultLoc].lng))	
}

function zoomAndCenter(zomi)
{
	map.setCenter(new GLatLng(lalo[defaultLoc].lat,lalo[defaultLoc].lng), zomi,0);		
}

function panMap(where)
{
	var w=0,h=0;
	switch(where)
	{
		case 'left': 	w = 100;	break;
		case 'top':		h = 100;	break;
		case 'right':	w = -100;	break;
		case 'bottom':	h = -100;	break;
	}
	map.panBy(new GSize(w,h));			
}

function showSearch()
{
 	var su = document.createElement('div');
	su.className = 'search'; 
	su.id = 'locdiv'
	su.innerHTML = document.getElementById('searchdiv').innerHTML
	locationcopy = su.innerHTML
	document.getElementById('searchdiv').parentNode.removeChild(document.getElementById('searchdiv'));
	document.getElementById("mappu").appendChild(su);
	plotRed(defaultZoom)
}
//tim = window.setInterval("showSearch()",500);
function mapit ()
{

	if (GBrowserIsCompatible()) {
	  
		 map = new GMap2(document.getElementById("mappu"));
		 GEvent.addListener(map,'load', function() { if(window.showRoad)showRoad();} );
//		map.addControl(new GLargeMapControl());
//		map.addControl(new GMapTypeControl(3));	

		if(window.ccenter)
			map.setCenter(new GLatLng(ccenter[0],ccenter[1]), defaultZoom,0);			
		else
			map.setCenter(new GLatLng(lalo[defaultLoc].lat,lalo[defaultLoc].lng), defaultZoom,0);	
		
		var blueIcon = new GIcon(G_DEFAULT_ICON);
		blueIcon.image = "images/marker.png";
//		blueIcon.iconSize = new GSize(27, 37);
	
                
		// Set up our GMarkerOptions object
		markerOptions = { icon:blueIcon };		
		
		var i;
		for(i=0;i<lalo.length;i++)
		{
//			alert(lalo[i].lat)
			pt[i] = [];
			pt[i] = new GMarker(new GLatLng(parseFloat(lalo[i].lat),parseFloat(lalo[i].lng)), markerOptions)
			pt[i].place = lalo[i].name
			pt[i].idx = i
			
			if(window.hy) { pt[i].notes = []; pt[i].notes = hy[i]; } // only for index page - Pine BLVD.
			
			map.addOverlay(pt[i]);	
			GEvent.addListener(pt[i], "click", function()
			{ 
				curpoint = this.idx
				
				//Only for index page  - Pine BLVD.
				if(window.hy)
				{
					var di = '<div style="100px;">BCT Routes:<br>';
					for(var k=0;k<this.notes.length;k++)
					{
	//					di += "<a href='"+this.notes[k].link+"'>" + this.notes[k].rno + "</a>";
						di += "<a href='"+this.notes[k].link+"' target='_blank'>"+this.notes[k].rno+"</a>";
						if(k<this.notes.length-1)di+=',&nbsp;';
					}
					di += '</div>';
				}
				
				var bod = "<div style='color:black;'>"+ this.place+"</div>"
				
				//Only for index page  - Pine BLVD.				
				if(window.hy)
				{
					if(this.notes.length)				
						bod += "<br>" + di
				}
					
				bod += "<br><span style='font:12px arial; color:#1069BD; text-decoration:underline; cursor:pointer;' onclick='doDirect()'>Get Directions to this location</span>";
				
				map.openInfoWindow(this.getLatLng(),bod);
			}); 
			
			GEvent.addListener(map, "zoomend", function(oz,nz)
			{
//				window.location.hash = nz
				if(nz%2)nz--;
				plotRed(nz);
			});
			
/*			GEvent.addListener(pt[i], "mouseup", function() 
			{ 
				map.closeInfoWindow();
			}); 

		GEvent.addListener(map,'click',function(overlay,point)
		{
			window.location.hash = point.lat() + ', ' + point.lng()
		});
*/
		}
	}
	plotRed(defaultZoom)
} 
function gzoom(step)
{
	var curzoom = map.getZoom() + (step)
	if(curzoom==21)curzoom =22;
	if(curzoom>22)curzoom = 22;
	if(curzoom<0)curzoom = 0;

//	zoomAndCenter(curzoom)
//	map.setZoom(curzoom);
	map.setCenter(map.getCenter(),curzoom,0);
//	centerMap();
	plotRed(curzoom)
}

function zoomMap(val)
{
//	map.setZoom(val*2);
	map.setCenter(map.getCenter(),val*2,0);	
	plotRed(val*2);
//	map.zoomIn();
}

function plotRed(curzoom)
{
	var ch = document.getElementById('zoommain')
	var so = ch.getElementsByTagName('a')

	for(var i=1;i<12;i++)
		so[i].className = '';
	
	for(var i=1;i<=curzoom/2;i++)
	{	
		so[i].className = 'active';
	}
	
}


document.onclick = function(e)
{
	var so = getEventSource(e)
	if(so.id=='deczoom' || so.id=='inczoom')return false;
	if((so.id.indexOf('boom')+1))
	{
		var val = so.id.replace('boom','');
		zoomMap(val);
//		centerMap();
//		zoomAndCenter(val*2);
		plotRed(val*2);		
		return false;
	}
	if(so.alt=='Close' && so.className=='close')document.getElementById('locdiv').style.display = 'none'
}

function getEventSource(e) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	return targ;
}

function trim(str, chars) {

    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


function doSearch()
{
	var sto = document.getElementById('whery')
	sto.value = trim(sto.value)	
	var str = sto.value
	if(str=='' || str=='Enter your address here')return;
	
	document.getElementById('dpanel').innerHTML ='';
	map.clearOverlays();
	var directions;
	directionsPanel = document.getElementById("dpanel");   
	directions = new GDirections(map,directionsPanel); 
	directions.load(sto.value + " to " + lalo[curpoint].lat + ", " + lalo[curpoint].lng);
	document.getElementById('dpanelmain').style.display='block'
}

function font_size(siz)
{
	var so = document.getElementById('conte')
	so.style.fontSize = siz + 'px'
	var ko = document.getElementById('sivapu')	
	ko.style.fontSize = siz + 'px'
	var wa =  document.getElementById('waru')	
	wa.style.fontSize = siz + 'px'
/*	
	var now
	var hi = ['p','div','span'];
	
	for(var i=0;i<hi.length;i++)
	{
		now = so.getElementsByTagName(hi[i])
		for(j=0;j<now.length;j++)
			now[j].style.fontSize = siz + 'px'
	}
*/	
}

/*
var road = [
[26.009111565460977, -80.24793863296509],
[26.01005650371862, -80.20768404006958],
[26.01045183277434, -80.1850837469101],
[26.010377106042643, -80.1848503947258],
[26.010042040435255, -80.18474847078323],
[26.009870891446734, -80.18462777137756],
[26.0093719063521, -80.18373191356659],
[26.009468328757876, -80.18314719200134],
[26.00994079740175, -80.18252491950989],
[26.010471117084453, -80.18224596977234],
[26.010895371106116, -80.16691446304321],
[26.00183142904886, -80.16680717468262],
[25.997357055112136, -80.16607761383057],
[25.982158340367487, -80.16564846038818],
[25.97725884342716, -80.1661205291748],
[25.968578131107414, -80.16539096832275],
[25.96402532366635, -80.1657772064209],
[25.96062989495858, -80.16762256622314],
[25.95522787464757, -80.17573356628418],
[25.94751027270057, -80.1851749420166],
[25.94361269147243, -80.1875352859497],
[25.939329062326514, -80.19240617752075],
[25.937148596669015, -80.19736289978027],
[25.933694502094593, -80.20163297653198],
[25.931957768239897, -80.20403623580933],
[25.93081922882149, -80.20495891571045],
[25.930317496094162, -80.20510911941528],
[25.92867720111581, -80.20590305328369],
[25.92796318322817, -80.2063536643982],
[25.927114075244166, -80.2072548866272],
[25.925435139178102, -80.2092719078064],
[25.92487548850791, -80.20978689193726],
[25.92408425371583, -80.21036624908447],
[25.923389506592216, -80.21075248718262],
[25.922385975740063, -80.211181640625],
[25.92187455769255, -80.21150350570679],
[25.92077451890177, -80.21153569221497],
[25.92038853794594, -80.21201848983765],
[25.920330640693578, -80.21357417106628],
[25.920427136098404, -80.2138102054596],
[25.920576703819783, -80.21397650241852],
[25.920938560425324, -80.21408379077911],
[25.921305240652558, -80.21450757980347],
[25.921228044910027, -80.21573066711426],
[25.920263093863195, -80.21573066711426],
[25.920185897438245, -80.21534442901611],
[25.920137649646968, -80.21490454673767],
[25.920205196549233, -80.21246910095215],
[25.920205196549233, -80.21246910095215],
[25.920349939780852, -80.21138548851013],
[25.9201472992068, -80.21095633506775],
[25.91729099501283, -80.210280418396],
[25.902854020709665, -80.2100658416748],
[25.888492496799547, -80.20929336547852],
[25.870962893227773, -80.20852088928223],
[25.868182628981614, -80.20843505859375],
[25.845629179944932, -80.20740509033203],
[25.842462084108583, -80.20620346069336],
[25.830874425603092, -80.20594596862793],
[25.825002912217514, -80.20663261413574],
[25.814302102769407, -80.20609617233276],
[25.805512808712145, -80.2057957649231],
[25.80383214416206, -80.20588159561157],
[25.79191226454643, -80.2053451538086],
[25.79023140714392, -80.20491600036621],
[25.78845392282027, -80.20410060882568],
[25.78742992519011, -80.20358562469482],
[25.78700486697311, -80.20345687866211],
[25.78661844909013, -80.20338177680969],
[25.785903572687324, -80.20326375961304],
[25.785217673709663, -80.20290970802307],
[25.784531770765216, -80.20228743553162],
[25.783430453514477, -80.20148277282715],
[25.781817101886407, -80.2006995677948],
[25.780696437541074, -80.20039916038513],
[25.77974966113681, -80.2002489566803],
[25.778798046626477, -80.20016849040985],
[25.778798046626477, -80.19954085350037],
[25.778836691019272, -80.19788861274719],
[25.778923640856974, -80.19541025161743],
[25.778923640856974, -80.1952600479126],
[25.77876906332364, -80.19534051418304],
[25.776976915342953, -80.19526541233063],
[25.77602527859179, -80.19523859024048],
[25.775671432015564, -80.1953499019146],
[25.775526511611474, -80.19545316696167],
[25.775369514307304, -80.19554167985916],
[25.775033780913603, -80.19561409950256],
[25.775004796691178, -80.19625917077065],
[25.7749589049912, -80.19775584340096],
[25.77489489811685, -80.19858330488205],
[25.77481156836076, -80.19890651106834],
[25.77592624996348, -80.19931688904762],
[25.776149668093158, -80.19944161176682],
[25.776875472194877, -80.19946709275246],
[25.778823407010673, -80.1995462179184],
[25.77975569927558, -80.19959181547165],
[25.781666150948283, -80.19967496395111],
[25.781823139919936, -80.19968971610069],
[25.781981336288897, -80.19970715045929],
[25.78203326329532, -80.19971787929535],
[25.78215402368744, -80.19975140690804],
[25.7822131962347, -80.19978493452072],
[25.78230376640294, -80.19984930753708],
[25.782459546930525, -80.20003572106361],
[25.78260808166164, -80.20019397139549],
[25.78278680613219, -80.20034283399582],
[25.783091120151617, -80.20054668188095],
[25.783163575755445, -80.2006083726883],
[25.783248107237306, -80.20072773098946],
[25.783473926757726, -80.20086318254471],
[25.783857939714277, -80.20103886723518]
 ]			
 */
//var poli = new GPolyline(road,'',10,5);
//map.addOverlay(poli);

function showRoad()
{
	var polyline = [] 
	for(var i=0;i<road.length;i++)
		polyline[i] = new GLatLng(parseFloat(road[i][0]), parseFloat(road[i][1]) );
	map.addOverlay(new GPolyline(polyline,'#ff0000',5));
}

var mapd
function doDirect()
{
	$('#dpanelmain').css("left", ($(document).width() - $('#dpanelmain').width()) / 2  )	
	$('#dpanelmain').css("top", ($(document).height() - $('#dpanelmain').height()) / 2 )		
	$('#dpanelmain').show();
	showDMap();
}

function showDMap()
{
	if (GBrowserIsCompatible()) {
	  
		 mapd = new GMap2(document.getElementById("dmap"));

		mapd.addControl(new GLargeMapControl());
//		mapd.addControl(new GMapTypeControl(3));	
	
		mapd.setCenter(new GLatLng(lalo[curpoint].lat,lalo[curpoint].lng), 12,0);	
		
		var iconblue = new GIcon(G_DEFAULT_ICON);
		iconblue.image = "images/marker.png";
//		blueIcon.iconSize = new GSize(27, 37);
                
		// Set up our GMarkerOptions object
		markerOptions = { icon:iconblue };		
		
		var ovl = new GMarker(new GLatLng(parseFloat(lalo[curpoint].lat),parseFloat(lalo[curpoint].lng)), markerOptions)		
		mapd.addOverlay(ovl);			
	}
	document.getElementById('dirclk').style.display = 'none'
}

var dire=null;
function showDirectionRoad()
{
	var sto = document.getElementById('address')
	sto.value = trim(sto.value)
	if(sto.value=='')return;

	if(dire)dire.clear()
	direpanel = document.getElementById("dmapdir");
	direpanel.innerHTML =''
	dire = new GDirections(mapd,direpanel); 
	dire.load(sto.value + " to " + lalo[curpoint].lat + ", " + lalo[curpoint].lng);
	document.getElementById('dirclk').style.display = 'inline'

}

function toggledirs(os)
{
	if(os.innerHTML == 'Show Directions')
	{
		document.getElementById("dmap").style.display='none';
		document.getElementById("dmapdir").style.display='block';		
		os.innerHTML = 'Show Map'
	}
	else
	{
		document.getElementById("dmapdir").style.display='none';
		document.getElementById("dmap").style.display='block';		
		os.innerHTML = 'Show Directions'
	}
}

function closed()
{
	document.getElementById("dmapdir").style.display='none';
	document.getElementById("dmap").style.display='block';
	document.getElementById("dirclk").innerHTML = 'Show Directions'
	document.getElementById('dpanelmain').style.display='none'	
}

function testimonials()
{
//	$('#testy').centerScreen();	
	$('.testimonial').fadeIn(500);	
	
}

function close_testimonial()
{
	$('.modalOverLay').fadeOut(300);
	$('.testimonial').fadeOut(300);

}

