var a_locBounds = new Array();
var a_loc_urls = new Array();	
a_loc_urls[1045] = 'http://nwctest.buysell.co.uk/location/north-wales/gwynedd/caernarfon/';
a_locBounds[1045] = new GLatLngBounds(
	new GLatLng( 		
		53.0990606112,
		-4.31834672651
	),
	new GLatLng( 
		53.1709993888,
		-4.20558056599
	)
);
a_loc_urls[1049] = 'http://nwctest.buysell.co.uk/location/north-wales/gwynedd/bangor/';
a_locBounds[1049] = new GLatLngBounds(
	new GLatLng( 		
		53.1487282639,
		-4.17714200659
	),
	new GLatLng( 
		53.2386517361,
		-4.03567219023
	)
);
a_loc_urls[1050] = 'http://nwctest.buysell.co.uk/location/north-wales/gwynedd/llanberis/';
a_locBounds[1050] = new GLatLngBounds(
	new GLatLng( 		
		53.0649059167,
		-4.21888984673
	),
	new GLatLng( 
		53.1728140833,
		-4.04948124748
	)
);
a_loc_urls[1051] = 'http://nwctest.buysell.co.uk/location/north-wales/gwynedd/criccieth/';
a_locBounds[1051] = new GLatLngBounds(
	new GLatLng( 		
		52.8926006112,
		-4.29492692099
	),
	new GLatLng( 
		52.9645393888,
		-4.18264146687
	)
);
a_loc_urls[1052] = 'http://nwctest.buysell.co.uk/location/north-wales/gwynedd/pwllheli/';
a_locBounds[1052] = new GLatLngBounds(
	new GLatLng( 		
		52.8524156112,
		-4.47552502882
	),
	new GLatLng( 
		52.9243543888,
		-4.36363989825
	)
);
a_loc_urls[1053] = 'http://nwctest.buysell.co.uk/location/north-wales/anglesey/holyhead-and-newlands-park/';
a_locBounds[1053] = new GLatLngBounds(
	new GLatLng( 		
		53.2341212223,
		-4.74964348974
	),
	new GLatLng( 
		53.3779987777,
		-4.52450457713
	)
);
a_loc_urls[1054] = 'http://nwctest.buysell.co.uk/location/north-wales/conwy/llandudno/';
a_locBounds[1054] = new GLatLngBounds(
	new GLatLng( 		
		53.2969704278,
		-3.87525333875
	),
	new GLatLng( 
		53.3473275722,
		-3.7954803426
	)
);
a_loc_urls[1055] = 'http://nwctest.buysell.co.uk/location/north-wales/conwy/colwyn-bay/';
a_locBounds[1055] = new GLatLngBounds(
	new GLatLng( 		
		53.2407222639,
		-3.76971024457
	),
	new GLatLng( 
		53.3306457361,
		-3.62708799115
	)
);
a_loc_urls[1056] = 'http://nwctest.buysell.co.uk/location/north-wales/conwy/penrhyn-bay/';
a_locBounds[1056] = new GLatLngBounds(
	new GLatLng( 		
		53.3031764792,
		-3.79844087859
	),
	new GLatLng( 
		53.3301535208,
		-3.75567381794
	)
);
a_loc_urls[1057] = 'http://nwctest.buysell.co.uk/location/north-wales/denbighshire/rhyl/';
a_locBounds[1057] = new GLatLngBounds(
	new GLatLng( 		
		53.2803406112,
		-3.53371800968
	),
	new GLatLng( 
		53.3522793888,
		-3.41916684456
	)
);
a_loc_urls[1058] = 'http://nwctest.buysell.co.uk/location/north-wales/denbighshire/ruthin/';
a_locBounds[1058] = new GLatLngBounds(
	new GLatLng( 		
		53.0743532639,
		-3.37731408425
	),
	new GLatLng( 
		53.1642767361,
		-3.23440651692
	)
);
a_loc_urls[1059] = 'http://nwctest.buysell.co.uk/location/north-wales/denbighshire/denbigh/';
a_locBounds[1059] = new GLatLngBounds(
	new GLatLng( 		
		53.1359782639,
		-3.4785136935
	),
	new GLatLng( 
		53.2259017361,
		-3.33561864785
	)
);
a_loc_urls[1060] = 'http://nwctest.buysell.co.uk/location/north-wales/gwynedd/harlech/';
a_locBounds[1060] = new GLatLngBounds(
	new GLatLng( 		
		52.8180666112,
		-4.16312024923
	),
	new GLatLng( 
		52.8900053888,
		-4.0508023116
	)
);
a_loc_urls[1061] = 'http://nwctest.buysell.co.uk/location/north-wales/gwynedd/porthmadog/';
a_locBounds[1061] = new GLatLngBounds(
	new GLatLng( 		
		52.8879559681,
		-4.19069819713
	),
	new GLatLng( 
		52.9724840319,
		-4.0585350287
	)
);
a_loc_urls[1062] = 'http://nwctest.buysell.co.uk/location/north-wales/flintshire/flint/';
a_locBounds[1062] = new GLatLngBounds(
	new GLatLng( 		
		53.1884082639,
		-3.20147936104
	),
	new GLatLng( 
		53.2783317361,
		-3.05783173332
	)
);
a_loc_urls[1063] = 'http://nwctest.buysell.co.uk/location/north-wales/flintshire/shotton/';
a_locBounds[1063] = new GLatLngBounds(
	new GLatLng( 		
		53.1703966112,
		-3.09564190591
	),
	new GLatLng( 
		53.2423353888,
		-2.98064078356
	)
);
a_loc_urls[1064] = 'http://nwctest.buysell.co.uk/location/north-wales/flintshire/holywell/';
a_locBounds[1064] = new GLatLngBounds(
	new GLatLng( 		
		53.2362682639,
		-3.29724686632
	),
	new GLatLng( 
		53.3261917361,
		-3.15364407115
	)
);
a_loc_urls[1065] = 'http://nwctest.buysell.co.uk/location/north-wales/gwynedd/abersoch/';
a_locBounds[1065] = new GLatLngBounds(
	new GLatLng( 		
		52.7858859167,
		-4.58920188606
	),
	new GLatLng( 
		52.8937940833,
		-4.42176813265
	)
);
a_loc_urls[1066] = 'http://nwctest.buysell.co.uk/location/north-wales/gwynedd/barmouth-and-fairbourne/';
a_locBounds[1066] = new GLatLngBounds(
	new GLatLng( 		
		52.6889736112,
		-4.11072810767
	),
	new GLatLng( 
		52.7609123888,
		-3.99864506053
	)
);
a_loc_urls[1067] = 'http://nwctest.buysell.co.uk/location/north-wales/anglesey/beaumaris/';
a_locBounds[1067] = new GLatLngBounds(
	new GLatLng( 		
		53.2363752639,
		-4.16965566363
	),
	new GLatLng( 
		53.3262987361,
		-4.0278897431
	)
);
a_loc_urls[1068] = 'http://nwctest.buysell.co.uk/location/north-wales/denbighshire/prestatyn/';
a_locBounds[1068] = new GLatLngBounds(
	new GLatLng( 		
		53.2826420903,
		-3.45710592834
	),
	new GLatLng( 
		53.3815579097,
		-3.29931367888
	)
);
a_loc_urls[1069] = 'http://nwctest.buysell.co.uk/location/north-wales/anglesey/llangefni/';
a_locBounds[1069] = new GLatLngBounds(
	new GLatLng( 		
		53.2146482639,
		-4.38335839571
	),
	new GLatLng( 
		53.3045717361,
		-4.2421118065
	)
);
a_loc_urls[1070] = 'http://nwctest.buysell.co.uk/location/north-wales/anglesey/amlwch-and-porthllechog/';
a_locBounds[1070] = new GLatLngBounds(
	new GLatLng( 		
		53.3668736112,
		-4.40414442828
	),
	new GLatLng( 
		53.4388123888,
		-4.29083951771
	)
);
a_loc_urls[1071] = 'http://nwctest.buysell.co.uk/location/north-wales/anglesey/benllech/';
a_locBounds[1071] = new GLatLngBounds(
	new GLatLng( 		
		53.2732592639,
		-4.29982466055
	),
	new GLatLng( 
		53.3631827361,
		-4.15821479028
	)
);
a_loc_urls[1072] = 'http://nwctest.buysell.co.uk/location/north-wales/anglesey/cernaes-and-llanfechell/';
a_locBounds[1072] = new GLatLngBounds(
	new GLatLng( 		
		53.3744866112,
		-4.51309809582
	),
	new GLatLng( 
		53.4464253888,
		-4.3999580059
	)
);
a_loc_urls[1073] = 'http://nwctest.buysell.co.uk/location/north-wales/anglesey/rhosneigr-and-gwalchmai/';
a_locBounds[1073] = new GLatLngBounds(
	new GLatLng( 		
		53.1931859167,
		-4.54694088013
	),
	new GLatLng( 
		53.3010940833,
		-4.37786993651
	)
);
a_loc_urls[1074] = 'http://nwctest.buysell.co.uk/location/north-wales/gwynedd/the-tip-of-the-peninsula/';
a_locBounds[1074] = new GLatLngBounds(
	new GLatLng( 		
		52.7717635695,
		-4.77539037388
	),
	new GLatLng( 
		52.8976564305,
		-4.58057300208
	)
);
a_loc_urls[1075] = 'http://nwctest.buysell.co.uk/location/north-wales/gwynedd/carmel-groeslon-and-penygroes/';
a_locBounds[1075] = new GLatLngBounds(
	new GLatLng( 		
		53.0372306112,
		-4.31792909152
	),
	new GLatLng( 
		53.1091693888,
		-4.20531854268
	)
);
a_loc_urls[1076] = 'http://nwctest.buysell.co.uk/location/north-wales/conwy/abergele/';
a_locBounds[1076] = new GLatLngBounds(
	new GLatLng( 		
		53.2496366112,
		-3.64088490482
	),
	new GLatLng( 
		53.3215753888,
		-3.52659431888
	)
);
a_loc_urls[1077] = 'http://nwctest.buysell.co.uk/location/north-wales/denbighshire/llanelwy-and-bodelwyddan/';
a_locBounds[1077] = new GLatLngBounds(
	new GLatLng( 		
		53.2026120903,
		-3.53171642257
	),
	new GLatLng( 
		53.3015279097,
		-3.37438430454
	)
);
a_loc_urls[1078] = 'http://nwctest.buysell.co.uk/location/north-wales/anglesey/llanfairpwllgwyngyll/';
a_locBounds[1078] = new GLatLngBounds(
	new GLatLng( 		
		53.1871786112,
		-4.25803800519
	),
	new GLatLng( 
		53.2591173888,
		-4.14494668742
	)
);
a_loc_urls[1079] = 'http://nwctest.buysell.co.uk/location/north-wales/conwy/conwy/';
a_locBounds[1079] = new GLatLngBounds(
	new GLatLng( 		
		53.2581152542,
		-3.85612856989
	),
	new GLatLng( 
		53.3174647458,
		-3.76214719235
	)
);
a_loc_urls[1644] = 'http://nwctest.buysell.co.uk/location/merseyside/liverpool/litherland/';
a_locBounds[1644] = new GLatLngBounds(
	new GLatLng( 		
		53.4560476058,
		-3.02036048963
	),
	new GLatLng( 
		53.4980778366,
		-2.95270275298
	)
);
a_loc_urls[1645] = 'http://nwctest.buysell.co.uk/location/merseyside/liverpool/maghull/';
a_locBounds[1645] = new GLatLngBounds(
	new GLatLng( 		
		53.4785525406,
		-3.0034953295
	),
	new GLatLng( 
		53.5350604504,
		-2.91243193726
	)
);
a_loc_urls[1646] = 'http://nwctest.buysell.co.uk/location/merseyside/liverpool/ormskirk/';
a_locBounds[1646] = new GLatLngBounds(
	new GLatLng( 		
		53.5293911865,
		-2.96834723551
	),
	new GLatLng( 
		53.6640246089,
		-2.75061903428
	)
);
a_loc_urls[1647] = 'http://nwctest.buysell.co.uk/location/merseyside/liverpool/skelmersdale/';
a_locBounds[1647] = new GLatLngBounds(
	new GLatLng( 		
		53.5143015595,
		-2.85636964915
	),
	new GLatLng( 
		53.5913479903,
		-2.73177798593
	)
);
a_loc_urls[1648] = 'http://nwctest.buysell.co.uk/location/merseyside/liverpool/widnes/';
a_locBounds[1648] = new GLatLngBounds(
	new GLatLng( 		
		53.3512046354,
		-2.77308843228
	),
	new GLatLng( 
		53.3945657336,
		-2.70320223291
	)
);
a_loc_urls[1649] = 'http://nwctest.buysell.co.uk/location/merseyside/liverpool/liverpool/';
a_locBounds[1649] = new GLatLngBounds(
	new GLatLng( 		
		53.3206824762,
		-3.01048590015
	),
	new GLatLng( 
		53.4801707464,
		-2.75381129581
	)
);
a_loc_urls[1650] = 'http://nwctest.buysell.co.uk/location/merseyside/sefton/aintree/';
a_locBounds[1650] = new GLatLngBounds(
	new GLatLng( 		
		53.4755956867,
		-2.9558222174
	),
	new GLatLng( 
		53.4910984933,
		-2.93084734398
	)
);
a_loc_urls[1651] = 'http://nwctest.buysell.co.uk/location/merseyside/sefton/bootle/';
a_locBounds[1651] = new GLatLngBounds(
	new GLatLng( 		
		53.4373358207,
		-3.01163286847
	),
	new GLatLng( 
		53.4740425821,
		-2.95256972942
	)
);
a_loc_urls[1652] = 'http://nwctest.buysell.co.uk/location/merseyside/sefton/crosby/';
a_locBounds[1652] = new GLatLngBounds(
	new GLatLng( 		
		53.4696282979,
		-3.0866920348
	),
	new GLatLng( 
		53.5271793201,
		-2.99407744279
	)
);
a_loc_urls[1653] = 'http://nwctest.buysell.co.uk/location/merseyside/sefton/formby/';
a_locBounds[1653] = new GLatLngBounds(
	new GLatLng( 		
		53.5324492934,
		-3.08404807874
	),
	new GLatLng( 
		53.5692279934,
		-3.0248022621
	)
);
a_loc_urls[1654] = 'http://nwctest.buysell.co.uk/location/merseyside/sefton/southport/';
a_locBounds[1654] = new GLatLngBounds(
	new GLatLng( 		
		53.5722346495,
		-3.05414433684
	),
	new GLatLng( 
		53.7163100365,
		-2.82115694476
	)
);
a_loc_urls[1655] = 'http://nwctest.buysell.co.uk/location/merseyside/st-helens/newton-le-willows/';
a_locBounds[1655] = new GLatLngBounds(
	new GLatLng( 		
		53.4406308989,
		-2.67674852903
	),
	new GLatLng( 
		53.4743881703,
		-2.62216461272
	)
);
a_loc_urls[1656] = 'http://nwctest.buysell.co.uk/location/merseyside/st-helens/st-helens/';
a_locBounds[1656] = new GLatLngBounds(
	new GLatLng( 		
		53.4183116406,
		-2.81653174062
	),
	new GLatLng( 
		53.5054115156,
		-2.67587962908
	)
);
a_loc_urls[1658] = 'http://nwctest.buysell.co.uk/location/merseyside/knowsley/kirkby/';
a_locBounds[1658] = new GLatLngBounds(
	new GLatLng( 		
		53.450656174,
		-2.90812302253
	),
	new GLatLng( 
		53.502326201,
		-2.82480263821
	)
);
a_loc_urls[1661] = 'http://nwctest.buysell.co.uk/location/cheshire/cheshire/chester-rural/';
a_locBounds[1661] = new GLatLngBounds(
	new GLatLng( 		
		53.0979049377,
		-3.0079894514
	),
	new GLatLng( 
		53.2866363209,
		-2.70558222555
	)
);
a_loc_urls[1664] = 'http://nwctest.buysell.co.uk/location/cheshire/cheshire/congleton/';
a_locBounds[1664] = new GLatLngBounds(
	new GLatLng( 		
		53.097386735,
		-2.31436029485
	),
	new GLatLng( 
		53.2222544684,
		-2.11255967095
	)
);
a_loc_urls[1665] = 'http://nwctest.buysell.co.uk/location/cheshire/cheshire/crewe/';
a_locBounds[1665] = new GLatLngBounds(
	new GLatLng( 		
		53.0199571701,
		-2.53904568953
	),
	new GLatLng( 
		53.1538891895,
		-2.3236341096
	)
);
a_loc_urls[1666] = 'http://nwctest.buysell.co.uk/location/cheshire/cheshire/ellesmere-port/';
a_locBounds[1666] = new GLatLngBounds(
	new GLatLng( 		
		53.2498046741,
		-2.98159242743
	),
	new GLatLng( 
		53.3071039105,
		-2.88970610267
	)
);
a_loc_urls[1667] = 'http://nwctest.buysell.co.uk/location/cheshire/cheshire/frodsham/';
a_locBounds[1667] = new GLatLngBounds(
	new GLatLng( 		
		53.2410932928,
		-2.7475756891
	),
	new GLatLng( 
		53.3134277338,
		-2.63116503377
	)
);
a_loc_urls[1668] = 'http://nwctest.buysell.co.uk/location/cheshire/cheshire/holmes-chapel/';
a_locBounds[1668] = new GLatLngBounds(
	new GLatLng( 		
		53.1798918901,
		-2.40450620918
	),
	new GLatLng( 
		53.2405722491,
		-2.30652769863
	)
);
a_loc_urls[1669] = 'http://nwctest.buysell.co.uk/location/cheshire/cheshire/knutsford/';
a_locBounds[1669] = new GLatLngBounds(
	new GLatLng( 		
		53.2042776147,
		-2.51837239743
	),
	new GLatLng( 
		53.3972713705,
		-2.20613438208
	)
);
a_loc_urls[1671] = 'http://nwctest.buysell.co.uk/location/cheshire/cheshire/macclesfield-rural/';
a_locBounds[1671] = new GLatLngBounds(
	new GLatLng( 		
		53.1599503136,
		-2.30858339024
	),
	new GLatLng( 
		53.3518649878,
		-1.99747219576
	)
);
a_loc_urls[1672] = 'http://nwctest.buysell.co.uk/location/cheshire/cheshire/malpas/';
a_locBounds[1672] = new GLatLngBounds(
	new GLatLng( 		
		52.9536690858,
		-2.89435270102
	),
	new GLatLng( 
		53.1075281466,
		-2.64842080053
	)
);
a_loc_urls[1673] = 'http://nwctest.buysell.co.uk/location/cheshire/cheshire/middlewich/';
a_locBounds[1673] = new GLatLngBounds(
	new GLatLng( 		
		53.145774361,
		-2.51414847913
	),
	new GLatLng( 
		53.2332159452,
		-2.37320622513
	)
);
a_loc_urls[1674] = 'http://nwctest.buysell.co.uk/location/cheshire/cheshire/nantwich/';
a_locBounds[1674] = new GLatLngBounds(
	new GLatLng( 		
		52.98899261,
		-2.58252807761
	),
	new GLatLng( 
		53.082045419,
		-2.43320525286
	)
);
a_loc_urls[1675] = 'http://nwctest.buysell.co.uk/location/cheshire/cheshire/newcastle-under-lyme/';
a_locBounds[1675] = new GLatLngBounds(
	new GLatLng( 		
		52.9488819484,
		-2.44151642374
	),
	new GLatLng( 
		53.0559987884,
		-2.26937577925
	)
);
a_loc_urls[1676] = 'http://nwctest.buysell.co.uk/location/cheshire/cheshire/northwich/';
a_locBounds[1676] = new GLatLngBounds(
	new GLatLng( 		
		53.2188267513,
		-2.61513212198
	),
	new GLatLng( 
		53.3016462691,
		-2.48162634332
	)
);
a_loc_urls[1677] = 'http://nwctest.buysell.co.uk/location/cheshire/cheshire/oswestry/';
a_locBounds[1677] = new GLatLngBounds(
	new GLatLng( 		
		52.7479403434,
		-3.25574997859
	),
	new GLatLng( 
		53.0253003008,
		-2.81554050639
	)
);
a_loc_urls[1678] = 'http://nwctest.buysell.co.uk/location/cheshire/cheshire/runcorn/';
a_locBounds[1678] = new GLatLngBounds(
	new GLatLng( 		
		53.2836809489,
		-2.7703524342
	),
	new GLatLng( 
		53.3657990637,
		-2.63808130351
	)
);
a_loc_urls[1679] = 'http://nwctest.buysell.co.uk/location/cheshire/cheshire/sandbach/';
a_locBounds[1679] = new GLatLngBounds(
	new GLatLng( 		
		53.0974758598,
		-2.42978638777
	),
	new GLatLng( 
		53.1901509902,
		-2.28037307799
	)
);
a_loc_urls[1680] = 'http://nwctest.buysell.co.uk/location/cheshire/cheshire/tarporley-kelsall/';
a_locBounds[1680] = new GLatLngBounds(
	new GLatLng( 		
		53.13749839,
		-2.70797023437
	),
	new GLatLng( 
		53.1886648456,
		-2.62581365909
	)
);
a_loc_urls[1681] = 'http://nwctest.buysell.co.uk/location/cheshire/cheshire/whitchurch/';
a_locBounds[1681] = new GLatLngBounds(
	new GLatLng( 		
		52.9093547803,
		-2.74824556581
	),
	new GLatLng( 
		52.9884334817,
		-2.62192005561
	)
);
a_loc_urls[1682] = 'http://nwctest.buysell.co.uk/location/cheshire/cheshire/winsford/';
a_locBounds[1682] = new GLatLngBounds(
	new GLatLng( 		
		53.154999394,
		-2.57200249672
	),
	new GLatLng( 
		53.2163451866,
		-2.47324416441
	)
);
a_loc_urls[1683] = 'http://nwctest.buysell.co.uk/location/cheshire/wirral/bebington/';
a_locBounds[1683] = new GLatLngBounds(
	new GLatLng( 		
		53.2964212387,
		-3.06167676654
	),
	new GLatLng( 
		53.3697448379,
		-2.944062015
	)
);
a_loc_urls[1684] = 'http://nwctest.buysell.co.uk/location/cheshire/wirral/birkenhead/';
a_locBounds[1684] = new GLatLngBounds(
	new GLatLng( 		
		53.3611389137,
		-3.07689762569
	),
	new GLatLng( 
		53.4102730989,
		-2.99802884285
	)
);
a_loc_urls[1685] = 'http://nwctest.buysell.co.uk/location/cheshire/wirral/heswall/';
a_locBounds[1685] = new GLatLngBounds(
	new GLatLng( 		
		53.3072733027,
		-3.14886670334
	),
	new GLatLng( 
		53.3681694781,
		-3.05131459929
	)
);
a_loc_urls[1686] = 'http://nwctest.buysell.co.uk/location/cheshire/wirral/hoylake/';
a_locBounds[1686] = new GLatLngBounds(
	new GLatLng( 		
		53.3789954623,
		-3.19745320371
	),
	new GLatLng( 
		53.4137958461,
		-3.14168695143
	)
);
a_loc_urls[1687] = 'http://nwctest.buysell.co.uk/location/cheshire/wirral/moreton/';
a_locBounds[1687] = new GLatLngBounds(
	new GLatLng( 		
		53.3873200451,
		-3.13822289221
	),
	new GLatLng( 
		53.4134877755,
		-3.09625410635
	)
);
a_loc_urls[1688] = 'http://nwctest.buysell.co.uk/location/cheshire/wirral/neston/';
a_locBounds[1688] = new GLatLngBounds(
	new GLatLng( 		
		53.246322651,
		-3.09844958893
	),
	new GLatLng( 
		53.3215706124,
		-2.97794568532
	)
);
a_loc_urls[1689] = 'http://nwctest.buysell.co.uk/location/cheshire/wirral/upton/';
a_locBounds[1689] = new GLatLngBounds(
	new GLatLng( 		
		53.3613085216,
		-3.13014334704
	),
	new GLatLng( 
		53.3946341604,
		-3.07671107634
	)
);
a_loc_urls[1690] = 'http://nwctest.buysell.co.uk/location/cheshire/wirral/wallasey/';
a_locBounds[1690] = new GLatLngBounds(
	new GLatLng( 		
		53.3909202348,
		-3.10545780859
	),
	new GLatLng( 
		53.4419787822,
		-3.02347473541
	)
);
a_loc_urls[1691] = 'http://nwctest.buysell.co.uk/location/cheshire/wirral/west-kirby/';
a_locBounds[1691] = new GLatLngBounds(
	new GLatLng( 		
		53.3591909954,
		-3.18382295477
	),
	new GLatLng( 
		53.3815999246,
		-3.14793293682
	)
);
a_loc_urls[1692] = 'http://nwctest.buysell.co.uk/location/west-yorkshire/kirklees/holmfirth/';
a_locBounds[1692] = new GLatLngBounds(
	new GLatLng( 		
		53.527456853,
		-1.88310702015
	),
	new GLatLng( 
		53.6338543052,
		-1.70842895529
	)
);
a_loc_urls[1693] = 'http://nwctest.buysell.co.uk/location/west-yorkshire/kirklees/huddersfield/';
a_locBounds[1693] = new GLatLngBounds(
	new GLatLng( 		
		53.5674752165,
		-1.92552652304
	),
	new GLatLng( 
		53.7303086397,
		-1.65775233696
	)
);

function getVisibleLocations(view) {
	var a_visible = new Array();
	
	
	if (isZoomedIn()) {

		
		for (var i = 0; i < a_locBounds.length; i ++) {
			
			if ((a_locBounds[i] != null) && (view.intersects(a_locBounds[i]))) {
				
				a_visible[a_visible.length] = i;
			}
		}
		
	}
	
	
	return a_visible;
}

var a_importedLocs = new Array();
var a_visiblePosts = new Array();
var o_postMarkers = new Object();
var o_postPoints = new Object();
var o_locListId = new Object();
var a_postLists = new Array();
var a_locXMLBuffer = new Array();
var xmlBufferSlot = 0;

var o_catFilter = new Object();

function isZoomedIn() {
	return (map.getZoom() > 11);
}

function getChild(node, name) {		
	try {
		var list = node.getElementsByTagName(name);
	} catch (e) {
		
	}
	if (list) {
		return list.item(0);
	} else {
		return null;
	}
}

function getNodeVal(node, name) {
	var container = getChild(node, name);
	if (container.nodeType == 3) {		
		return container.nodeValue;
	} else {
		for (var i = 0; i < container.childNodes.length; i ++) {
			if (container.childNodes[i].nodeType == 3) {
				return container.childNodes[i].nodeValue;
			}
		}
	}
}

function isCategoryFiltered(category) {
	if (o_catFilter[getNodeVal(category, "id")] != null) {
		return true;
	} else {
		var parent = getChild(category, "parent");
		if (parent) {
			return isCategoryFiltered(parent);
		}
	}
}

function expandCategory(category) {
	var catId = getNodeVal(category, "id");
	var elContainer = window.document.getElementById("catcontainer" + catId);
	var parent = getChild(category, "parent");
	if (parent) {
		if (elContainer) {
			elContainer.style.display = 'block';
		}
	
		expandCategory(parent);
	} else {
		if (elContainer) {
			elContainer.style.display = 'block';
		}
	}
}

function centreViewOnPost(postId, zoom) {
	var point = o_postPoints[postId];
	if (point) {
		map.setCenter(point, zoom);
		GEvent.trigger(o_postMarkers[postId], "click");
	}
}

function buildAdPanel(post, postId, category) {
	
	if (document.getElementById("post" + postId) == null) {
		
		var divNode = window.document.createElement("div");
		divNode.setAttribute("id", "post" + postId);
		divNode.setAttribute("class", "mapPostItemPanel");
		divNode.setAttribute("style", "display:none");
		
		
		var context = new ExprContext(post);
		context.setVariable("graphics_path", new StringValue("http://gfx.buysell.co.uk"));
		xsltProcessContext(context, postXslt, divNode);
		
		
		var catId = getNodeVal(category, "id");
					
		
		window.document.getElementById("postlist_cat_" + catId).appendChild(divNode);
	}
}

function addMarker(postId, xmlDoc, post, point) {	
	var category = getChild(post, "category");
	
	
	if (!isCategoryFiltered(category)) {		
		var icon = ad_icon;				
		
		// map.setCenter(point, 13);
		// icon = hilight_icon;
		
		var marker = new GMarker(point, icon);
		map.addOverlay(marker);
		
		
		
		var location = getChild(post, "location");
		if (location) {
			locationStuff = '<br/>Location: <a href="' + getNodeVal(location, "url") + '">' + getNodeVal(location, "name") + '</a>';
		} else {
			locationStuff = '';
		}
	
		GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml('<div style="width:200px;"><a href="' + getNodeVal(post, "url") + '">' + getNodeVal(post, "title") + '</a><br/>Category: <a href="' + getNodeVal(category, "url") + '">' + getNodeVal(category, "name") + '</a>' + locationStuff + '</div>'); });
		
		
		
		if (marker) {						
			o_postMarkers[postId] = marker; 
		}
		
		return marker;
	}
}

function cacheLocation(locId, xmlDoc) {
	a_locXMLBuffer[xmlBufferSlot] = new Object();
	a_locXMLBuffer[xmlBufferSlot].locId = locId;
	a_locXMLBuffer[xmlBufferSlot].xmlDoc = xmlDoc;
	xmlBufferSlot ++;
	if (xmlBufferSlot >= 15) {
		xmlBufferSlot = 0;
	}
}

function loadAnyFile(url) {
	var xmlHttp = GXmlHttp.create();
	xmlHttp.open("GET", url, false);
	xmlHttp.send("");
		
	return xmlHttp.responseText;
}

function loadXMLFile(url) {
	var xmlHttp = GXmlHttp.create();
	xmlHttp.open("GET", url, false);
	xmlHttp.send("");
	
	return xmlHttp.responseXML;
}

function addPostList(locId, a_posts, xmlDoc) {
	
	var fileList = new Object();
	if (locId != null) {
		fileList.locId = locId;
	}
	fileList.a_posts = a_posts;
	fileList.xmlDoc = xmlDoc;
	
	
	var i = a_postLists.length;
	a_postLists[i] = fileList;
	if (locId != null) {
		o_locListId[locId] = i;
	}
}

function processList(url) {
	var xmlDoc = loadXMLFile(url);
	if (xmlDoc) {
		processXMLList(xmlDoc);
	}
}

function processXMLList(xmlDoc, locId) {
	
	var postsNode = getChild(getChild(xmlDoc, "list"), "posts");
	if (postsNode) {
			
		var filePosts = new Array();
	
		var posts = postsNode.getElementsByTagName("post");
		if (posts) {
			for (var i = 0; i < posts.length; i ++) {
				
				var position = getChild(posts[i], "position");
				var point = new GLatLng(getNodeVal(position, "latitude"), getNodeVal(position, "longitude"));
				var postId = posts[i].getAttribute("id");								
				
				o_postPoints[postId] = point;
				
				filePosts[filePosts.length] = postId;
				
				
				buildAdPanel(posts[i], postId, getChild(posts[i], "category"));			
			}
		}
		
		
		addPostList(locId, filePosts, xmlDoc);
	}		
}

function importLocation(locId) {
	var xmlDoc;
	
	a_importedLocs[a_importedLocs.length] = locId;
		
	
	var b_found = false;
	for (var i = 0; i < a_locXMLBuffer.length; i ++) {
		if (a_locXMLBuffer[i].locId == locId) {
			
			xmlDoc = a_locXMLBuffer[i].xmlDoc;
			b_found = true;
			break;
		}
	}
	if (!b_found) {
		
		var locURL = a_loc_urls[locId] + 'map.xml';		
		
		
		xmlDoc = loadXMLFile(locURL);
		
		
		cacheLocation(locId, xmlDoc);		
	}

	if (xmlDoc) {
		processXMLList(xmlDoc, locId);
	}
}

function hideIfAllHidden(el) {
	var b_someLeft = false;
	for (var i = 0; i < el.childNodes.length; i ++) {
		if (el.childNodes[i].tagName == "LI" && el.childNodes[i].style.display != 'none') {
			b_someLeft = true;
			break;
		}
	}
	if (!b_someLeft) {
		var elParent;
		for (elParent = el.parentNode; elParent && elParent.tagName != "LI"; elParent = elParent.parentNode);
		if (elParent) {
			elParent.style.display = 'none';
		}
	}
}

function hideIfEmpty(el) {
	var b_someLeft = false;
	for (var i = 0; i < el.childNodes.length; i ++) {
		if ((el.childNodes[i].tagName == "DIV") && (el.childNodes[i].style.display != 'none')) {
			b_someLeft = true;
			break;			
		}
	}
	if (!b_someLeft) {
		
		var elParent;
		for (elParent = el.parentNode; elParent && elParent.tagName != "LI"; elParent = elParent.parentNode);
		if (elParent) {
			elParent.style.display = 'none';
			
			
			hideIfAllHidden(elParent.parentNode);
		}				
	}
}

function removePost(postId) {
	map.removeOverlay(o_postMarkers[postId]);
	delete o_postMarkers[postId];		
	
	var elDiv = window.document.getElementById("post" + postId);
	if (elDiv) {
		elParent = elDiv.parentNode;
		elParent.removeChild(elDiv);
		
		
		hideIfEmpty(elParent);			
	}
}

function hidePost(postId) {
	map.removeOverlay(o_postMarkers[postId]);
	delete o_postMarkers[postId];	
	
	var elDiv = window.document.getElementById("post" + postId);
	if (elDiv) {
		elDiv.style.display = 'none';		
		
		
		hideIfEmpty(elDiv.parentNode);
	}
}

function removeLocList(locId) {
	var id = o_locListId[locId];
	
	var newList = new Array();	
	for (var i = 0; i < a_postLists.length; i ++) {
		if (i != id) {
			var j = newList.length;
			newList[j] = a_postLists[i];
			
			if (typeof a_postLists[i].locId != 'undefined') {
				
				o_locListId[a_postLists[i].locId] = j;
			}
		}
	}

	a_postLists = newList;
	
	delete o_locListId[locId];
}

function unloadLocation(locId) {	
	
	var id = o_locListId[locId];
	if (id != null) {
		var postList = a_postLists[id].a_posts;		
		if (postList) {
			for (var i = 0; i < postList.length; i ++) {
				removePost(postList[i]);
			}
		}
		removeLocList(locId);
	}
	
	
	var newList = new Array();
	for (var i = 0; i < a_importedLocs.length; i ++) {
		if (a_importedLocs[i] != locId) {
			newList[newList.length] = a_importedLocs[i];
		}
	}
	
	a_importedLocs = newList;	
}

function findPostElement(xmlDoc, postId) {
	var postsNode = getChild(getChild(xmlDoc, "list"), "posts");
	if (postsNode) {
		var posts = postsNode.getElementsByTagName("post");
		if (posts) {
			for (var i = 0; i < posts.length; i ++) {
				if (posts[i].getAttribute("id") == postId) {
					return posts[i];
				}
			}
		}
	}
}

function showPost(postId, category) {
	var elDiv = window.document.getElementById("post" + postId);
	if (elDiv) {
		elDiv.style.display = 'block';
		
		expandCategory(category);
	}
}

function refreshVisiblePosts(view) {
	
	var newList = new Array();
	for (var i = 0; i < a_visiblePosts.length; i ++) {
		var postId = a_visiblePosts[i];
		if (!view.contains(o_postPoints[postId])) {
			
			hidePost(postId);
		} else {
			newList[newList.length] = postId;
		}
	}
	
	
	for (var i = 0; i < a_postLists.length; i ++) {
		var a_posts = a_postLists[i].a_posts;
		var xmlDoc = a_postLists[i].xmlDoc;
		for (var j = 0; j < a_posts.length; j ++) {
			var postId = a_posts[j];
			var point = o_postPoints[postId];
			if (view.contains(point)) {
				
				if (o_postMarkers[postId] == null) {					
					var post = findPostElement(xmlDoc, postId);
					var category = getChild(post, "category");

					
					newList[newList.length] = postId;
					
											
					if (post) {
						addMarker(postId, xmlDoc, post, point);
						showPost(postId, category);
					}										
				}
			}
		}
	}
	
	
	a_visiblePosts = newList;
}

function updateView(view) {
	
	var a_visible = getVisibleLocations(view);
	
	
	var loaded = new Object();
	var currentLocs = a_importedLocs;
	for (var j = 0; j < currentLocs.length; j ++) {
		loaded[currentLocs[j]] = true;
		
		
		var b_visible = false;
		for (var i = 0; i < a_visible.length; i ++) {
			
			if (a_visible[i] == currentLocs[j]) {
				b_visible = true;
				break;
			}
		}		
		if (!b_visible) {
			
			unloadLocation(currentLocs[j]);
		}
	}
			
	for (var i = 0; i < a_visible.length; i ++) {
		if (loaded[a_visible[i]] == null) {
			
			importLocation(a_visible[i]);	
		}
	}
	
	
	refreshVisiblePosts(view);
	
	document.getElementById('zoomInMessage').style.visibility = (isZoomedIn() ? 'hidden' : 'visible');
}

function refreshDisplay() {
	
	map.clearOverlays();
	a_visiblePosts = new Array();
	o_postMarkers = new Object();
	
	
	refreshVisiblePosts(map.getBounds());
}

function expandOrContract(checked, catId) {
	document.getElementById("postlist_cat_" + catId).style.display = (checked ? 'block' : 'none');
}

function setCategoryFilter(input, filtered, dontRefresh) {
	input.checked = filtered;
	input.src = document.getElementById((filtered ? "node_open" : "node_closed")).src;

	expandOrContract(filtered, input.id);
	if (filtered) {
		
		delete o_catFilter[input.id];
	} else {
		
		o_catFilter[input.id] = true;
	}
	
	if (!dontRefresh) {
		
		refreshDisplay();
	}		
}

function changeCategoryFilter(input) {
	setCategoryFilter(input, (typeof input.checked != "undefined" && !input.checked));
}


