var tweetloc=null;var maptweets=new Array();var months=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];var _username="";var _maxdiff=null;var loc=new CM.Icon();loc.image="img/icon.png";loc.iconSize=new CM.Size(24,24);loc.iconAnchor=new CM.Point(12,24);$(function(){$(".anyClass").jCarouselLite({auto:1000,speed:2500,visible:6});$('#update').bind('click',function(){update()});$("#dialog-update").dialog({autoOpen:false,height:500,width:480,modal:true});});function showInfo(tweetid){map.setCenter(new CM.LatLng(0.0,13.0),1);for(var i=0;i<maptweets.length;i++){if(parseInt(maptweets[i].tweetid)==tweetid){maptweets[i].closeInfoWindow();maptweets[i].openInfoWindow("<b>"+maptweets[i].username+"</b><br/><span style='font-size:0.8em'>"+maptweets[i].loc+"</span>",{pixelOffset:new CM.Size(0,-10)});}}}function showTweet(tweetid){for(var i=0;i<maptweets.length;i++){if(parseInt(maptweets[i].tweetid)==tweetid){maptweets[i].closeInfoWindow();maptweets[i].openInfoWindow("<b>"+maptweets[i].username+"</b><br/>"+maptweets[i].msg,{pixelOffset:new CM.Size(0,-10)});map.setCenter(new CM.LatLng(maptweets[i].lat,maptweets[i].lon),12);}}}function offTweet(tweetid){map.setCenter(new CM.LatLng(0.0,13.0),1);}function update(){$("#dialog-update").dialog('open');}function textCounter(field,cntfield,maxlimit){if($('#zmessage')[0].value.length>116){$('#zmessage')[0].value=$('#zmessage')[0].value.substring(0,116);}else{if($('#zmessage')[0].value.length>=(111)){$('#zcounter')[0].style.color="#ff6666";}else{$('#zcounter')[0].style.color="#6eb0cb";}$('#zcounter')[0].value=116-$('#zmessage')[0].value.length;}}function getData(u,s,n){_username=u;map.closeInfoWindow();if(maptweets){for(var i=0;i<maptweets.length;i++){map.removeOverlay(maptweets[i]);}}maptweets=new Array();var baseurl=location.href.substring(0,location.href.lastIndexOf('/'));var url=baseurl+"/gettweets.php?u="+u+"&s="+s+"&n="+n;var ns=s+100;$('#next').unbind('click');$('#next').bind('click',{s:ns,n:n,u:u},function(event){getData(event.data.u,event.data.s,event.data.n);});var ps=s-100;if(ps<0){ps=0;}$('#prev').unbind('click');$('#prev').bind('click',{s:ps,n:n,u:u},function(event){getData(event.data.u,event.data.s,event.data.n);});$.ajax({url:url,dataType:'json',success:function(data,txtstatus){$('#feed').html("");var mapcount=0;if(data!=null){if(_username!="all"){$('#ztitle').html("geotweets by "+data[0][1]);}var maxlat=0;var minlat=0;var maxlon=0;var minlon=0;var firsttime=true;for(var i=0;i<data.length;i++){if(data[i][3]&&data[i][7].length>0){if(firsttime){maxlat=parseFloat(data[i][3]);minlat=parseFloat(data[i][3]);maxlon=parseFloat(data[i][4]);minlon=parseFloat(data[i][4]);firsttime=false;}tweetloc=new CM.LatLng(parseFloat(data[i][3]),parseFloat(data[i][4]));maptweets[mapcount]=new CM.Marker(tweetloc,{title:data[i][1],icon:loc});maptweets[mapcount].tweetid=data[i][0];maptweets[mapcount].username=data[i][1];maptweets[mapcount].msg=data[i][7];maptweets[mapcount].lat=data[i][3];maptweets[mapcount].lon=data[i][4];maptweets[mapcount].loc=unescape(data[i][2]);maptweets[mapcount].bindInfoWindow("<b>"+maptweets[mapcount].username+"</b><br/>"+maptweets[mapcount].loc,{pixelOffset:new CM.Size(0,-10)});addMarkerClick(maptweets[mapcount]);map.addOverlay(maptweets[mapcount]);if(parseFloat(data[i][3])>maxlat&&data[i][3]!=""&&IsNumeric(data[i][3]))maxlat=data[i][3];else if(parseFloat(data[i][3])<minlat&&data[i][3]!=""&&IsNumeric(data[i][3]))minlat=data[i][3];if(parseFloat(data[i][4])>maxlon&&data[i][4]!=""&&IsNumeric(data[i][4]))maxlon=data[i][4];else if(parseFloat(data[i][4])<minlon&&data[i][4]!=""&&IsNumeric(data[i][4]))minlon=data[i][4];mapcount++;var content="<div title='Click to zoom into the geotweet' id='tweet"+data[i][0]+"' class='tweet' onclick='showTweet("+data[i][0]+")'>";content+="<table id='tb"+data[i][0]+"'><tr><td rowspan='3' valign='top'>";if(data[i][8]){content+="<img src='avatars/"+data[i][8]+"' alt='profile_photo' style='opacity:0.7;filter:alpha(opacity=70);width:48px;height:48px;' />";}else{content+="<img src='img/noimage.png' alt='no image' />";}content+="</td><td><span class='username'>"+data[i][1]+"</span></td></tr>";content+="<tr><td>"+data[i][7]+"</td></tr>";var splitdate=data[i][5].split("-");var date=new Date(parseInt(splitdate[0]),parseInt(splitdate[1]-1),parseInt(splitdate[2]));var month=date.getMonth();var day=date.getDate();var year=date.getFullYear();content+="<tr><td><span class='date'>"+months[month]+" "+day+", "+year+" @</span> <a class='location' href='#'>"+unescape(data[i][2])+"</a></td></tr></table></div>";$('#feed').append(content);$('#tweet'+data[i][0]).bind('mouseenter',{msg:data[i][0]},function(event){showInfo(event.data.msg)});$('#tweet'+data[i][0]).bind('click',{msg:data[i][0]},function(event){showTweet(event.data.msg)});}}_maxdiff=maxlon-minlon>maxlat-minlat?maxlon-minlon:maxlat-minlat;}},error:function(x,txt,e){alert(txt);}});}function addMarkerClick(marker){CM.Event.addListener(marker,'click',function(){var id="#tweet"+marker.tweetid;$(id).delay(800).fadeOut("slow");$(id).fadeIn("slow");$('#feed').scrollTo(id,800,{easing:'elasout'});});}function zoomToLoc(lon,lat){map.setCenter(new CM.LatLng(lon,lat),12);}function updateStatus(){var params={};params.u=$('#zusername').val();params.p=$('#zpassword').val();params.l=$('#zlocation').val();params.m=$('#zmessage').val();$('#update1').attr('src','img/loader.gif');var baseurl=location.href.substring(0,location.href.lastIndexOf('/'));var url=baseurl+"/update.php";$.ajax({type:'POST',url:url,data:params,dataType:'json',success:function(data,txtstatus){if(!data.error){$('#dialog-update').html("<center><br/><br/><b>"+data.username+", your geotweet was posted successfully.</b></center><br/><br/>");$('#dialog-update').append("<center><span style='color:#3B85C1'>Your personal URL is <a href='"+data.url+"' class='info' target='_blank'>"+data.url+"</a>.<br/>It has also been appended to your last tweet!</span></center>");$('#dialog-update').append("<br/><center><img src='img/back.png' alt='Back to geotweeter' title='Show my location on the map' onclick='location.reload(true)' /></center>");$('#dialog-update').dialog({height:300});}else if(data.error="creds"){alert('Please make sure you entered a username and password');$('#update1').attr('src','img/geotweet.png');}else{alert(data.error);$('#update1').attr('src','img/geotweet.png');}},error:function(x,txt,e){alert('Please check your username & password and try again');$('#zpassword').val("");$('#update1').attr('src','img/geotweet.png');}});}function IsNumeric(sText){var ValidChars="0123456789.";var IsNumber=true;var Char;for(i=0;i<sText.length&&IsNumber==true;i++){Char=sText.charAt(i);if(ValidChars.indexOf(Char)==-1){IsNumber=false;}}return IsNumber;}
