var locations= {
	Abermain: {
		lat:-32.8105668,
		lng:151.4319447,
		title:'Coalfields Neighbourcare Inc',
		website:'cnc.net.au',
		phone:'49304706',
		email:'lorraine@cnc.net.au',
		address:'209 Cessnock Road Abermain  NSW  2326',
		pobox:'PO Box 39 Abermain  NSW  2326',
		t:'abermain',
		sv:'http://maps.google.com.au/maps?q=209+Cessnock+Road+Abermain+NSW+2326&layer=c&sll=-32.810563,151.431944&cbp=13,31.73,,0,6.02&cbll=-32.810851,151.431825&gl=au&sspn=0.006295,0.006295&ie=UTF8&hq=&hnear=209+Cessnock+Rd,+Abermain+New+South+Wales+2326&ll=-32.810713,151.43162&spn=0.007232,0.013937&t=h&z=17&iwloc=A&panoid=Q-Djmy70rQLj_CFr9Nw5gA'
	},
	"Port stephens": {
		lat:-32.726490,
		lng:152.075513,
		title:'Community Transport Group of Port Stephens Inc',
		phone:'02 4984 7999',
		email:'info@ctps.org.au',
		website:'ctps.org.au',
		address:'Unit 1 / 124 George Road,<br />'+
				'Salamander Bay NSW 2317',
		pobox:'',
		t:'portstephens',
		sv:'http://maps.google.com.au/maps?q=Unit+1+%2F+124+George+Road,Salamander+Bay+NSW+2317&layer=c&sll=-32.726490,152.075506&cbp=13,147.37,,0,0.1&cbll=-32.726283,152.075349&gl=au&sspn=0.006295,0.006295&ie=UTF8&hq=&hnear=1%2F124+George+Rd,+Salamander+Bay+New+South+Wales+2317&ll=-32.726281,152.07535&spn=0.007239,0.013937&t=h&z=17&iwloc=A&panoid=RDB-J3nIAyYCnm9_mZJ8Xg'
	},
	Scone: {
		lat:-32.052119,
		lng:150.867991,
		title:'TransCare Hunter Ltd',
		website:'transcare.org.au',
		address:'206 Kelly St, Scone',
		pobox:'PO Box 455, Scone 2337',
		phone:'6545 3113',
		email:'enquiries@transcare.org.au',
		t:'scone',
		sv:'http://maps.google.com.au/maps?ie=UTF8&q=206+Kelly+St,+Scone&fb=1&gl=au&hnear=Newcastle+New+South+Wales&cid=0,0,12021703518493874784&ll=-32.052044,150.867305&spn=0,0.027874&t=h&z=16&layer=c&cbll=-32.051945,150.867306&panoid=I661cdzvwkOTb-H2ON6CEg&cbp=12,105.89,,0,1.11'
	},
	Bungree:{
		lat:-33.263655,
		lng:151.541676,
		title:'Bungree Aboriginal Association Inc CT',
		website:'',
		address:'272 Main Road Toukley NSW 2263',
		pobox:'PO Box 422, Toukley  2263',
		phone:'4397 7700',
		email:'beverly.simon@bungree.org.au',
		t:'bungree',
		sv:'http://maps.google.com.au/maps?ie=UTF8&q=272+Main+Road+Toukley+NSW+2263&fb=1&gl=au&hnear=Newcastle+New+South+Wales&cid=0,0,4194725838148906902&ll=-33.263501,151.541658&spn=0,0.027874&t=h&z=16&iwloc=A&layer=c&cbll=-33.263501,151.541658&panoid=Bbqyy7xWhrUkLCabMagcBg&cbp=12,173.7,,0,0'
	},
	Wyong:{
		lat:-33.2571722,
		lng:151.5131345,
		title:'Wyong Community Transport',
		website:'http://www.centralcoasthacc.com.au/index.php?new_c_id=45',
		address:'Beryl Street Community Centre, 2 Dan Close, Gorokan',
		pobox:'PO Box 6171, Gorokan  2263',
		phone:'4392 5633',
		fax:'4392 5640',
		email:'admin@wyongct.com',
		t:'wyong',
		sv:'http://maps.google.com.au/maps?q=2+Dan+Close,+Gorokan&layer=c&sll=-33.257244,151.512859&cbp=13,218.73,,0,0.13&cbll=-33.257069,151.513024&hl=en&gl=au&ie=UTF8&hq=&hnear=2+Dan+Close,+Gorokan+New+South+Wales+2263&ll=-33.257072,151.51302&spn=0.007195,0.013937&t=h&z=17&iwloc=A&panoid=lTasyzBSo84hbnobfWsJCQ'
	},
	Gosford:{
		lat:-33.380614,
		lng:151.367491,
		title:'Coastwide Community Transport Ltd',
		website:'gosfordct.org.au',
		address:'27 Awaba St Lisarow NSW 2250',
		pobox:'PO Box 851, Gosford NSW 2250',
		phone:'4323 4028',
		fax:'4323 4031',
		email:'owen@gosfordct.org.au',
		t:'gosford',
		sv:'http://maps.google.com.au/maps?q=27+Awaba+St+Lisarow+NSW+2250&layer=c&sll=-33.380459,151.369165&cbp=13,255.89,,0,12.23&cbll=-33.380452,151.369198&hl=en&gl=au&sspn=0.006295,0.006295&ie=UTF8&hq=&hnear=27+Awaba+St,+Lisarow+New+South+Wales+2250&ll=-33.380453,151.3692&spn=0.007185,0.013937&t=h&z=17&iwloc=A&panoid=dIpCg3D50ReJWcmh7w4aHQ'
	},
	Cessnock:{
		lat:-32.835884,
		lng:151.356097,
		title:'Cessnock Community Transport',
		website:'',
		pobox:'PO Box 341 Cessnock  NSW  2325',
		address:'119 Vincent Street Cessnock NSW 2325',
		phone:'4990 7247',
		email:'cessnockct@bigpond.com',
		t:'cessnock',
		sv:'http://maps.google.com.au/maps?ie=UTF8&q=119+Vincent+Street+Cessnock+NSW+2325&fb=1&gl=au&hnear=Newcastle+New+South+Wales&cid=0,0,10733353195203028967&ll=-32.835913,151.356111&spn=0,0.027874&t=h&z=16&iwloc=A&layer=c&cbll=-32.835917,151.356119&panoid=Svd_sLkw9wMRPQl7GggyRg&cbp=12,292.88,,0,9'
	},
	'Lake Macquarie':{
		lat:-32.910551,
		lng:151.749003,
		title:'Lake Macquarie Community Transport',
		website:'mercyservices.org.au',
		address:'13 Brooks St, Wallsend, NSW ',
		pobox:'',
		phone:'4944 1944',
		email:'lakemacquarie@mercyservices.com.au',
		t:'lakemacquarie',
		sv:'http://maps.google.com.au/maps?q=32+Union+Street,+Tighes+Hill+NSW+2297+Australia&layer=c&sll=-32.910593,151.748893&cbp=13,276.57,,0,0.07&cbll=-32.910604,151.749009&hl=en&gl=au&sspn=0.006295,0.006295&ie=UTF8&hq=&hnear=32+Union+St,+Tighes+Hill+New+South+Wales+2297&ll=-32.910594,151.748901&spn=0.000451,0.000871&t=h&z=21&iwloc=A&panoid=VDL_RYTegGwhiUvxQK_s8A'
	},
	Newcastle:{
		lat:-32.918913,
		lng:151.765579,
		title:'Newcastle Community Transport Group Inc',
		website:'newcastlect.com/index.htm',
		pobox:'PO Box 52 CARRINGTON NSW 2294',
		address:'10 Darvall Street CARRINGTON NSW 2294',
		phone:'4961 3113',
		email:'mail@newcastlect.com',
		t:'newcastle',
		sv:'http://maps.google.com.au/maps?q=10+Darvall+Street+CARRINGTON+NSW+2294&layer=c&sll=-32.918931,151.765574&cbp=13,169.47,,0,0&cbll=-32.918675,151.765519&hl=en&gl=au&sspn=0.006295,0.006295&ie=UTF8&hq=&hnear=10+Darvall+St,+Carrington+New+South+Wales+2294&ll=-32.918675,151.765519&spn=0,0.000871&t=h&z=21&iwloc=A&panoid=duooTBL2jQwFUnvCDmuLfQ'
	},
	Maitland:{
		lat:-32.723752,
		lng:151.538670,
		title:'Maitland Community Transport Inc',
		website:'mccs.org.au/',
		address:'Unit 3 & 4 27 John Street Telarah NSW 2320',
		pobox:'',
		phone:'4932-5755',
		email:'mail@mccs.org.au',
		t:'maitland',
		sv:'http://maps.google.com.au/maps?ie=UTF8&q=27+John+Street+Telarah+NSW+2320&fb=1&gl=au&hnear=Newcastle+New+South+Wales&cid=0,0,7345769010938726215&ll=-32.723927,151.539246&spn=0,0.000871&t=h&z=21&layer=c&cbll=-32.723927,151.539246&panoid=LsFvelt56a7TV69qfIGfrQ&cbp=12,288.58,,0,0.07'
	},
	Singleton:{
		lat:-32.564863,
		lng:151.169649,
		title:'Singleton Community Transport Project',
		website:'www.ourcare.org.au',
		pobox:'PO Box 219, Singleton  2330',
		address:'3 Bathurst Street, Singleton NSW 2330',
		phone:'6571 2300',
		email:'ladie@ourcare.org.au',
		t:'singleton',
		sv:'http://maps.google.com.au/maps?f=q&source=s_q&hl=en&geocode=&q=3+Bathurst+Street,+Singleton+NSW+2330&aq=&sll=-32.918675,151.765519&sspn=0.000454,0.000871&gl=au&ie=UTF8&hq=&hnear=3+Bathurst+St,+Singleton+New+South+Wales+2330&ll=-32.564854,151.169654&spn=0.007252,0.013937&t=h&z=17'
	},
	Dungog:{
		lat:-32.402042,
		lng:151.746308,
		title:'Dungog &amp; District Neighbourcare Inc',
		website:'neighbourcare.org.au/',
		pobox:'PO Box 171 Dungog NSW 2420',
		address:'62 Hospital Road PO Box 171 Dungog NSW 2420',
		phone:'4992 3348',
		email:'',
		t:'dungog',
		sv:'http://maps.google.com.au/maps?q=62+Hospital+Road+PO+Box+171+Dungog+NSW+2420&layer=c&sll=-32.401625,151.746302&cbp=13,353.42,,0,8.79&cbll=-32.401661,151.746306&hl=en&gl=au&sspn=0.006295,0.006295&ie=UTF8&hq=&hnear=62+Hospital+Rd,+Dungog+New+South+Wales+2420&ll=-32.401634,151.746305&spn=0.001816,0.003484&t=h&z=19&iwloc=A&panoid=_wYMMg2xKO_GIpwZMZjjKQ'
	}
}


window.onload = function() {
	var options = {
	  zoom: 8,
	  center: new google.maps.LatLng(-32.7, 151.2),
	  mapTypeId: google.maps.MapTypeId.TERRAIN
	}; 

	var map = new google.maps.Map(document.getElementById('map'), options);

	var infowindow = new google.maps.InfoWindow({
		content: '<div class=infowindow></div>',
		maxWidth:300
		
	});
	  
	var markers={};
	var maplist=$("#maplist");
	
	$.each(locations,function(name,loc) {
		
		//Create Markers
		markers[name] = new google.maps.Marker({
			position: new google.maps.LatLng(loc.lat, loc.lng), 
			map: map,
			title: name,
			icon:'images/huntermapicon5.png'
		});
		
		//Attach click handlers to each marker
		var click=function() {
			infowindow.setContent('<div class=infowindow><b>'+loc.title+"</b><br /><a href='"+loc.sv+"' ><img src='cto_th/"+loc.t+".jpg' /></a><br /><span><img class=phoneicon src='images/phoneicon2.png' />"+loc.phone+"</span></div>");
			infowindow.open(map, markers[name]);
			
			var maplist=$("#maplist");
			var location=maplist.find(":contains('"+this.title+"')");
			maplist.find(".selectedlocation").removeClass("selectedlocation")
			location.addClass("selectedlocation");
			maplist.find(".detailsshow").removeClass("detailsshow");
			location.next().addClass("detailsshow");
			
		}
		google.maps.event.addListener( markers[name], 'click',click);
		var website="";
		if (loc.website!=="") {
			website="<a class='button website' href='http://www."+loc.website+"' target=_blank >Website</a>";
		}
		var loc_link=$("<div class=locbox><span class=location>"+name+"</span>"+
						"<div class=details>"+
						"<input type=hidden name=trading value='"+loc.title+"' />"+
						"<div><a class='button email' href='mailto:"+loc.email+"' >Email</a>"+
						website+						
						"</div>"+
						"<label>Phone</label>"+loc.phone+
						"<label>Address</label>"+loc.address+
						"<label>PO Box</label>"+loc.pobox+
						"<label>Trading Name</label>"+loc.title+
						"</div>"+
						"</div>");
					
		loc_link.find(".location").click(click).click(function() {
			$("#maplist").find(".selectedlocation").removeClass("selectedlocation")
			$(this).addClass("selectedlocation");
			$("#maplist").find(".detailsshow").removeClass("detailsshow");
			$(this).next().addClass("detailsshow");
		});
		maplist.append(loc_link);
	})
	$( "#contact" ).dialog({autoOpen:false,width:500,modal:true,show:'fade'});
	$("#maplist").delegate(".email","click",function(e) {
		e.preventDefault();
		var email=$(this).attr("href");
		email=email.replace("mailto:","");
		
		var trading=$(this).parents(".details").find("[name=trading]").val();
		$( "#contact" ).dialog( "open" ).dialog("option",{title:"Send Message to "+trading});
		$( "#contact" ).find("[name=to]").val(email);
	});
	$( "#contact" ).submit(function(e) {
		e.preventDefault()
		var form=$(this);
		
		var formdata=form.serialize();
		form.find(":submit").val("Sending Message").attr("disabled",true);
		$.get("send_email.php",formdata,function() {
			form.html("Your message has been sent");
		})
	});
	
}


