var g_metros=null
var g_map=null;var g_map_info=null;var g_overview_map;var g_spanish_countries={"AD":true,"ES":true,"MX":true,"PR":true,"CR":true,"PA":true,"SV":true,"CU":true,"DO":true,"GT":true,"HN":true,"CO":true,"NI":true,"BZ":true,"VE":true,"EC":true,"PE":true,"CL":true,"AR":true,"PY":true,"UY":true}
$().ready(function(){setActiveTab("home");$.getJSON(url="/WAS/country_list",data={},function(json){for(var i in json){var next=json[i];$(".countries").append("<option value='"+next.abbr+"'>"+next.name+"</option>")}
initHomepage();});});var initHomepage=function(){var countryAbbr=extractParam("country");if(countryAbbr.length!=0){writeCountryCookie(countryAbbr);if(!g_spanish_countries[countryAbbr])
document.location.href="http://world.waze.com/";else
document.location.href="http://es.waze.com/";return;}
if(hasCountryCookie()){$('.countries').val(readCountryCookie());changeCountry();}
$('.countries').change(changeCountry);$(".int_body").show();$.getJSON(url="/WAS/top_ranked",data={count:5},function(json){for(var i in json){var next=json[i];var wazer=$("<div class='wazer' style='display:none;'></div>");$(".top_wazers").append(wazer);$(wazer).html($("#wazer_mold").html());var serial=parseInt(i)+1;if(next.name.indexOf("anon_")==0)
$("strong",wazer).prepend(serial+". ");else
$("strong",wazer).text(serial+". "+next.name);$(".joined .time",wazer).text(getTimeAgo(next.joinDateMillisecs));$(".stars",wazer).attr("src","/homepage/images/star_"+next.starCount+".gif");$(".points .number",wazer).text(next.points);}
$(".wazer").fadeIn("slow");});$.getJSON(url="/WAS/general_stats",callback=function(json){for(var i in json){$("#"+i+" .value").text(json[i]);}});$.getJSON(url="/WAS/blog_feed",data={count:5},callback=function(json){if(!json.successful)
return;for(var i in json.result){var next=json.result[i];var blog_link=$("<a class='blog_post_link' style='display:none;'></a>");$(".blog").append(blog_link);$(blog_link).attr("href",next.link);var d=new Date(next.date);var date_str=(d.getMonth()+1)+"."+d.getDate()+"."+d.getFullYear();$(blog_link).text(date_str+" - \""+next.title+"\"");}
$(".blog_post_link:eq(0)").fadeIn("slow");window.setInterval(function(){var count=$(".blog_post_link").length;var index=$(".blog_post_link").index($(".blog_post_link:visible"));var old_index=index;index++;var index=index%count;$(".blog_post_link:eq("+old_index+")").fadeOut("slow",function(){$(".blog_post_link:eq("+index+")").fadeIn("slow");});},7000);});$.getJSON(url="/WAS/map_info",callback=function(map_info){g_map_info=map_info;var center=null;if(map_info.base_layer_type=="OSM")
center=OpenLayers.Layer.SphericalMercator.forwardMercator(map_info.default_center.lon,map_info.default_center.lat);else
center=new OpenLayers.LonLat(map_info.default_center.lon,map_info.default_center.lat);if(typeof(OverviewMap)=="function"&&typeof(OverviewMap.prototype)=="object")
g_overview_map=new OverviewMap(map_info,'map',center);changeCountry();$.getJSON(url="/rss/metros.json",callback=function(json){g_metros=json;for(var i in g_metros){var metro=g_metros[i];var next_opt=$("<option></option>");$("select[name=metro_list]").append(next_opt);$(next_opt).val(i).text(metro.fullname);}
updateMetroStatus();$(".standard_form").slideDown("slow");});});updateRecentReports();$("select").change(function(){updateMetroStatus();});}
var updateRecentReports=function(){var max_events=4;var params={"format":"JSON","types":"alerts",ma:max_events,as:"update"};$(".recent_report").fadeOut("slow");$.getJSON(url="/rtserver/web/GeoRSS",data=params,callback=function(json){$(".recent_report").remove();var alerts=json.alerts;if(!alerts)
alerts=[];if(alerts.constructor.toString().indexOf("Array")==-1)
alerts=[alerts];if(alerts.length<max_events){var params={type:"update_requests",format:"json",count:(max_events-alerts.length)}
$.getJSON(url="/feed",data=params,callback=function(json){for(var i in json){var next=json[i];next.reportBy=next.user_name
next.reportDescription=next.description;next.pubMillis=next.millisec;alerts.push(next);}
if(alerts){alerts.sort(function(a,b){return b.pubMillis-a.pubMillis;});}
addEvents(alerts);});return;}
addEvents(alerts);});}
var addEvents=function(alerts){for(var i in alerts){var next=alerts[i];var report=$("<div class='recent_report' style='display:none;'></div>");$(".recent_reports").append(report);$(report).html($("#recent_report_mold").html());if(next.imageId&&next.imageId.length>0){$('.graphic',report).addClass("small_thumb").append("<div class='image'></div>");$('.image ',report).css("background-image","url(http://waze.photos.s3.amazonaws.com/thumbs/thumb32_"+next.imageId+")");$('.image',report).colorbox({href:"http://waze.photos.s3.amazonaws.com/"+next.imageId,photo:true});}
else
$(".graphic",report).addClass($("#"+next.type+" .icon_class").text());if(next.reportBy)
$("a.reports_user",report).text(next.reportBy);if(next.reportDescription)
$(".report_text",report).text("\""+next.reportDescription+"\"");if(next.pubMillis)
$(".when .time",report).text(getTimeAgo(next.pubMillis));if(next.type){$(".alert_type",report).text($("#"+next.type+" .title").text());if(next.location)
$(".alert",report).attr("href","/livemap/?zoom=4&lat="+next.location.y+"&lon="+next.location.x);else
$(".alert",report).attr("href","/livemap/?zoom=4&lat="+next.y+"&lon="+next.x);}
if(next.city||next.street){if(next.street){$(".location",report).append(" "+next.street);if(next.city)
$(".location",report).append(", "+next.city);}
else if(next.city)
$(".location",report).append(next.city);$(".location",report).show();}}
$(".recent_report").fadeIn("slow");window.setTimeout(updateRecentReports,60000);}
var updateMetroStatus=function(){var metro=g_metros[$("select[name=metro_list]").val()];if(!metro)return;$(".metro_name").text(metro.fullname);$(".metro_name").show();$(".status_graph_fill").css("width",metro.overall_score+"%");var car_pos=Math.round((metro.overall_score/100)*$(".status_graph").width()-$(".status_graph_car").width()/2);$(".status_graph_car").css("left",car_pos+"px");$(".status").text(metro.state);$(".quality").text(metro.quality_score_st);$(".traffic").text(metro.traffic_score_st);$(".usage").text(metro.usage_score_st);var lonlat=new OpenLayers.LonLat(metro.x,metro.y);if(typeof(OverviewMap)=="function"&&typeof(OverviewMap.prototype)=="object"){if(g_overview_map.map_info.base_layer_type=="OSM")
lonlat=OpenLayers.Layer.SphericalMercator.forwardMercator(lon=lonlat.lon,lat=lonlat.lat);g_overview_map.setMetroMarker(lonlat);}}