function win(location){
	if(location.coords){
		var lat=location.coords.latitude;
		var lng=location.coords.longitude;
	}else {
		var lat=location.latitude;
		var lng=location.longitude;
	}
	
	//check for existing locationDiv
	locationDiv=document.getElementById("locationdiv");
	if (locationDiv.hasChildNodes()) {
    	while (locationDiv.childNodes.length>=1) {
       	 locationDiv.removeChild(locationDiv.firstChild);       
    	} 
	}
		
	locationHeader=document.createElement("h3");
	headerText=document.createTextNode("Your Location");
	locationHeader.appendChild(headerText);
	locationDiv.appendChild(locationHeader);
	locationMap=document.createElement("img");
	locationMap.setAttribute("src","http:\/\/maps.google.com/staticmap?center=" + location.coords.latitude + "," + location.coords.longitude + "&size=240x160&zoom=14&maptype=roadmap&key=ABQIAAAAPvVn-WQCgB0xVo84OTfzSRTtPZkRzSTQw3RbemNSLo32LnqC1hS41yyDZN8xhmxjkPmK0CMlVUpZBQ&sensor=true&markers="+location.coords.latitude+","+location.coords.longitude+",blue");
	locationDiv.appendChild(locationMap);
	linkPara=document.createElement("p");
	searchLink=document.createElement("a");
	linkText=document.createTextNode("Show listings near you");
	searchLink.setAttribute("href","/list.php?geosearch=true&lat="+location.coords.latitude+"&lng="+location.coords.longitude);
	searchLink.appendChild(linkText);
	linkPara.appendChild(searchLink);
	locationDiv.appendChild(linkPara);
}

function fail(){
	alert("Could not find your location. Sorry!");
}

function locationHandler(){
	//check for cookie
	if(geo!=false){
		geo.getCurrentPosition(win,fail,{maximumAge:0});
	}
}

addEvent(window,"load",locationHandler,false);

