var map=null;
var markerCache={};
var markerCacheDeleteMe={};
var imageSize=32;
var baseIcon=new GIcon();
baseIcon.iconSize=new GSize(imageSize,imageSize);
baseIcon.iconAnchor=new GPoint(imageSize/2,imageSize/2);
baseIcon.infoWindowAnchor=new GPoint(imageSize/2,imageSize/2+2);
function unloadMap(){
markerCache={};
GUnload();
}
function load(){
if(GBrowserIsCompatible()){
map=new GMap2(document.getElementById("map"));
map.enableDoubleClickZoom();
map.enableScrollWheelZoom();
map.enableContinuousZoom();
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());
map.addControl(new FullScreenControl());
map.addControl(new FilterControl());
GEvent.addListener(map,"moveend",function(){
loadDatingoUsers();
});
GEvent.addDomListener(map.getContainer(),"DOMMouseScroll",wheelevent);
map.getContainer().onmousewheel=wheelevent;
map.setCenter(new GLatLng(init_lat,init_lon),init_zoom);
if(window.location.hash=="#fullscreen"){
switchFullscreen();
}
}
}
function wheelevent(e){
if(!e){
e=window.event;
}
if(e.preventDefault){
e.preventDefault();
}
e.returnValue=false;
}
var globalGender="";
function loadDatingoUsers(){
var _2=map.getBounds();
var _3=_2.getSouthWest();
var _4=_2.getNorthEast();
var _5="/mapjson/?lon1="+_3.lng()+"&lon2="+_4.lng()+"&lat1="+_3.lat()+"&lat2="+_4.lat()+"&gender="+globalGender;
GDownloadUrl(_5,displayUsers);
}
function displayUsers(_6,_7){
eval("var result = "+_6);
var _8=1;
for(var i=0;i<result.length;i++){
var _a=markerCache[result[i]["username"]];
if(typeof _a!="undefined"){
markerCacheDeleteMe[result[i]["username"]]=false;
}else{
var _b=new GLatLng(result[i]["lat"],result[i]["long"]);
_a=createMarker(_b,result[i]);
map.addOverlay(_a);
markerCache[result[i]["username"]]=_a;
markerCacheDeleteMe[result[i]["username"]]=false;
}
setMarkerZIndex(_a,_8);
_8++;
}
for(deleteMe in markerCacheDeleteMe){
if(markerCacheDeleteMe[deleteMe]==true){
map.removeOverlay(markerCache[deleteMe]);
delete markerCacheDeleteMe[deleteMe];
delete markerCache[deleteMe];
}else{
markerCacheDeleteMe[deleteMe]=true;
}
}
}
function createMarker(_c,_d){
var _e=new GIcon(baseIcon);
_e.image=_d["picture"];
var _f=new GMarker(_c,{icon:_e});
GEvent.addListener(_f,"click",function(){
_f.openInfoWindowHtml("<table border=\"0\"><tr><td><a href='/member/"+_d["username"]+"'><img width=\"55\" height=\"55\" src='"+_d["picture"]+"'/></a>"+"</td><td>&nbsp;</td><td valign='top' align='left'><b><a href='/member/"+_d["username"]+"'>"+_d["username"]+"</a><br>"+_d["age"]+"<br>"+_d["city"]+"</b></td></tr></table>");
});
return _f;
}
function filterChanged(){
var _10=document.getElementById("gender_select");
globalGender=_10.options[_10.selectedIndex].value;
loadDatingoUsers();
}
function FilterControl(){
}
FilterControl.prototype=new GControl();
FilterControl.prototype.initialize=function(map){
var _12=document.createElement("div");
var _13=document.createElement("div");
var _14=document.getElementById("gender_select");
_13.appendChild(_14);
_14.style.display="block";
_14.onchange=filterChanged;
setButtonStyle_(_13);
_13.style.width="155px";
_13.style.textDecoration="none";
_13.style.padding="3px";
_12.appendChild(_13);
map.getContainer().appendChild(_12);
return _12;
};
FilterControl.prototype.getDefaultPosition=function(){
return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT,new GSize(135,13));
};
function FullScreenControl(){
}
FullScreenControl.prototype=new GControl();
FullScreenControl.prototype.initialize=function(map){
var _16=document.createElement("div");
var _17=document.createElement("div");
setButtonStyle_(_17);
_16.appendChild(_17);
_17.appendChild(document.createTextNode(text_fullscreen));
GEvent.addDomListener(_17,"click",switchFullscreen);
map.getContainer().appendChild(_16);
return _16;
};
FullScreenControl.prototype.getDefaultPosition=function(){
return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT,new GSize(7,13));
};
setButtonStyle_=function(_18){
_18.style.textDecoration="underline";
_18.style.color="#0000cc";
_18.style.backgroundColor="white";
_18.style.fontSize="12px";
_18.style.border="1px solid black";
_18.style.padding="2px";
_18.style.marginBottom="1px";
_18.style.paddingBottom="1px";
_18.style.paddingTop="5px";
_18.style.textAlign="center";
_18.style.width="115px";
_18.style.height="18px";
_18.style.cursor="pointer";
};
var fullscreen=false;
var allDiv=null;
var mapDiv=null;
var saveStyles=[];
function switchFullscreen(){
if(!fullscreen){
window.location.hash="#fullscreen";
saveStyles=[];
mapDiv=document.getElementById("map");
allDiv=document.getElementById("all");
document.body.removeChild(allDiv);
document.body.appendChild(mapDiv);
saveStyles.push(document.body.style.height);
document.body.style.height="100%";
saveStyles.push(document.getElementsByTagName("html")[0].style.height);
document.getElementsByTagName("html")[0].style.height="100%";
saveStyles.push(mapDiv.style.height);
mapDiv.style.height="100%";
saveStyles.push(mapDiv.style.margin);
mapDiv.style.margin="0px";
fullscreen=true;
var _19=map.getCenter();
map.checkResize();
map.setCenter(_19);
}else{
document.body.removeChild(mapDiv);
document.body.appendChild(allDiv);
document.getElementById("main").appendChild(mapDiv);
saveStyles.reverse();
document.body.style.height=saveStyles.pop();
document.getElementsByTagName("html")[0].style.height=saveStyles.pop();
mapDiv.style.height=saveStyles.pop();
mapDiv.style.margin=saveStyles.pop();
fullscreen=false;
window.location.hash="#";
var _19=map.getCenter();
map.checkResize();
map.setCenter(_19);
}
}

