
var localtext=[];var map;var panorama;var geocoder;var wait=false;var tweetsArrayMarker=[];var tweetsArrayMarkerPop=[];var timelineRecords="";var markeronmap=[];var totaltweets=0;var infowindowonmap="";var filt='';var tweet=[];var resultsnumber=100;var updatetimer=30;var timerID=0;var radius=2;var markmgr;var layer_tweets;var layer_latitude;var marker;var circle;var infowindow=[];var lastiwopened=0;var layer;var centerLatitude=true;var idle;var dragend;var start=null;var end=null;var travelmode;var showClip=false;var panoramioLayer;var showTweets=true;var showPhotos=false;var lastAddressPosition='';var directionsDisplay;var directionsService;var oldDirections=[];var currentDirections=null;var manageFilter=function(){jQuery(function($){filt=localtext[currentLanguage()].filter;$('#address').watermark(localtext[currentLanguage()].search,{useNative:false});$('#address_from').watermark(localtext[currentLanguage()].address_from,{useNative:false});$('#address_to').watermark(localtext[currentLanguage()].address_to,{useNative:false});$('#filter').watermark(localtext[currentLanguage()].filter);$('#numberresultsslide').slider({range:"min",value:resultsnumber,min:1,max:100,slide:function(event,ui){document.getElementById("numberresultstitle").innerHTML=localtext[currentLanguage()].last+' '+ui.value+' tweets';},change:function(event,ui){resultsnumber=ui.value;deleteTweetsMarkers();GettheTweets();}});document.getElementById("numberresultstitle").innerHTML=localtext[currentLanguage()].last+' '+$("#numberresultsslide").slider("value")+' tweets';$('#radiusslider').slider({range:"min",value:radius,min:1,max:2500,slide:function(event,ui){document.getElementById("radiusslidertitle").innerHTML=localtext[currentLanguage()].radius+' '+ui.value+' km';},change:function(event,ui){radius=ui.value;deleteTweetsMarkers();GettheTweets();fitBoundsDiameter(radius,true);}});document.getElementById("radiusslidertitle").innerHTML=localtext[currentLanguage()].radius+' '+$("#radiusslider").slider("value")+' km';$('#timeslider').slider({range:"min",value:updatetimer,min:0,max:300,step:30,slide:function(event,ui){document.getElementById("timeslidertitle").innerHTML=localtext[currentLanguage()].updateevery+' '+ui.value+localtext[currentLanguage()].seconds;},change:function(event,ui){updatetimer=ui.value;clearTimeout(timerID);if(updatetimer!=0){timerID=setTimeout("executeEveryTimer(updatetimer);",updatetimer*1000);}}});document.getElementById("timeslidertitle").innerHTML=localtext[currentLanguage()].updateevery+' '+$("#timeslider").slider("value")+localtext[currentLanguage()].seconds;timerID=setTimeout("executeEveryTimer(updatetimer);",updatetimer*1000);});}
var executeEveryTimer=function(updatetimer){deleteTweetsMarkers();GettheTweets();timerID=setTimeout("executeEveryTimer(updatetimer);",updatetimer*1000);}
var fitBoundsDiameter=function(diameter,fit){try{circle.setMap(null)}catch(e){};if(showTweets==true){circle=new google.maps.Circle({center:map.getCenter(),fillcolor:"#000000",strokeWeight:0,strokeColor:"#000000",strokeOpacity:0.05,fillOpacity:0.05,radius:diameter*1000});circle.setMap(map);if(fit==true)
map.fitBounds(circle.getBounds());}}
var initialize=function(){var myOptions={zoom:13,mapTypeControlOptions:{style:google.maps.MapTypeControlStyle.DROPDOWN_MENU},navigationControl:true,navigationControlOptions:{style:google.maps.NavigationControlStyle.DEFAULT},mapTypeId:google.maps.MapTypeId.ROADMAP}
map=new google.maps.Map(document.getElementById("map_canvas"),myOptions);panorama=map.getStreetView();directionsService=new google.maps.DirectionsService();directionsDisplay=new google.maps.DirectionsRenderer({'map':map,'preserveViewport':false,'draggable':true});directionsDisplay.setPanel(document.getElementById("directions"));travelmode=google.maps.DirectionsTravelMode.DRIVING;map.setTilt(45);geocoder=new google.maps.Geocoder();layer_tweets=new MarkerManager(map);var hash=window.location.hash.replace("#","");var latobj=0;lonobj=0
var loc=null;if(hash!=''){var hashparts=hash.split('&');location.hash='';if(hashparts[1]){var llhash=hashparts[1].replace('ll=','');var ll=llhash.split(",");if(ll[0]&&ll[1]&&ll[2]&&ll[3]){var zoomobj=ll[3];radius=ll[2]*1000;var latobj=ll[0];var lonobj=ll[1];var loc=null;if(ll[4]&&ll[5]){var pos=new google.maps.LatLng(ll[4],ll[5])
var mark=new google.maps.Marker({map:map,position:pos});}}else{var zoomobj=2;var loc=google.loader.ClientLocation;}}else{var zoomobj=2;var loc=google.loader.ClientLocation;}
document.getElementById("filter").value=hashparts[0];}else{var zoomobj=2;var loc=google.loader.ClientLocation;}
manageFilter();if(loc!=null){var myLatlng=new google.maps.LatLng(loc.latitude,loc.longitude);map.setCenter(myLatlng);idle=google.maps.event.addListener(map,'idle',function(event){showContent(true);google.maps.event.removeListener(idle);});}else{var myLatlng=new google.maps.LatLng(latobj,lonobj);map.setCenter(myLatlng);map.setZoom(parseInt(zoomobj));idle=google.maps.event.addListener(map,'idle',function(event){showContent();google.maps.event.removeListener(idle);});}
google.maps.event.addListener(map,'zoom_changed',function(event){if(showClip){updateClip();}});google.maps.event.addListener(map,'dragend',function(event){showContent();if(showClip){updateClip();}});google.maps.event.addListener(directionsDisplay,'directions_changed',function(){if(currentDirections){oldDirections.push(currentDirections);setUndoDisabled(false);}
currentDirections=directionsDisplay.getDirections();});setUndoDisabled(true);panoramioLayer=new google.maps.panoramio.PanoramioLayer();}
var showPanoramio=function(){if(showPhotos==false){showPhotos=true;panoramioLayer.setMap(map);$('#panoramio').html('<img onclick="showPanoramio()" title="Photos" class="cursor" src="img/panoramio-on.png">');}else{showPhotos=false;panoramioLayer.setMap(null);$('#panoramio').html('<img onclick="showPanoramio()" title="Photos" class="cursor" src="img/panoramio-off.png">');}}
var showGeotweets=function(){if(showTweets==false){showTweets=true;collapseHorizontal=false;CollapseHorizontal();GettheTweets();fitBoundsDiameter(radius,true);$('#twitterbutton').html('<img onclick="showGeotweets()" title="Geotweets" class="cursor" src="img/twitter-on.png">');}else{deleteTweetsMarkers();showTweets=false;collapseHorizontal=true;CollapseHorizontal();$('#twitterbutton').html('<img onclick="showGeotweets()" title="Geotweets" class="cursor" src="img/twitter-off.png">');}}
var showContent=function(trueorfalse){if(trueorfalse==null)
trueorfalse=false;deleteTweetsMarkers();GettheTweets();fitBoundsDiameter(radius,trueorfalse);}
var getlatlonzoom=function(){if(showClip==false){$('#copytextbox').show();showClip=true;updateClip();$("#clip").html('<img onclick="getlatlonzoom();" class="cursor" title="Copy link"  src="img/clip-on.png">');}else{showClip=false;$('#copytextbox').hide();$("#clip").html('<img onclick="getlatlonzoom();" class="cursor" title="Copy link"  src="img/paperclip.png">');}}
var updateClip=function(){var filter=document.getElementById("filter").value;if(filter!=null&&filter!=filt){filter=document.getElementById("filter").value.replace('#','%23');}else{filter='';}
if(lastAddressPosition!=''){var lastpos=','+lastAddressPosition;}else{var lastpos='';}
var ll=map.center.lat()+','+map.center.lng()+','+radius/1000+','+map.getZoom()+lastpos;$('#copytextbox').val('http://metaki.com/#'+filter+'&ll='+ll);$('#copytextbox').focus();$('#copytextbox').select();}
var deleteOverlays=function(){if(ArrayMarkersPop){for(i in ArrayMarkersPop){ArrayMarkersPop[i].setMap(null);}
ArrayMarkersPop.length=0;}}
var filterChanges=function(){if(showClip){updateClip();}
deleteOverlays();GettheTweets();}
var currentLanguage=function(){var lang='';if(navigator.appName=='Netscape')
var language=navigator.language;else
var language=navigator.browserLanguage;if(language.indexOf('en')>-1)lang='en';else if(language.indexOf('es')>-1)lang='es';else lang='es';return lang;};var GettheTweets=function(){if(showTweets)
GetTweets(map.center.lat(),map.center.lng());}
var GetTweets=function(lat,lng){loading(true);var query='';var filter=document.getElementById("filter").value;if(filter!=null&&filter!=filt){query='&q='+document.getElementById("filter").value.replace('#','%23');}
timelineRecords='';$.getJSON("http://search.twitter.com/search.json?geocode="+lat+","+lng+","+radius+"km&callback=?&count="+resultsnumber+query,function(data){var currentdate=new Date();timelineRecords='';$('#timeline').html('');$.each(data.results,function(i,item){totaltweets=i;var hasPoint=false;if(item.geo!=null&&item.geo.type=='Point'){hasPoint=true;tweet[i]={profile_image_url:item.profile_image_url,from_user:item.from_user,text:item.text,location:item.location,created_at:item.created_at,to_user_id:item.to_user_id,id:item.id,hasPoint:hasPoint};var tweettext=$([item.text]).linkUrl().linkUser().linkHash()[0];timelineRecords+=addRecordTimeLine(item.profile_image_url,48,48,i,item.from_user,tweettext,item.location,timeAgo(item.created_at,currentdate.toUTCString()),item.to_user_id,hasPoint,item.id_str);var coordinate=item.geo.coordinates.toString();var latlng=coordinate.split(',');var marker=CreateMarker(item.profile_image_url,48,48,latlng[0],latlng[1],i,item.from_user,tweettext,'',timeAgo(item.created_at,currentdate.toUTCString()),item.id_str);}});$('#timeline').html(timelineRecords);$.each(data.results,function(i,item){});loading(false);});}
var addRecordTimeLine=function(imageavatar,w,h,i,from_user,text,location,created_at,to_user_id,hasPoint,id){var ret='';ret+='<div id="tweet" onClick="try{infowindow[lastiwopened].close()}catch(e){};if(panorama.getVisible()){infowindow['+i+'].open(panorama,markeronmap['+i+'])}else{infowindow['+i+'].open(map,markeronmap['+i+'])};lastiwopened='+i+';centerLatitude=false;" class="tweet_record_tl">';ret+='<div class="avatar_tl"><a target="_blank" href="https://twitter.com/intent/user?screen_name='+from_user+'"><img width="'+w+'" height="'+h+'" border="0" src="'+imageavatar+'" /></a></div>';ret+='<div class="data_tl">';ret+='<div><a target="_blank" href="https://twitter.com/intent/user?screen_name='+from_user+'">'+from_user+'</a></div>';ret+='<div>'+text+'</div><div></div>';ret+='<div style="color:gray;">'+created_at+'</div>'
ret+='<span><a href="https://twitter.com/intent/tweet?in_reply_to='+id+'">'+localtext[currentLanguage()].reply+'</a> <a href="https://twitter.com/intent/retweet?tweet_id='+id+'">'+localtext[currentLanguage()].retweet+'</a> <a href="https://twitter.com/intent/favorite?tweet_id='+id+'">'+localtext[currentLanguage()].favorite+'</a></span>';ret+='</div>';ret+='</div>';return ret;}
var geocodeAddress=function(){var address=document.getElementById("address").value;if(geocoder){geocoder.geocode({'address':address},function(results,status){if(status==google.maps.GeocoderStatus.OK){map.setCenter(results[0].geometry.location);var mark=new google.maps.Marker({map:map,position:results[0].geometry.location});alert(results[0].geometry.location.latitude);showContent();}else{alert("Geocode was not successful for the following reason: "+status);}});}}
var CreateMarker=function(imagefile,w,h,lat,lng,i,from_user,text,location,created_at,id){var myLatlng=new google.maps.LatLng(lat,lng);var title='<div class="infowindow"><img width="48px" height="48px" class="avatar" border="0" align="left" src="'+
imagefile+'" /><div class="from_user"><a target="_blank" href="https://twitter.com/intent/user?screen_name='+from_user+'">'+
from_user+'</a></div><div>'+text+' </div><br><br><div class="graytext">Creado: '+created_at+'<br>'+'<span><a href="https://twitter.com/intent/tweet?in_reply_to='+id+'">'+localtext[currentLanguage()].reply+'</a> <a href="https://twitter.com/intent/retweet?tweet_id='+id+'">'+localtext[currentLanguage()].retweet+'</a> <a href="https://twitter.com/intent/favorite?tweet_id='+id+'">'+localtext[currentLanguage()].favorite+'</a></span>'+'<div class="hyperlink" onClick="zoomin();">Acercar</div><div class="hyperlink" onClick="zoomout();">Alejar</div></div>';infowindow[i]=new google.maps.InfoWindow({content:title,position:myLatlng});var image=new google.maps.MarkerImage(imagefile,new google.maps.Size(22,22),new google.maps.Point(0,0),new google.maps.Point(11,32),new google.maps.Size(22,22));var marker_tweet=new google.maps.Marker({position:myLatlng,map:map,icon:image,zIndex:10000,title:'@'+from_user+' '+text});var marker_icon=new google.maps.Marker({position:myLatlng,map:map,icon:"img/marker.png",zIndex:9999,title:'@'+from_user+' '+text});markeronmap[i]=marker_tweet;new google.maps.event.addListener(markeronmap[i],'click',function(){try{infowindow[lastiwopened].close();}catch(e){};if(panorama.getVisible()){infowindow[i].open(panorama,this);}else{infowindow[i].open(map,this);}
lastiwopened=i;});layer_tweets.addMarker(marker_icon,0,19);layer_tweets.addMarker(marker_tweet,0,19);}
var zoomin=function(){if(map.getZoom()<20)
map.setZoom(map.getZoom()+1);}
var zoomout=function(){if(map.getZoom()>1)
map.setZoom(map.getZoom()-1);}
var deleteTweetsMarkers=function(){layer_tweets.clearMarkers();}
$(document).ready(function(){$("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'fast',opacity:0.80,showTitle:false,allowresize:false,default_width:500,default_height:344,counter_separator_label:'/',theme:'facebook',hideflash:false,wmode:'opaque',autoplay:true,modal:false,changepicturecallback:function(){},callback:function(){},markup:'<div class="pp_pic_holder"> \
      <div class="pp_top"> \
       <div class="pp_left"></div> \
       <div class="pp_middle"></div> \
       <div class="pp_right"></div> \
      </div> \
      <div class="pp_content_container"> \
       <div class="pp_left"> \
       <div class="pp_right"> \
        <div class="pp_content"> \
         <div class="pp_fade"> \
          <a href="#" class="pp_expand" title="Expand the image">Expand</a> \
          <div class="pp_loaderIcon"></div> \
          <div class="pp_hoverContainer"> \
           <a class="pp_next" href="#">next</a> \
           <a class="pp_previous" href="#">previous</a> \
          </div> \
          <div id="pp_full_res"></div> \
          <div class="pp_details clearfix"> \
           <a class="pp_close" href="#">Close</a> \
           <p class="pp_description"></p> \
           <div class="pp_nav"> \
            <a href="#" class="pp_arrow_previous">Previous</a> \
            <p class="currentTextHolder">0/0</p> \
            <a href="#" class="pp_arrow_next">Next</a> \
           </div> \
          </div> \
         </div> \
        </div> \
       </div> \
       </div> \
      </div> \
      <div class="pp_bottom"> \
       <div class="pp_left"></div> \
       <div class="pp_middle"></div> \
       <div class="pp_right"></div> \
      </div> \
     </div> \
     <div class="pp_overlay"></div> \
     <div class="ppt"></div>',image_markup:'<img id="fullResImage" src="" />',flash_markup:'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{width}" height="{height}"><param name="wmode" value="{wmode}" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="{path}" /><embed src="{path}" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="{width}" height="{height}" wmode="{wmode}"></embed></object>',quicktime_markup:'<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="{height}" width="{width}"><param name="src" value="{path}"><param name="autoplay" value="{autoplay}"><param name="type" value="video/quicktime"><embed src="{path}" height="{height}" width="{width}" autoplay="{autoplay}" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>',iframe_markup:'<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',inline_markup:'<div class="pp_inline clearfix">{content}</div>'});});var AddLoginLogoutTwitterButton=function(){jQuery(function(){twttr.anywhere(function(T){var currentUser,screenName,profileImage,profileImageTag;if(T.isConnected()){currentUser=T.currentUser;screenName=currentUser.data('screen_name');profileImage=currentUser.data('profile_image_url');profileImageTag="<img src='"+profileImage+"'/>";$('#login').append("Logged in as "+profileImageTag+" "+screenName);}else{T("#login").connectButton();};});});}
var mapGPSCenter=function(){if(navigator.geolocation){navigator.geolocation.getCurrentPosition(function(position){var initialLocation=new google.maps.LatLng(position.coords.latitude,position.coords.longitude);map.panTo(initialLocation);showContent(true);});}else{alert('El navegador no puede localizarte o el GPS no est‡ activo!');}}
google.maps.event.addDomListener(window,'load',initialize);lastAddressPosition='';$().ready(function(){$('#address').geo_autocomplete(new google.maps.Geocoder,{mapkey:'ABQIAAAAbnvDoAoYOSW2iqoXiGTpYBTIx7cuHpcaq3fYV4NM0BaZl8OxDxS9pQpgJkMv0RxjVl6cDGhDNERjaQ',selectFirst:true,minChars:3,cacheLength:50,width:400,scroll:true,scrollHeight:330}).result(function(_event,_data){if(_data){map.fitBounds(_data.geometry.viewport);var mark=new google.maps.Marker({map:map,position:_data.geometry.location});lastAddressPosition=_data.geometry.location.lat()+','+_data.geometry.location.lng();showContent();}});$('#address_from').geo_autocomplete(new google.maps.Geocoder,{mapkey:'ABQIAAAAbnvDoAoYOSW2iqoXiGTpYBTIx7cuHpcaq3fYV4NM0BaZl8OxDxS9pQpgJkMv0RxjVl6cDGhDNERjaQ',selectFirst:true,minChars:3,cacheLength:50,width:400,scroll:true,scrollHeight:330}).result(function(_event,_data){if(_data){start=_data.geometry.location;calcRoute();}});$('#address_to').geo_autocomplete(new google.maps.Geocoder,{mapkey:'ABQIAAAAbnvDoAoYOSW2iqoXiGTpYBTIx7cuHpcaq3fYV4NM0BaZl8OxDxS9pQpgJkMv0RxjVl6cDGhDNERjaQ',selectFirst:true,minChars:3,cacheLength:50,width:400,scroll:true,scrollHeight:330}).result(function(_event,_data){if(_data){end=_data.geometry.location;calcRoute();}});});var searchOrRoute=function(option){if(option==1){$('#search_address').show();$('#search_route').hide();$('#searchbutton').css({'background-image':'url(img/search-sel.png)','width':'28px','height':'28px'});$('#routebutton').css({'background-image':'url(img/route.png)','width':'33px','height':'17px'});start=null;end=null;$('#directions_panel').hide();directionsDisplay.setMap(null);}else{directionsDisplay.setMap(map);$('#search_address').hide();$('#search_route').show();$('#searchbutton').css({'background-image':'url(img/search.png)','width':'24px','height':'25px'});$('#routebutton').css({'background-image':'url(img/route-sel.png)','width':'36px','height':'20px'});}}
var inverse=function(){var from=document.getElementById("address_from").value;var to=document.getElementById("address_to").value;var fromok=from;var took=to;if(from!=localtext[currentLanguage()].address_from)
{took=from;}else{took='';}
if(to!=localtext[currentLanguage()].address_to)
{fromok=to;}else{fromok='';}
$("#address_from").val(fromok);$("#address_to").val(took);$('#address_from').watermark(localtext[currentLanguage()].address_from,{useNative:false});$('#address_to').watermark(localtext[currentLanguage()].address_to,{useNative:false});}
var undo=function(){currentDirections=null;directionsDisplay.setDirections(oldDirections.pop());if(!oldDirections.length){setUndoDisabled(true);}}
var setUndoDisabled=function(value){}
var calcRoute=function(){if(start!=null&&end!=null){$('#directions_panel').show();var request={origin:start,destination:end,travelMode:travelmode};directionsService.route(request,function(response,status){if(status==google.maps.DirectionsStatus.OK){directionsDisplay.setDirections(response);}});}}
