google.setOnLoadCallback(initializeServices);var map;var max_friends_allowed=1500;var friends_per_request=20;function initializeServices(){addDebug("Initialize Services");Event.observe("facebookfriendsmap-connect-button","click",facebookConnect);Event.observe("facebookfriendsmap-disconnect-button","click",facebookDisconnect);if(GBrowserIsCompatible()){map=new GMap2($("facebookfriendsmap-canvas"));map.setCenter(new GLatLng(32.879587,13.183594),2);map.enableScrollWheelZoom();map.addMapType(G_PHYSICAL_MAP);map.setMapType(G_PHYSICAL_MAP);map.addControl(new GSmallMapControl());map.addControl(new GMapTypeControl());FB.init("a5a1988d60f81e58c3cfeea470f9eb6d","../../fileadmin/utilities/xd_receiver.htm",{ifUserConnected:onUserConnected,ifUserNotConnected:onUserNotConnected})}else{addDebug("Browser not compatible");alert("Failed: Browser not compatible")}}function createMarker(e,d,b,h,g,c){var a=new GMarker(new GLatLng(g,c));var f="<div><div style='float:left;margin-right:10px'><a href='http://www.facebook.com/profile.php?id="+e+"' target='_blank'><img src='"+b+"'></a></div>";f+="<a href='http://www.facebook.com/profile.php?id="+e+"' target='_blank'><b>"+d+"</b></a><br>"+h;f+="</div><div style='clear:left'></div>";GEvent.addListener(a,"click",function(){a.openInfoWindowHtml(f)});map.addOverlay(a)}function facebookConnect(){FB_RequireFeatures(["Connect"],function(){FB.Connect.requireSession()})}function facebookDisconnect(){FB.Connect.logout(function(){addDebug("User disconnected")});map.clearOverlays()}function onUserConnected(a){$("facebookfriendsmap-connect").hide();$("facebookfriendsmap-disconnect").show();$("facebookfriendsmap-canvas").show();$("facebookfriendsmap-debugtoogle").hide();$("facebookfriendsmap-debug").hide();addDebug("User is now logged into Facebook and also this app ("+a+")");parseFriends()}function onUserNotConnected(){$("facebookfriendsmap-connect").show();$("facebookfriendsmap-disconnect").hide();$("facebookfriendsmap-canvas").show();$("facebookfriendsmap-debugtoogle").hide();$("facebookfriendsmap-debug").hide();FB.ensureInit(function(){FB.Connect.get_status().waitUntilReady(function(a){if(a==FB.ConnectState.userNotLoggedIn){addDebug("User is not logged into Facebook")}if(a==FB.ConnectState.appNotAuthorized){addDebug("User is logged into Facebook but this app is not authorized")}})})}function addDebug(e){var b=new Date();var d=b.getHours();var a=(b.getMinutes()<10)?("0"+b.getMinutes()):b.getMinutes();var c=(b.getSeconds()<10)?("0"+b.getSeconds()):b.getSeconds();$("facebookfriendsmap-debug").innerHTML+=d+":"+a+":"+c+" - "+e+"<br>"}function toogleDebug(){if($("facebookfriendsmap-debug").visible()){$("facebookfriendsmap-debug").hide()}else{$("facebookfriendsmap-debug").show()}}function parseFriends(){addDebug("Start parsing friends");map.clearOverlays();$("facebookfriendsmap-loading").show();FB_RequireFeatures(["Api"],function(){FB.Facebook.apiClient.requireLogin(function(a){FB.Facebook.apiClient.friends_get(new Array(),function(c,b){FB.Facebook.apiClient.users_getInfo(c,["uid","name","pic_small","hometown_location","current_location"],function(n,g){$("facebookfriendsmap-total").innerHTML=c.length;addDebug(c.length+" friends found");var d="type=facebook";var m=d;var f=0;var k=0;var e=0;var j=0;var l=0;for(var h=0;h<c.length;h++){if(n[h].hometown_location&&k<max_friends_allowed){$("facebookfriendsmap-location").innerHTML=++k;m+="&arg"+f+"="+h;m+="&city"+f+"="+encodeURI(n[h].hometown_location.city);m+="&state"+f+"="+encodeURI(n[h].hometown_location.state);m+="&country"+f+"="+encodeURI(n[h].hometown_location.country);f++}if(f==friends_per_request||h==c.length-1){addDebug("Submit request with "+f+" friends");new Ajax.Request("/fileadmin/utilities/geocoding.php",{method:"post",postBody:m,asynchronous:true,onComplete:function(s){var q=s.responseXML.getElementsByTagName("response");for(var p=0;p<q.length;p++){if(q[p].getAttribute("status")=="200"){var i=q[p].getAttribute("arg");var r=q[p].getAttribute("lat");var o=q[p].getAttribute("lng");createMarker(n[i].uid,n[i].name,n[i].pic_small,n[i].hometown_location.city,r,o);$("facebookfriendsmap-success").innerHTML=parseInt($("facebookfriendsmap-success").innerHTML)+1}else{l++}}addDebug("Response received with "+q.length+" friends");if(++j==e){$("facebookfriendsmap-loading").hide();addDebug("Finished, "+e+" requests sent ("+l+" errors)")}}});e++;m=d;f=0}}})})})})};