/**********************************
 * GeoImpress - v1.6 - gi.js
 * copyright by Hoelle Development e.U., Thomas Teufel, 2011
 * office@hoelle.net
 **********************************/

var gi={};$(document).ready(function(){gi.$map=$("div#g_map");gi.$mapClose=$("div#map_close");gi.$head=$("head").get(0);gi.$content=$("div#content");gi.$precision=$("div#precision");gi.$precisionSlider=gi.$precision.find("div#precision_slider");gi.precisionLayer;gi.precisionCircle;gi.precisionCircleImg;gi.$precisionRefresh=$("div#precision div#refresh");gi.$service=$("div#service select#services");gi.serviceKeyPics=gi.$service.find("option").get(0).value;gi.serviceKeyTweets=gi.$service.find("option").get(1).value;gi.$extras=$("div#extras");gi.$extrasOpen=$("div#extras_open");gi.$addressSearchForm=$("form.address_search");gi.$random=$("a.random");gi.$homeLocation=$("div#homelocation");gi.$twitterBird=$("div#twitter_bird");gi.ajaxRequest=$.ajax();gi.twitterBirdRequest=$.ajax();gi.map;gi.mapInnerHtml;gi.mapTotalHeight=parseInt(gi.$map.css("height"));gi.mapSmallPercent=60;gi.newHeight;gi.positionMarker;gi.geoCoder;gi.cLatLng=null;gi.cPoint=null;gi.kmHeight;gi.pxPerLat;gi.pxPerKm;gi.cCircleRadius;gi.homeLatLng=null;gi.homeLocNames;gi.addressSearchDefault=gi.$addressSearchForm.find("input#address").val();gi.addressTmp;gi.requestpage;gi.enhancedAgent=(navigator.userAgent.indexOf("IE")==-1);gi.basicFadeDur=250;gi.loaderDuration=4000;gi.tweetsSince=Math.floor((new Date().getTime())/60000)-100;gi.tweetsQuerySplit;gi.tweetsStack=new Array();gi.lastTweetAdded=-1;gi.tweetsAdded=0;gi.tweetsOnDisplay=0;gi.tweetsPerPage=13;gi.tweetPages=20;gi.tweetTimeout=1000;gi.tweetInterval=false;gi.initialize=function(){mapInnerHtml=gi.$map.html();gi.geoCoder=new google.maps.Geocoder();gi.mapOptions={backgroundColor:$("div#box").css("backgroundColor"),mapTypeId:google.maps.MapTypeId.ROADMAP,mapTypeControlOptions:{mapTypeIds:new Array(google.maps.MapTypeId.ROADMAP,google.maps.MapTypeId.HYBRID,google.maps.MapTypeId.SATELLITE)},overviewMapControl:true,scaleControl:true,panControl:true,scrollwheel:false,streetViewControl:false,zoom:7};gi.map=new google.maps.Map(gi.$map.get(0),gi.mapOptions);gi.map.setCenter(new google.maps.LatLng(25,15));gi.map.setZoom(2);google.maps.event.addListener(gi.map,"click",function(a){if(a.latLng){gi.cLatLng=a.latLng;gi.startService()}});google.maps.event.addListener(gi.map,"zoom_changed",function(a){gi.maximizeMap()});google.maps.event.addListener(gi.map,"dragstart",function(a){gi.maximizeMap()});google.maps.event.addListener(gi.map,"maptypeid_changed",function(a){gi.maximizeMap()});if(google.loader.ClientLocation){gi.homeLatLng=new google.maps.LatLng(google.loader.ClientLocation.latitude,google.loader.ClientLocation.longitude);gi.homeLocNames=google.loader.ClientLocation.address.country+"/"+google.loader.ClientLocation.address.region+"/"+google.loader.ClientLocation.address.city;gi.$homeLocation.fadeIn(gi.basicFadeDur);gi.$extras.append('<div class="sep"></div><a href="#" class="extra_link home">Focus home location</a></li>');gi.$extras.find("a.home").click(function(a){gi.focusHomeLocation();a.preventDefault()})}if(gi.useStartLocation){gi.cLatLng=new google.maps.LatLng(sLat,sLng);gi.map.setZoom(sZoom);gi.centerLocation();gi.startService()}gi.$map.append(mapInnerHtml);gi.$map.find("div:first").append('<div id="precision_layer"><div id="precision_circle"><img src="img/precision_circle.png" /></div></div>');gi.$precisionLayer=gi.$map.find("div:first div#precision_layer");gi.$precisionCircle=gi.$precisionLayer.find("div#precision_circle");gi.$precisionCircleImg=gi.$precisionCircle.find("img")};gi.$extrasOpen.click(function(a){gi.$extras.slideDown(gi.basicFadeDur);gi.$extrasOpen.fadeOut(gi.basicFadeDur)});gi.$extras.find("a.closer").click(function(a){gi.$extras.slideUp(gi.basicFadeDur);gi.$extrasOpen.fadeIn(gi.basicFadeDur);a.preventDefault()});gi.$addressSearchForm.submit(function(a){if(gi.$addressSearchForm.find("input#address").val()!=""){gi.geoCoder.geocode({address:gi.$addressSearchForm.find("input#address").val()},function(c,b){if(b!=google.maps.GeocoderStatus.OK){gi.printError("nolocation")}else{gi.cLatLng=c.pop().geometry.location;gi.map.setZoom(11);gi.centerLocation();gi.startService()}})}else{gi.printError("noaddress")}a.preventDefault()});gi.$addressSearchForm.find("input#address").focus(function(a){if(gi.$addressSearchForm.find("input#address").val()==gi.addressSearchDefault){gi.$addressSearchForm.find("input#address").get(0).select()}});gi.$addressSearchForm.find("input#address").blur(function(a){if(gi.$addressSearchForm.find("input#address").val()==""){gi.$addressSearchForm.find("input#address").val(gi.addressSearchDefault)}});gi.$random.click(function(a){gi.closePanels();gi.prepareNewContent();gi.ajaxRequest=$.ajax({url:"getrandomloc.php",type:"POST",dataType:"json",error:function(d,c,b){gi.printError("load")},success:function(b){if(b.error=="0"){gi.cLatLng=new google.maps.LatLng(b.lat,b.lng);gi.$precisionSlider.slider("value",50);gi.$precisionRefresh.hide();gi.map.setZoom(11);gi.centerLocation();gi.startService()}else{gi.printError("load")}}});a.preventDefault()});gi.$mapClose.click(function(a){gi.minimizeMap()});gi.focusHomeLocation=function(){gi.$homeLocation.fadeOut(gi.basicFadeDur);gi.cLatLng=gi.homeLatLng;gi.map.setZoom(11);gi.centerLocation();gi.startService()};gi.$homeLocation.find("a:not(a.closer)").click(function(a){gi.focusHomeLocation();a.preventDefault()});gi.$homeLocation.find("a.closer").click(function(a){gi.$homeLocation.fadeOut(gi.basicFadeDur);a.preventDefault()});gi.removeMarker=function(){if(gi.positionMarker){gi.positionMarker.setMap(null);gi.positionMarker=null}};gi.startService=function(){gi.closePanels();gi.prepareNewContent();gi.removeMarker();gi.positionMarker=new google.maps.Marker({map:gi.map,position:gi.cLatLng});if(gi.$service.val()==gi.serviceKeyPics){gi.getPictures(gi.cLatLng,gi.getPrecision());gi.$twitterBird.find("a").get(0).setAttribute("href","/twitterlocation.php?lt="+gi.cLatLng.lat()+"&ln="+gi.cLatLng.lng()+"&z="+gi.map.getZoom()+"&p="+gi.$precisionSlider.slider("value"));gi.$twitterBird.fadeIn(gi.basicFadeDur)}else{if(gi.$service.val()==gi.serviceKeyTweets){gi.getLocNames(gi.cLatLng)}}};gi.prepareNewContent=function(){gi.ajaxRequest.abort();window.clearInterval(gi.tweetInterval);gi.$content.empty();gi.$content.html('<div id="loader"></div>');gi.$content.find("div#loader").stop().animate({width:"100%"},{duration:gi.loaderDuration});gi.minimizeMap()};gi.centerLocation=function(){google.maps.event.trigger(gi.map,"resize");gi.map.setCenter(gi.cLatLng)};gi.getContentHeight=function(){if(window.innerHeight){return window.innerHeight}else{if(window.document.documentElement&&window.document.documentElement.clientHeight){return window.document.documentElement.clientHeight}else{return window.document.body.offsetHeight}}};gi.closePanels=function(){gi.$extras.slideUp(gi.basicFadeDur);gi.$extrasOpen.fadeIn(gi.basicFadeDur);gi.$homeLocation.fadeOut(gi.basicFadeDur)};gi.minimizeMap=function(){gi.animateMap(gi.mapSmallPercent)};gi.maximizeMap=function(){gi.animateMap(100)};gi.animateMap=function(a){if(a==100){gi.$mapClose.fadeIn(gi.basicFadeDur)}else{gi.$mapClose.fadeOut(gi.basicFadeDur);google.maps.event.trigger(gi.map,"resize")}newHeight=String(Math.floor(gi.mapTotalHeight*a/100))+"px";gi.$map.stop().animate({height:newHeight},{duration:200});window.setTimeout(function(){google.maps.event.trigger(gi.map,"resize")},400)};gi.$twitterBird.find("a").click(function(a){if(!gi.cLatLng||gi.$service.val()!=gi.serviceKeyPics){a.preventDefault()}});$('a[href^="#?p"]').click(function(a){gi.prepareNewContent();requestpage=a.target.href.substring(a.target.href.indexOf("=")+1);gi.ajaxRequest=$.ajax({url:"getpage.php",type:"POST",data:"page="+requestpage,dataType:"json",error:function(d,c,b){gi.printError("load")},success:function(b){if(requestpage!=b.html){gi.$content.html('<div id="text">'+b.html+"</div>");$.getScript("http://www.geoimpress.com/_test/js/page/"+requestpage+".js")}else{gi.printError("load")}}});a.preventDefault()});$("div#refresh a").click(function(a){gi.startService();a.preventDefault()});gi.$service.change(function(a){if(gi.$service.val()==gi.serviceKeyPics){gi.$precision.fadeIn(gi.basicFadeDur);if(gi.cLatLng){gi.$twitterBird.fadeIn(gi.basicFadeDur)}}else{gi.$precision.fadeOut(gi.basicFadeDur);gi.$twitterBird.fadeOut(gi.basicFadeDur)}if(gi.cLatLng!=null){gi.startService()}}).change();gi.getPrecision=function(){return parseFloat(gi.$precisionSlider.slider("value"))/100};gi.getPictures=function(g,b){gi.$precisionRefresh.fadeOut(gi.basicFadeDur);var c=Math.floor(parseInt(gi.$content.css("width"))/106),f=Math.floor((parseInt(gi.getContentHeight())-(gi.mapTotalHeight*gi.mapSmallPercent/100)-parseInt($("div#header").css("height"))-60)/81),a=(gi.homeLatLng!=null&&g.lat()==gi.homeLatLng.lat()&&g.lng()==gi.homeLatLng.lng()?"&hl=1":""),d="getpics.php",e="lat="+g.lat()+"&lon="+g.lng()+"&z="+b+"&ppr="+c+"&rws="+f+a;gi.ajaxRequest=$.ajax({url:d,type:"POST",data:e,dataType:"json",error:function(j,i,h){gi.printError("load")},success:function(h){if(h.error=="0"){gi.$content.html(h.html);$(function(i){i('a[rel^="lightbox"]').slimbox({overlayOpacity:0.8,easing:"easeOutElastic"},null,function(j){return(this==j)||((this.rel.length>8)&&(this.rel==j.rel))})})}else{gi.printError("load")}}})};gi.$precisionSlider.slider({animate:true,range:"min",min:0,max:100,step:0.5,value:(gi.useStartLocation?sPrecision:50),start:function(f,d){if(gi.cLatLng!=null){var c=gi.map.getProjection().fromLatLngToPoint(gi.cLatLng),b=gi.map.getProjection().fromLatLngToPoint(gi.map.getBounds().getNorthEast()),a=gi.map.getProjection().fromLatLngToPoint(gi.map.getBounds().getSouthWest()),g=Math.pow(2,gi.map.getZoom());gi.cPoint=new google.maps.Point((c.x-a.x)*g,(c.y-b.y)*g)}else{gi.cPoint=new google.maps.Point($(gi.map.getDiv()).width()/2,$(gi.map.getDiv()).height()/2)}if(gi.enhancedAgent){gi.$precisionLayer.fadeIn(gi.basicFadeDur/2)}else{gi.$precisionLayer.show()}gi.refreshCircle()},stop:function(b,a){if(gi.enhancedAgent){gi.$precisionLayer.fadeOut(gi.basicFadeDur)}else{gi.$precisionLayer.hide()}},slide:function(b,a){gi.refreshCircle()},change:function(b,a){gi.$precisionRefresh.show()}});gi.getCircleRadiusPx=function(){kmHeight=gi.map.getBounds().toSpan().lat()*111.32;pxPerLat=$(gi.map.getDiv()).height()/gi.map.getBounds().toSpan().lat();pxPerKm=$(gi.map.getDiv()).height()/kmHeight;return Math.max(100-parseFloat(gi.$precisionSlider.slider("value")),1/32*100)/100*32*pxPerKm};gi.refreshCircle=function(){cCircleRadius=gi.getCircleRadiusPx();gi.$precisionCircleImg.css("width",cCircleRadius*2);gi.$precisionCircleImg.css("height",cCircleRadius*2);gi.$precisionCircle.css("left",gi.cPoint.x);gi.$precisionCircle.css("top",gi.cPoint.y);gi.$precisionCircle.css("margin-left",-cCircleRadius);gi.$precisionCircle.css("margin-top",-cCircleRadius)};$("div#morethoughts a").live("click",function(a){$(this).fadeOut(gi.basicFadeDur);gi.moreTweets()});gi.getLocNames=function(a){gi.geoCoder.geocode({location:gi.cLatLng},function(d,c){if(c!=google.maps.GeocoderStatus.OK){gi.printError("nolocation");switch(c){case google.maps.GeocoderStatus.ZERO_RESULTS:gi.printError("nolocation");break;case google.maps.GeocoderStatus.OVER_QUERY_LIMIT:gi.printError("gmqueryoverload");break;default:gi.printError("load");break}}else{gi.currentPlace=new Array();var b=d.shift().address_components;for(key in b){for(typeKey in b[key].types){var e=b[key].types[typeKey];if(e=="country"||e=="locality"||e=="sublocality"){gi.currentPlace.push(b[key].long_name)}}}gi.currentPlace=gi.currentPlace.join("/");gi.refreshTweets("")}})};gi.refreshTweets=function(d){var a="http://search.twitter.com/search.json",c='callback=gi.addTweets&q="'+gi.currentPlace.replace(/\//g,'"+OR+"')+'"+-filter%3Alinks&lang=all&rpp='+(gi.tweetsPerPage*gi.tweetPages)+"&since="+d,b=document.createElement("script");gi.tweetsQuerySplit=gi.currentPlace.split("/");b.setAttribute("type","text/javascript");b.setAttribute("src",a+"?"+c);gi.$head.appendChild(b)};gi.addTweets=function(a){gi.$content.empty();gi.$content.prepend('<div id="morethoughts"><a href="#" style="display:none;">more Thoughts?</a></div>');gi.tweetsAdded=gi.tweetsOnDisplay=0;gi.tweetsSince=a.max_id;gi.tweetsStack=a.results;gi.lastTweetAdded=a.results.length-1;window.clearInterval(gi.tweetInterval);gi.tweetInterval=window.setInterval(gi.addTweet,gi.tweetTimeout)};gi.moreTweets=function(){gi.minimizeMap();gi.tweetsAdded=0;window.clearInterval(gi.tweetInterval);gi.tweetInterval=window.setInterval(gi.addTweet,gi.tweetTimeout)};gi.addTweet=function(){if(--gi.lastTweetAdded>=0&&gi.tweetsAdded<gi.tweetsPerPage){var h=gi.tweetsStack[gi.lastTweetAdded].text,e,k,c,l,f,g,j,m,a;e=h.toLowerCase();for(var b=0;b<gi.tweetsQuerySplit.length;b++){var d=gi.tweetsQuerySplit[b];k=d.toLowerCase();c=e.indexOf(k);while(c>-1){h=h.substring(0,c)+'<span class="keyword">'+d+"</span>"+h.substring(c+d.length);e=h.toLowerCase();c=e.indexOf(k,e.indexOf("</span>",c))}}if(gi.tweetsOnDisplay>=gi.tweetsPerPage){gi.$content.find("p.tweet:last").remove();gi.tweetsOnDisplay--}gi.tweetsStack[gi.lastTweetAdded].text=h;gi.$content.prepend('<p class="tweet" style="display:none;">'+gi.tweetsStack[gi.lastTweetAdded].text+"</p>");gi.$content.find("p.tweet:hidden").stop().slideDown(800);gi.tweetsAdded++;gi.tweetsOnDisplay++}else{window.clearInterval(gi.tweetInterval);if(gi.lastTweetAdded>-1){$("div#morethoughts a").fadeIn(gi.basicFadeDur)}else{if(gi.tweetsStack.length>0){gi.$content.prepend('<div id="morethoughts">These are the most recent thoughts for the target.</div>')}else{gi.printError("nothoughts")}}}};gi.printError=function(a){var b="";switch(a){case"load":b='<p class="error">Sorry, an error occurred while loading the content.<br />Please try again.</p>';break;case"gmqueryoverload":b='<p class="error">Sorry, there have been to many requests one after another.</p>';break;case"nolocation":b='<p class="error">Sorry, could not find the specified location.<br />Please try again somewhere else.</p>';break;case"noaddress":b='<p class="error">Please fill the search field with an address<br /> if you want to use the address search.</p>';break;case"nothoughts":b='<p class="error">Sorry, there are no thoughts for this area.</p>';break;default:break}gi.$content.html(b)};google.load("maps","3.x",{callback:gi.initialize,other_params:"libraries=geometry&sensor=false"})});function hashDump(a){var b="";for(var c in a){b+=c+": "+a[c]+"\n"}alert(b)};
