
var sotn={map:null,tweets:[],queue:[],geocoder:null,slide:500,fade:250,goodIcon:null,badIcon:null,latest:0,popup:null,marker:null,cookie:'sotn-start',lastPanel:false};$(document).ready(function(){$.ajaxSetup({'timeout':10000});google.load('maps','2.x',{'callback':mapsInit});$('#footer #bar a#toggle').click(toggleTopics).oneTime('2s',function(){$(this).click();});$(document).everyTime('30s',getTweets).oneTime('1s',getTweets);$('#map').everyTime('500ms',moveControls);$('a[rel=about]').click(showAbout);$('a[rel=terms]').click(showTerms);$('a[rel=privacy]').click(showPrivacy);$('a[rel=close], #modal').click(closePanel);$(window).resize(windowResize).load(windowResize).load(firstTime);swfobject.embedSWF('../ads/free_hotels_nights/468x60.swf?clickTag=http%3A//www.lastminute.com/site/travel/hotels/','ad','468','60','9.0.0');});function showAbout(){showPanel('#about');return false;}
function showTerms(){if($('#terms .content').html().length<50){$("#terms .content").load("./terms.html");}
showPanel('#terms');return false;}
function showPrivacy(){if($('#privacy .content').html().length<50){$("#privacy .content").load("./privacy.html");}
showPanel('#privacy');return false;}
function firstTime(){if($.cookie(sotn.cookie)==null){$.cookie(sotn.cookie,'true',{path:'/',expires:365});$(document).oneTime('1s',function(){showPanel('#hello');});}}
function mapsInit(){if(GBrowserIsCompatible()){sotn.map=new GMap2(document.getElementById('map'));sotn.map.addControl(new GLargeMapControl3D(),new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(10,100)));sotn.map.addMapType(G_PHYSICAL_MAP);sotn.map.setMapType(G_PHYSICAL_MAP);sotn.map.enableScrollWheelZoom();sotn.map.enableContinuousZoom();sotn.geocoder=new GClientGeocoder();sotn.goodIcon=new GIcon();sotn.goodIcon.image='./images/good-icon.png';sotn.goodIcon.shadow='';sotn.goodIcon.iconSize=new GSize(32,32);sotn.goodIcon.iconAnchor=new GPoint(16,16);sotn.goodIcon.infoWindowAnchor=new GPoint(16,16);sotn.goodIcon.transparent='';sotn.badIcon=new GIcon(sotn.goodIcon);sotn.badIcon.image='./images/bad-icon.png';GEvent.addListener(sotn.map,'zoomend',zoomChange);centerMap(new GLatLng(54,-4));}
else{alert('Sorry, Google Maps cannot be displayed.');}}
function windowResize(){$('#ad').toggle(($(window).width()>1125))
centreAllPanels();}
function zoomChange(oldLevel,newLevel){if(sotn.popup)sotn.popup.redraw(true);}
function moveControls(){$('#logocontrol').css('bottom','8px');$('.terms-of-use-link').parent().attr('id','copyright');$('#copyright').css('bottom','8px');if($('#logocontrol, #copyright').length==2)$('#map').stopTime();}
function toggleTopics(){var tv=($('#footer').css('bottom')=='-188px');var tb=tv?'0px':'-188px';var cb=tv?'240px':'50px';var lc=tv?'240px':'50px';var mb=tv?'228px':'40px';$('#footer').animate({'bottom':tb},sotn.slide);$('#logocontrol').animate({'bottom':lc},sotn.slide);$('#copyright').animate({'bottom':cb},sotn.slide);$('a#toggle').toggleClass('up',tv);return false;}
function centerMap(latLng){sotn.map.setCenter(latLng,5);}
function generateSearchUrl(){return'./app/json.php?since='+sotn.latest;}
function getTweets(){$.getJSON(generateSearchUrl(),function(data){if(data){if(data.tweets){data.tweets=data.tweets.sort(sortTweets);$.each(data.tweets,function(i,tweet){tweet.latlng=new GLatLng(tweet.home_latitude,tweet.home_longitude);if(tweet.home_located>0)plotTweet(tweet);logTweet(tweet);sotn.tweets.push(tweet);});}
sotn.latest=data.latest;}});}
function processQueue(){if(sotn.queue.length>0){var tweet=sotn.queue.pop();tweet.latlng=new GLatLng(tweet.home_latitude,tweet.home_longitude);if(tweet.home_located)plotTweet(tweet);logTweet(tweet);sotn.tweets.push(tweet);}}
function plotTweet(tweet){var icon=(tweet.good_mood>0?sotn.goodIcon:sotn.badIcon);tweet.marker=new GMarker(tweet.latlng,icon);GEvent.addListener(tweet.marker,'click',function(){showPopUp(tweet);});sotn.map.addOverlay(tweet.marker);}
function iconUrl(tweet,focus){if(focus)return(tweet.good_mood>0)?'./images/good-icon-focus.png':'./images/bad-icon-focus.png';return(tweet.good_mood>0)?'./images/good-icon.png':'./images/bad-icon.png';}
function showPopUp(tweet){closePopUp();var html=$('<div class="profile"><a href="http://twitter.com/'+tweet.from_user+'" target="_blank"><img alt="*" src="'+tweet.profile_image_url+'" /></a></div><div class="text"><a class="close" href="#"></a><h3><a href="http://twitter.com/'+tweet.from_user+'" target="_blank">@'+tweet.from_user+'</a></h3><p>'+tweet.text+'</p><small>Tweeted at '+tweet.tweeted_at+'</small></div>');html.find('.close').click(closePopUp);sotn.popup=new PopUp(tweet.latlng,html);sotn.popup.tweet=tweet;sotn.popup.show(sotn.map,tweet.good_mood>0?'good':'bad');tweet.marker.setImage(iconUrl(tweet,true));sotn.map.panTo(tweet.latlng);}
function closePopUp(){if(sotn.popup){sotn.popup.remove();sotn.popup.tweet.marker.setImage(iconUrl(sotn.popup.tweet,false));}
return false;}
function PopUp(latlng,html){this.latlng_=latlng;this.html_=html;this.prototype=new GOverlay();this.show=function(map,className){this.map_=map;this.div_=$('<div id="popup" />').appendTo(map.getPane(G_MAP_FLOAT_PANE));this.div_.addClass(className).hide();this.update(this.html_);this.div_.show();}
this.update=function(html){this.html_=html;this.div_.empty().append(html).hide().fadeIn(150);this.redraw(true);}
this.remove=function(){this.div_.remove();}
this.redraw=function(force){if(!force)return;var point=this.map_.fromLatLngToDivPixel(this.latlng_);this.div_.css({left:point.x+10,top:point.y-20});}}
function logTweet(tweet){var li='<li class="'+(tweet.good_mood>0?'good':'bad')+'"><div class="profile"><a href="http://twitter.com/'+tweet.from_user+'" target="_blank"><img alt="*" src="'+tweet.profile_image_url+'" /></a></div><div class="text">';if(tweet.home_located>0)li+='<a class="zoom" href="#"></a>';li+='<h3><a href="http://twitter.com/'+tweet.from_user+'" target="_blank">@'+tweet.from_user+'</a></h3><p>'+linkify(tweet.text)+'</p><small>Tweeted at '+tweet.tweeted_at+'</small></div></li>';$('#footer #tweets ul').prepend(li).find('li:first').hide().fadeIn(250).click(function(){showPopUp(tweet);});$('#footer #tweets ul').css('width',$('#footer #tweets ul li').length*240);}
function linkify(text){if(text==null)return;var urls=text.match(/http\S+/ig);if(urls){for(u=0;u<urls.length;u++){var url=urls[u];var t=(url.length>30)?url.substr(0,27)+'...':url;var a='<a href="'+url+'" target="_blank">'+t+'</a>';text=text.replace(url,a);}}
return text;}
function closePanel(){if(sotn.lastPanel){showPanel('#'+sotn.lastPanel);sotn.lastPanel=false;}
else{hidePanels();}
return false;}
function showPanel(selector){panel=$(selector);if($('.panel:visible').length>0){$('.panel:visible').fadeOut(sotn.fade,function(){panel.fadeIn(sotn.fade);});}
else{if(panel.hasClass('modal')){$('#modal').fadeIn(sotn.fade);}
panel.fadeIn(sotn.fade);}}
function hidePanels(){$('#modal:visible, .panel:visible').fadeOut(sotn.fade);return false;}
function centrePanels(selector){$(selector).each(function(){var l=($(window).width()-$(this).outerWidth())/2;var b=(($(window).height()-$(this).outerHeight())/2);$(this).css('left',l).css('bottom',b);});}
function centreAllPanels(){centrePanels('.panel');}
function sortTweets(x,y){return x.status_id-y.status_id;}