/*
 * TweetMap 0.1 - jQuery twitter map widget
 *
 * Copyright (c) 2009 Simon Wood (http://www.hpoom.co.uk/)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Revision: $Id: jquery.tweetMap.js 2009-08-21 $
 *
 */


(function($){jQuery.fn.tweetMap=function(options){var settings=jQuery.extend({search:"jQuery",animate:false},options);var defaults={lat:44.0,long:-100.0,zoom:3,disableDefaultUI:true,mapTypeId:google.maps.MapTypeId.SATELLITE};return this.each(function(){var elmThis=this;var center=new google.maps.LatLng(defaults.lat,defaults.long);var map=new google.maps.Map(this,$.extend(defaults,{center:center}));$(elmThis).data('aMarkers',new Array());$(elmThis).data('map',map);$(elmThis).data('animateCount',0);var twitterUrl='http://twitter.com/statuses/public_timeline.json?callback=?'
$.getJSON(twitterUrl,function(data){$.each((data.results?data.results:data),function(resultIndex,result){if(result.user.location&&result.user.location!=''){var geocoder=new google.maps.Geocoder();geocoder.geocode({address:result.user.location},function(results,status){if(status==google.maps.GeocoderStatus.OK&&results.length){if(status!=google.maps.GeocoderStatus.ZERO_RESULTS){map.set_center(results[0].geometry.location);var marker=new google.maps.Marker({position:results[0].geometry.location,map:map});var infoWindow=new google.maps.InfoWindow({content:'<img src="'+result.user.profile_image_url+'" alt="'+result.user.screen_name+'" style="float:left;" /><div style="float:left;"><h3 style="line-height:0px;padding-left:10px;">'+result.user.screen_name+'</h3><em style="line-height:0px;padding-left:10px;">'+result.user.name+'</em></div><br/><br/><div style="clear:both;padding-top:10px;padding-bottom:25px">'+result.text+'</div>',maxWidth:280});var aTempMarkers=$(elmThis).data('aMarkers');aTempMarkers[aTempMarkers.length]={'marker':marker,'info':infoWindow};$(elmThis).data('aMarkers',aTempMarkers);}}});}});});setTimeout(function(){$.tweetMap.animate(elmThis);},$.tweetMap.animateSpeed);});};jQuery.tweetMap={animate:function(tweetMapElm){var aTempMarkers=$(tweetMapElm).data('aMarkers');var map=$(tweetMapElm).data('map');var animateCount=$(tweetMapElm).data('animateCount');if(animateCount==0){aTempMarkers[aTempMarkers.length-1].info.close();}else{aTempMarkers[animateCount-1].info.close();}
aTempMarkers[animateCount].info.open(map,aTempMarkers[animateCount].marker);if(animateCount==(aTempMarkers.length-1)){$(tweetMapElm).data('animateCount',0);}else{$(tweetMapElm).data('animateCount',animateCount+1);}
setTimeout(function(){$.tweetMap.animate(tweetMapElm);},$.tweetMap.animateSpeed);},animateSpeed:5000};})(jQuery);