var imgClicked=0;
var myLocId=0;
var iBadTown=999;

var imgState=new Array();

var aryTownsReady=new Array(7,29);
var aryTowns=new Array(
new Array("Amawalk",2,58),
new Array("Ardsley",22,64),
new Array("Armonk",15,66),
new Array("Baldwin Place",2,73),
new Array("Bedford Hills",8,82),
new Array("Bedford Village",8,83),
new Array("Briarcliff Manor",13,87),
new Array("Bronxville",33,88),
new Array("Buchanan",5,89),
new Array("Chappaqua",10,97),
new Array("Cortlandt Manor",0,478),
new Array("Crompond",0,110),
new Array("Cross River",7,112),
new Array("Croton Falls",3,113),
new Array("Croton-on-Hudson",6,114),

new Array("Dobbs Ferry",27,121),
new Array("Eastchester",31,124),
new Array("Elmsford",20,128),
new Array("Goldens Bridge",7,149),
new Array("Harrison",23,157),
new Array("Hartsdale",19,158),
new Array("Hastings-on-Hudson",28,159),
new Array("Hawthorne",12,160),
new Array("Irvington",26,180),
new Array("Jefferson Valley",1,183),
new Array("Katonah",8,186),

new Array("Larchmont",37,189),
new Array("Lincolndale",2,192),
new Array("Mamaroneck",35,197),
new Array("Millwood",10,205),
new Array("Mohegan Lake",1,206),
new Array("Montrose",0,207),
new Array("Mount Kisco",11,210),
new Array("Mount Vernon",38,212),
new Array("New Rochelle",34,220),
new Array("North Salem",3,221),
new Array("North White Plains",15,222),
new Array("Ossining",14,807),

new Array("Peekskill",4,245),
new Array("Pelham",39,246),
new Array("Pelham Manor",40,247),
new Array("Pleasantville",16,258),
new Array("Pocantico Hills",21,392),
new Array("Port Chester",25,263),
new Array("Pound Ridge",9,264),
new Array("Purchase",23,273),
new Array("Purdys",3,274),
new Array("Rye",36,290),
new Array("Rye Brook",24,291),
new Array("Scarsdale",29,293),
new Array("Shenorock",2,299),
new Array("Shrub Oak",1,301),
new Array("Sleepy Hollow",17,304),
new Array("Somers",2,307),
new Array("South Salem",7,308),

new Array("Tarrytown",21,319),
new Array("Thornwood",12,325),
new Array("Tuckahoe",32,330),
new Array("Valhalla",12,332),
new Array("Verplanck",0,334),
new Array("West Harrison",23,584),
new Array("White Plains",18,338),
new Array("Yonkers",30,343),
new Array("Yorktown Heights",1,344)
);

var imgCoord=new Array(
//"Cortlandt",
new Array(8,43,new Array()),
//"Yorktown",
new Array(88,35,new Array()),
//"Somers",
new Array(144,24,new Array()),
//"North Salem",
new Array(212,12,new Array()),
//"Peekskill",
new Array(25,66,new Array()),
//"Buchanan",
new Array(2,93,new Array()),
//"Croton-on-Hudson",
new Array(7,137,new Array()),
//"Lewisboro",
new Array(198,63,new Array()),
//"Bedford",
new Array(166,87,new Array()),
//"Pound Ridge",
new Array(252,109,new Array()),
//"New Castle",
new Array(82,124,new Array()),
//"Mount Kisco",
new Array(164,141,new Array()),
//"Mount Pleasant",
new Array(86,190,new Array()),
//"Briarcliff Manor",
new Array(30,195,new Array()),
//"Ossining",
new Array(53,164,new Array()),
//"North Castle",
new Array(148,173,new Array()),
//"Pleasantville",
new Array(129,203,new Array()),
//"Sleepy Hollow",
new Array(29,243,new Array()),
//"White Plains",
new Array(139,280,new Array()),
//"Greenburgh",
new Array(87,268,new Array()),
//"Elmsford",
new Array(111,284,new Array()),
//"Tarrytown",
new Array(52,263,new Array()),
//"Ardsley",
new Array(95,319,new Array()),
//"Harrison",
new Array(163,270,new Array()),
//"Rye Brook",
new Array(196,275,new Array()),
//"Port Chester",
new Array(213,317,new Array()),
//"Irvington",
new Array(59,298,new Array()),
//"Dobbs Ferry",
new Array(33,320,new Array()),
//"Hastings on Hudson",
new Array(7,339,new Array()),
//"Scarsdale",
new Array(125,320,new Array()),
//"Yonkers",
new Array(37,351,new Array()),
//"EastChester",
new Array(119,352,new Array()),
//"Tuckahoe",
new Array(84,372,new Array()),
//"Bronxville",
new Array(80,388,new Array()),
//"New Rochelle",
new Array(127,351,new Array()),
//"Mamaroneck",
new Array(152,358,new Array()),
//"Rye",
new Array(188,345,new Array()),
//"Larchmont",
new Array(156,399,new Array()),
//"MountVernon",
new Array(97,402,new Array()),
//"Pelham",
new Array(122,406,new Array()),
//"Pelham Manor"
new Array(114,429,new Array())
);

var imgArea=new Array(
//"Cortlandt",
'"0,11, 82,0, 95,116, 74,119, 80,102, 74,102, 63,97, 57,98, 54,96, 45,95, 40,98, 35,97, 35,90, 18,86, 17,80, 8,72, 11,64, 19,64, 24,75, 34,69, 32,60, 39,60, 40,54, 54,47, 58,36, 62,34, 63,31, 44,22, 22,35, 0,19"',
//"Yorktown",
'"0,9, 56,0, 67,94, 74,117, 15,125"',
//"Somers",
'"0,11, 79,0, 81,27, 67,43, 66,53, 62,50, 56,51, 57,55, 62,62, 60,68, 56,70, 53,77, 48,77, 51,82, 39,92, 35,89, 34,96, 12,103"',
//"North Salem",
'"11,12, 90,0, 84,59, 71,55, 63,60,62,50, 0,57, 14,40, 11,33, 13,30, 9,17"',
//"Peekskill",
'"0,18, 26,0, 45,8, 45,12, 41,12, 38,24, 23,32, 22,36, 14,36"',
//"Buchanan",
'"0,9, 31,0, 39,13, 39,19, 32,24, 30,24, 28,17, 0,16"',
//"Croton-on-Hudson",
'"0,10, 46,0, 80,9, 76,15, 74,35, 68,35, 69,40, 57,52, 0,17"',
//"Lewisboro",
'"4,12, 11,14, 15,9, 76,0, 76,9, 86,5, 99,10, 100,16, 149,88, 127,101, 91,46, 55,48, 43,23, 0,38, 1,32, 7,30, 7,25, 9,23, 3,13"',
//"Bedford",
'"0,36, 29,16, 75,1, 105,76, 30,104, 24,89, 29,81, 24,74, 18,78, 24,58, 19,53, 10,59"',
//"Pound Ridge",
'"0,3, 38,0, 72,53, 72,56, 5,95, 1,63, 20,56"',
//"New Castle",
'"0,40, 81,28, 75,4, 83,0, 92,21, 88,30, 87,36, 89,40, 85,43, 86,44, 83,48, 94,52, 98,49, 99,45, 102,50, 107,50, 113,68, 87,94"',
//"Mount Kisco",
'"0,31, 7,23, 7,21, 6,21, 5,17, 5,14, 8,6, 14,5, 15,2, 16,3, 19,1, 19,0, 22,0, 23,4, 25,4, 19,25, 27,20, 30,26, 26,33, 21,32, 17,28, 14,34, 10,34"',
//"Mount Pleasant",
'"1,40, 21,44, 24,41, 27,43, 32,32, 36,34, 37,27, 35,17, 30,19, 27,17, 32,7, 31,4, 36,0, 56,12, 44,36, 53,39, 63,32, 67,38, 71,37, 68,33, 68,28, 63,28, 64,20, 61,16, 81,27, 80,37, 85,43, 68,79, 70,81, 62,92, 16,74, 16,58, 5,58, 5,52, 0,52, 0,43"',
//"Briarcliff Manor",
'"0,24, 60,23, 60,20, 62,18, 61,12, 61,10, 68,0, 79,4, 80,2, 85,2, 86,4, 83,12, 85,14, 87,14, 90,12, 91,13, 90,15, 93,19, 93,25, 91,28, 89,26, 84,37, 82,37, 81,36, 79,36, 78,38, 0,32"',
//"Ossining",
'"0,30, 29,0, 68,25, 63,34, 61,32, 56,32, 56,34, 54,34, 46,30, 37,41, 37,43, 39,45, 36,53, 34,53, 0,37"',
//"North Castle",
'"0,113, 1,106, 8,101, 8,97, 7,95, 18,73, 17,68, 24,61, 19,52, 20,45, 50,18, 104,0, 108,32, 33,78, 48,101, 42,101, 39,100, 39,96, 35,96, 32,100, 28,100, 25,96, 23,99, 20,96, 15,96, 15,104, 17,108, 13,109, 9,106, 5,111, 10,115, 9,121, 3,119"',
//"Pleasantville",
'"0,13, 0,7, 10,7, 14,0, 17,1, 18,5, 20,6, 21,8, 46,7, 46,14, 24,16, 25,18, 24,19, 24,21, 27,23, 27,24, 24,24, 20,18, 16,23, 13,24, 10,25, 8,24, 7,25, 2,22, 6,13"',
//"Sleepy Hollow",
'"0,10, 57,0, 61,0, 61,6, 72,5, 72,21, 71,21, 70,20, 66,20, 62,26, 54,26, 52,24, 0,17"',
//"White Plains",
'"0,32, 11,21, 9,19, 12,13, 16,13, 16,15, 18,15, 20,8, 18,6, 15,5, 15,3, 17,0, 19,0, 21,3, 23,3, 24,2, 26,2, 26,12, 29,14, 29,17, 23,26, 23,33, 34,34, 47,52, 47,56, 40,68, 36,68, 36,72, 32,75, 31,75, 29,69, 28,69, 23,64, 18,64, 2,38, 0,38"',
//"Greenburgh",
'"0,90, 8,71, 12,71, 13,68, 14,68, 18,73, 24,67, 23,66, 23,64, 28,59, 28,56, 24,51, 14,51, 20,34, 15,37, 10,32, 9,25, 15,26, 15,13, 17,1, 24,0, 60,15, 63,23, 58,39, 51,44, 51,51, 54,51, 52,59, 38,82"',
//"Elmsford",
'"0,1, 9,1, 9,0, 17,0, 34,1, 34,7, 20,8, 17,13, 13,13, 3,11, 2,10,  2,6, 3,6, 3,3, 0,3"',
//"Tarrytown",
'"0,15, 25,14, 43,0, 58,4, 51,6, 49,9, 49,30, 44,29, 45,36, 43,36, 41,34, 39,34, 37,36, 36,36, 34,34, 33,34, 31,36, 31,24, 0,22"',
//"Ardsley",
'"0,16, 6,1, 10,1, 11,0, 12,0, 20,3, 32,6, 32,12, 14,13, 14,16, 15,16, 15,17, 10,21, 6,16, 3,19, 0,19"',
//"Harrison",
'"1,0, 5,1, 5,2, 10,1, 12,4, 17,4, 21,0, 23,0, 23,5, 32,6, 33,13, 32,19, 36,22, 38,22, 41,26, 41,29, 40,33, 42,36, 42,47, 37,53, 40,55, 39,63, 41,69, 43,69, 47,72, 47,74, 44,74, 44,77, 28,94, 29,97, 30,97, 31,95, 33,95, 33,97, 29,106, 25,107, 16,103, 16,99, 13,97, 8,97, 7,86, 24,66, 10,43, 0,42, 0,36, 6,26, 6,23, 3,23, 3,11, 1,7"',
//"Rye Brook",
'"0,0, 1,0, 46,34, 46,40, 16,49, 16,69, 15,69, 15,66, 13,66, 10,63, 8,63, 7,57, 8,50, 5,48, 5,47, 10,42, 10,30, 8,28, 8,25, 9,24, 9,21, 0,14, 0,10, 1,8, 0,6"',
//"Port Chester",
'"0,7, 10,0, 60,17, 60,22, 10,35, 0,28"',
//"Irvington",
'"0,7, 21,7, 24,0, 28,0, 29,1, 31,1, 32,0, 36,0, 43,8, 47,5, 47,7, 42,21, 25,23, 20,23, 20,26, 0,14"',
//"Dobbs Ferry",
'"0,5, 67,0, 59,23, 0,12"',
//"Hastings on Hudson",
'"0,6, 69,0, 85,5, 80,19, 65,23, 0,12"',
//"Scarsdale",
'"0,29, 6,16, 15,4, 15,0, 17,0, 34,25, 42,28, 44,34, 44,37, 27,58, 22,30, 19,30, 19,32, 17,32, 14,36, 12,36, 12,39, 13,40, 13,42, 12,43, 11,43, 0,32"',
//"Yonkers",
'"0,56, 34,12, 87,0, 83,5, 86,8, 86,12, 74,34, 72,34, 66,58, 65,58, 54,78, 0,63"',
//"EastChester",
'"6,0, 18,14, 18,17, 12,24, 12,27, 13,28, 13,29, 12,30, 12,33, 14,33, 14,34, 9,41, 9,44, 9,49, 12,51, 10,53, 6,53, 6,52, 1,52, 1,50, 3,50, 0,34, 0,30, 3,23, 0,22, 0,19, 5,8, 2,4, 5,0"',
//"Tuckahoe",
'"2,5, 30,5, 34,0, 37,0, 38,1, 38,3, 37,3, 34,9, 34,12, 36,12, 36,13, 35,14, 31,14, 25,13, 2,11"',
//"Bronxville",
'"0,4, 28,0, 40,1, 42,11, 42,13, 39,13, 39,16, 26,12, 0,10"',
//"New Rochelle",
'"20,0, 28,60, 31,63, 34,63, 34,64, 32,67, 31,69, 29,67, 28,65, 27,67, 25,70, 25,72, 28,73, 26,75, 30,78, 21,89, 20,89, 12,89, 6,82, 2,55, 5,52, 0,48, 0,45, 7,33, 5,33, 5,30, 6,28, 4,28, 4,26, 10,17, 10,14, 9,14, 9,13, 11,11, 11,6, 12,6, 15,2, 18,2, 18,0"',
//"Mamaroneck",
'"0,20, 16,0, 17,0, 20,10, 26,11, 26,15, 36,21, 38,26, 38,30, 39,31, 68,38, 68,44, 26,51, 23,45, 20,45, 18,42, 16,42, 15,43, 13,43, 9,40, 8,40, 3,46, 3,51, 9,54, 9,55, 5,55, 3,53, 0,26"',
//"Rye",
'"0,33, 2,33, 7,27, 7,22, 8,21, 6,20, 4,22, 5,16, 16,4, 20,2, 20,0, 25,0, 35,8, 35,11, 34,12, 34,13, 36,15, 36,18, 39,17, 40,14, 38,12, 38,11, 40,11, 41,12, 41,16, 38,19, 39,22, 38,26, 36,26, 35,24, 34,26, 32,26, 31,25, 30,29, 27,32, 25,32,25,38, 22,42, 19,44, 21,45, 21,46, 17,46, 15,51, 14,51, 14,48, 20,35, 19,34, 11,44, 9,43, 8,45, 4,45"',
//"Larchmont",
'"0,5, 3,0, 6,0, 7,1, 8,1, 8,3, 11,3, 12,2, 14,2, 15,3, 15,5, 14,6, 14,10, 51,11, 51,17, 8,18, 8,16, 6,16, 6,12, 3,12, 0,10"',
//"MountVernon",
'"0,18, 8,2, 11,0, 13,0, 31,4, 29,5, 26,15, 24,15, 24,27, 22,29, 22,23, 21,23, 17,34, 17,36, 18,37, 9,33, 7,24, 0,22"',
//"Pelham",
'"0,23, 0,12, 5,0, 6,0, 9,22, 4,23"',
//"Pelham Manor"
'"13,0, 18,0, 18,3, 23,8, 25,12, 25,13, 20,23, 0,23, 1,8, 4,8, 6,6, 6,1, 12,1"'
);

function imgPlace(i,t){
document.write(
'<p><span style="position: absolute; left: '
 + (imgCoord[i][0]+iOffSetX) + 
'; top: '
 + (imgCoord[i][1]+iOffSetY) + 
'"><img src="'
 + imgCache[(i*2)+t].src + 
'" ID="btn'
 + i + 
'"></span></p>'
);
}


function mskPlace(){

urlPathParseArg();

iOffSetX=elementLeftPositionGet(document.getElementById("MapSpace"));
iOffSetY=elementTopPositionGet(document.getElementById("MapSpace"));

//munis
for(var i=0;i<(aCountyMapImg.length)/2;i++){
	imgState.push(0);
	imgPlace(i,0);}

//base
document.write('<div style="position: absolute; left: ' + iOffSetX + '; top: ' + iOffSetY + '">');

document.write('<img src="../img/sup/spacer.gif" width="350" height="468" USEMAP="#msk">');

document.write('<MAP NAME="msk">');
//maps
for(var i=((aCountyMapImg.length)/2)-1;i>=0;i--){
	var tmp=new Array();
	var strTmp=imgArea[i].substr(1,imgArea[i].length-2);
	tmp=strTmp.split(",");
	for(var j=0;j<(tmp.length);j=j+2){
		tmp[j]=parseInt(tmp[j])+parseInt(imgCoord[i][0]);
		tmp[j+1]=parseInt(tmp[j+1])+parseInt(imgCoord[i][1]);}
document.write(
'<AREA shape="poly" COORDS="'
 + tmp.join(",") + 
'" HREF=javascript:btnClick('
 + i + 
') onMouseOver="btnStatusSet('
 + i + 
'); return true;" onMouseOut="btnStatusOff('
 + i + 
');" NAME="msk'
 + i + 
'">'
);

}

//everything else
document.write('<AREA shape="rect" COORDS="0,0,350,468" HREF="javascript:btnClearAll();" NAME="mskRemain">');
document.write('</MAP>');
document.write('</div>');

	document.write('<div style="position: absolute; left: ' + (iOffSetX+220) + '; top: ' + (iOffSetY+240) + '">');
	document.write('<table border="2" cellpadding="2" cellspacing="0" bgcolor="#F3ECE4" CLASS="displayNone" ID="prmtList">');
	document.write('<tr><td>');
	document.write('<center><div class="promptText"><b>Click&nbsp;town&nbsp;from<br>list&nbsp;on&nbsp;right</b></div></center>');
	document.write('</td></tr>');
	document.write('</table>');
	document.write('</div>');
}

function btnClick(i){
	if(myLocId==0){
		btnClear();
		btnStatusSet(i);
		imgClicked=i+1;
		classChange(document.getElementById("prmtList"),"DisplayNormal");
	}else{
		top.location=location.protocol + "//" + location.host + location.pathname;// + "?loc=" + btnMnuEvent.arguments[1];
	}
}

function btnClear(){
	if(imgClicked!=0){
		var tmp=imgClicked-1;
		imgClicked=0;
		btnStatusOff(tmp);
	}
}

function btnClearAll(){
	classChange(document.getElementById("prmtList"),"DisplayNone");
	imgClicked=0;
	for(var i=0;i<imgState.length;i++)
		if(imgState[i]!=0)btnStatusOff(i);
}

function btnStatusSet(i){
    if(imgClicked==0){
	imgState[i]=1;
//	var elm=eval("btn" + i);
	var elm=document.getElementById("btn" + i);
	elm.src=imgCache[i*2+1].src;
	for(var j=0;j<imgCoord[i][2].length;j++)
	    classChange(document.getElementById("town"+imgCoord[i][2][j]),"townHighlight");
    }
    window.status="";
}

function btnStatusOff(i){
    if(imgClicked==0){
	imgState[i]=0;
//	var elm=eval("btn" + i);
	var elm=document.getElementById("btn" + i);
	elm.src=imgCache[i*2].src;
	for(var j=0;j<imgCoord[i][2].length;j++)
	    classChange(document.getElementById("town"+imgCoord[i][2][j]),"townNormal");
    }
    window.status="";
}

function classChange(element,newclass) {
	element.className = newclass;
}

function directPromptOff(){
	classChange(document.getElementById("DirectPrompt"),"DisplayNone");
}

function urlPathParseArg(){
var aMnuSrArg="";
	var iIx1=4+location.search.indexOf("msa=");
	var iIx2=4+location.search.indexOf("loc=");
	if(iIx1>4&&iIx2>4){
		if(iIx1<iIx2){
			aMnuSrArg=location.search.substring(iIx1,iIx2-5).split(",");
			myLocId=location.search.substr(iIx2);
		}else{
			myLocId=location.search.substring(iIx2,iIx1-5);
			aMnuSrArg=location.search.substr(iIx1).split(",");}
	}else{
		if(iIx1>4)aMnuSrArg=location.search.substr(iIx1).split(",");
		if(iIx2>4)myLocId=location.search.substr(iIx2);}
	if(iIx2>4){
			var iIxPg="000" + aryTowns[myLocId][2];
			iIxPg=iIxPg.substr(iIxPg.length-3,3);
			location.replace("./lnk/L" + iIxPg + "C042.html");
	}
}

function spacesRemove(string){
	var strTmp = "";
	splitstring = string.split(" ");
	for(i=0;i<splitstring.length;i++)
		strTmp += splitstring[i];
	return strTmp;
}


function btnMnuEvent(){
var strWk="";
// 0: Navigation
// 1: Search
// 2: Town
// 3: Links
// 4:
// 5:
// 6: 
// 7: Members
// 8: Advertising
// 9: About Us
var strWk="";
if(btnMnuEvent.arguments.length>1){
	for (var i=1;i<btnMnuEvent.arguments.length;i++)strWk=strWk + "," + btnMnuEvent.arguments[i];
	switch(btnMnuEvent.arguments[0])
	{
	case 0:{
		switch(btnMnuEvent.arguments[1])
		{
			case 1:{
				top.location="./index.html";
				break;
			}
			case 2:{
				historygo(-1);
				break;
			}
			default:{
				alert("Coming soon!");
				break;
			}
		}
		break;
	}	
	case 1:{
		var iIxPg="000" + btnMnuEvent.arguments[1];
		iIxPg=iIxPg.substr(iIxPg.length-4,4)
		top.location="lnk/Link" + iIxPg + ".html";
		break;
	}
	case 3,4:{
		var iIxPg="000" + btnMnuEvent.arguments[1];
		iIxPg=iIxPg.substr(iIxPg.length-3,3)
		top.location="lnk/L" + iIxPg + "C042.html";
		break;
	}
	case 2:{
		top.location=location.protocol + "//" + location.host + location.pathname + "?loc=" + btnMnuEvent.arguments[1];
		break;
	}
	default:{
		alert("Coming soon!");
		break;}
	}
}else{
	alert("Coming soon!");
}
}

function isTownReady(iTown){
var iState=false;
for(var i=0;i<aryTownsReady.length;i++)
	if(iTown==aryTownsReady[i]) iState=true;
	return iState;
}

function elementLeftPositionGet(e){
var x=0;
    while(e){
        x+=e.offsetLeft; //+e.clientLeft;
       if(e==document.getElementsByTagName('body')[0]){break}
       else{e=e.parentNode;}
    }
return x;
}

function elementTopPositionGet(e){
var y=0;
    while(e){
        y+=e.offsetTop; //+e.clientTop;
       if(e==document.getElementsByTagName('body')[0]){break}
       else{e=e.parentNode;}
    }
return y;
}


