
YAHOO.namespace("ea.sp.geo");YAHOO.ea.sp.geo.jsHandler=function()
{this.objReference=arguments[0];this.callBackFnc=arguments[1];this.scriptId=arguments[2];}
YAHOO.ea.sp.geo.jsHandler.prototype={transferOO:function()
{if(this.objReference)
{if(arguments[0].Locations)
this.callBackFnc.call(this.objReference,arguments[0].Locations[0].Latitude,arguments[0].Locations[0].Longitude);else if(arguments[0].geoplugin_latitude&&arguments[0].geoplugin_longitude)
this.callBackFnc.call(this.objReference,arguments[0].geoplugin_latitude,arguments[0].geoplugin_longitude);if(navigator.appName!='Microsoft Internet Explorer')
{document.body.removeChild(document.getElementById("script"+this.scriptId));}
this.objReference=null;this.callBackFnc=null;}}}
YAHOO.ea.sp.geo.AssetBubble=function(latLng,assetUrl,innerHTML)
{var Dom=YAHOO.util.Dom;this.assetLatLng=latLng;this.prototype=new GOverlay();this.initialize=function(map)
{var div=document.createElement("div");Dom.addClass(div,'featCreationBG');Dom.addClass(div,'mapBubbleBG');div.style.position='absolute';div.style.display='block';div.innerHTML=innerHTML;map.getPane(G_MAP_FLOAT_PANE).appendChild(div);this.div=div;this.map=map;}
this.redraw=function(force)
{if(!force)return;var point=this.map.fromLatLngToDivPixel(this.assetLatLng);var z=GOverlay.getZIndex(this.assetLatLng.lat());this.div.style.left=(point.x-54)+"px";this.div.style.top=(point.y-170)+"px";this.div.style.zIndex=501;}
this.remove=function()
{var prent=this.div.parentNode;prent.removeChild(this.div);this.div=null;}}
YAHOO.ea.sp.geo.IpMappingApplication=function(url,callbackStr,assetService)
{this.apiUrl=url;this.callbackString=callbackStr;this.assetService=assetService;this.outputId="divOutput";this.callQueue=new Array();this.devMode=false;this.autopanOff=YAHOO.util.Dom.get('autopan_off');this.autopanOn=YAHOO.util.Dom.get('autopan_on');YAHOO.util.Event.addListener(this.autopanOff,'click',this.bind(this.toggleAutopan));YAHOO.util.Event.addListener(this.autopanOn,'click',this.bind(this.toggleAutopan));this.newAssetIndex=74;this.templates=new YAHOO.ea.sp.Template();this.templates.parseSections(YAHOO.util.Dom.get('template-container').value);var mapElement=document.getElementById("map_canvas");if(mapElement)
{this.map=new GMap2(mapElement);this.map.addControl(new GMapTypeControl());this.map.disableDoubleClickZoom();this.map.disableScrollWheelZoom();this.map.setCenter(new GLatLng(25,-30.00),4,G_NORMAL_MAP);}}
YAHOO.ea.sp.geo.IpMappingApplication.prototype={fetchIpLocation:function(asset)
{this.asset=asset;if(this.ip=='')
return;var _ref=this;var _url=this.apiUrl+asset.sourceIp;this.getJSON(_ref,_ref.displayLocations,_url);},getJSON:function(objReference,objCallBackFnc,jsonUrl)
{var _index=this.callQueue.length;this.callQueue[_index]=new YAHOO.ea.sp.geo.jsHandler(objReference,objCallBackFnc,_index);var elem=document.createElement("script");elem.id="script"+_index;elem.src=jsonUrl+this.callbackString;document.body.appendChild(elem);},mapIt:function()
{if(this.map&&this.asset)
{var innerHTML=this.templates.render('asset-bubble-insides',this.asset);var thumbUrl=this.templates.render('asset-image-url',this.asset);var bubble=new YAHOO.ea.sp.geo.AssetBubble(this.asset.latLng,thumbUrl,innerHTML);this.map.addOverlay(bubble);if(YAHOO.util.Dom.getStyle(this.autopanOn,'display')=='block')
this.panToAsset(bubble.assetLatLng,185,185,145,185);GEvent.addDomListener(bubble.div,"mouseover",function(e){bubble.div.style.zIndex='1000';});GEvent.addDomListener(bubble.div,"mouseout",function(e){bubble.div.style.zIndex='500';});var fetchFreq=4000;var removeFreq=60000;var removeBubble=(function(marker,map){return function(){map.removeOverlay(marker);}}(bubble,this.map));window.setInterval(removeBubble,removeFreq);if(this.fetchAssetTimer==null)
this.fetchAssetTimer=window.setInterval(this.fetchNewAsset,fetchFreq);}},panToAsset:function(latLng,top,right,bottom,left)
{point=this.map.fromLatLngToContainerPixel(latLng);var mapDimensions=this.map.getSize();var horizontal=0;var vertical=0;if(point.x-left<0)
horizontal=Math.abs(point.x-left);if(point.x+right>mapDimensions.width)
horizontal=mapDimensions.width-(point.x+right);if(point.y-top<0)
vertical=Math.abs(point.y-top);if(point.y+bottom>mapDimensions.height)
vertical=mapDimensions.height-(point.y+bottom);if(horizontal||vertical)
this.map.panBy(new GSize(horizontal,vertical));},toggleAutopan:function()
{if(YAHOO.util.Dom.getStyle(this.autopanOn,'display')=='block')
{YAHOO.util.Dom.setStyle(this.autopanOff,'display','block');YAHOO.util.Dom.setStyle(this.autopanOn,'display','none');}
else
{YAHOO.util.Dom.setStyle(this.autopanOff,'display','none');YAHOO.util.Dom.setStyle(this.autopanOn,'display','block');}},fetchNewAsset:function()
{var idx=0;if(this.ipMapApp)
{this.ipMapApp.newAssetIndex=this.ipMapApp.newAssetIndex-1;if(this.ipMapApp.newAssetIndex>0)
idx=this.ipMapApp.newAssetIndex;else
this.ipMapApp.newAssetIndex=74;}
else
{this.newAssetIndex=this.newAssetIndex-1;if(this.newAssetIndex>0)
idx=this.newAssetIndex;else
this.newAssetIndex=74;}
if(this.ipMapApp)
{var assetQuery;if(this.ipMapApp.devMode)
assetQuery={index:idx,count:1,view:'RANDOM'};else
assetQuery={index:idx,count:1,view:'NEWEST'};this.assetService.listAssets(assetQuery,this.ipMapApp.bind(this.ipMapApp.fetchedNewAssetLoaded));}
else
{var assetQuery;if(this.devMode)
assetQuery={index:idx,count:1,view:'RANDOM'};else
assetQuery={index:idx,count:1,view:'NEWEST'};this.assetService.listAssets(assetQuery,this.bind(this.fetchedNewAssetLoaded));}},fetchedNewAssetLoaded:function(assetList)
{if(assetList.length>0)
{var dwrAsset=assetList[0];if(dwrAsset.sourceIp)
{this.fetchIpLocation(dwrAsset);}}},geoPlugin:function(geoObject)
{var scriptId=this.callQueue.length-1;if(scriptId<0)
scriptId=0;this.callQueue[scriptId].transferOO(geoObject);},displayLocations:function(lat,long)
{if(lat&&long)
{this.asset.latLng=new GLatLng(lat,long);this.mapIt();}}};YAHOO.lang.augment(YAHOO.ea.sp.geo.IpMappingApplication,YAHOO.ea.sp.Bindable);YAHOO.lang.augment(YAHOO.ea.sp.geo.IpMappingApplication,YAHOO.ea.sp.EventProvider);
