google.load("jquery","1.4");google.load("gdata","2");google.load("search","1");if(!Array.prototype.forEach)Array.prototype.forEach=function(b,g){var f=this.length>>>0;if(typeof b!="function")throw new TypeError;for(var a=0;a<f;a++)a in this&&b.call(g,this[a],a,this)};if(!Array.prototype.map)Array.prototype.map=function(b,g){var f=this.length>>>0;if(typeof b!="function")throw new TypeError;for(var a=new Array(f),j=0;j<f;j++)if(j in this)a[j]=b.call(g,this[j],j,this);return a};
if(!Array.prototype.filter)Array.prototype.filter=function(b,g){var f=this.length>>>0;if(typeof b!="function")throw new TypeError;for(var a=[],j=0;j<f;j++)if(j in this){var c=this[j];b.call(g,c,j,this)&&a.push(c)}return a};
if(!Array.prototype.reduce)Array.prototype.reduce=function(b){var g=this.length>>>0;if(typeof b!="function")throw new TypeError;if(g==0&&arguments.length==1)throw new TypeError;var f=0;if(arguments.length>=2)var a=arguments[1];else{do{if(f in this){a=this[f++];break}if(++f>=g)throw new TypeError;}while(1)}for(;f<g;f++)if(f in this)a=b.call(null,a,this[f],f,this);return a};
if(!Array.prototype.indexOf)Array.prototype.indexOf=function(b,g){var f=this.length>>>0,a=Number(g)||0;a=a<0?Math.ceil(a):Math.floor(a);if(a<0)a+=f;for(;a<f;a++)if(a in this&&this[a]===b)return a;return-1};
metrolicious=function(){function b(p,r){function I(y){z=y.feed.entry?y.feed.entry.map(function(A){return new metrolicious.gcal.Entry(A)}).sort(function(A,D){var E=A.startTime.getTime()-D.startTime.getTime();if(E==0)E=A.endTime.getTime()-D.endTime.getTime();return E}):[];F.entriesLoaded()}var P=[],z,Q=metrolicious.gcal.createQueryUrl(p,(new metrolicious.net.URL(window.location.href)).queryParameters,r,metrolicious.util.adjustDate(r,1)),F;return{getEntries:function(){if(z)return z;else{z=P;selectedEntry=
null;pins={};jQuery.getJSON(Q.toString(),I)}},setObserver:function(y){F=y}}}function g(p,r){function I(){J=null;if(p.getEntries()){P();z();y()}}function P(){w={};var d=r.themeUrl+"normal-pins.png",i=r.themeUrl+"selected-pins.png";p.getEntries().forEach(function(t,G){var u={x:10,y:10+(G+1)*54,width:21,height:34},R=new google.maps.Point(u.x,u.y),S=new google.maps.Size(u.width,u.height);w[t.hexuid]={tileBounds:u,normal:new google.maps.MarkerImage(d,S,R),selected:new google.maps.MarkerImage(i,S,R)}})}
function z(){if(l.scrollView){B=jQuery("<table>");K={};s=null;p.getEntries().forEach(function(d,i){var t=Q(d,i);K[d.hexuid]=t;B.append(t)});l.scrollView.empty();l.scrollView.append(B)}}function Q(d){var i=jQuery(U);i.attr("id",d.hexuid);i.pins=w[d.hexuid];jQuery("img",i).css("background-position",-i.pins.tileBounds.x+"px "+-i.pins.tileBounds.y+"px");jQuery(".time",i).text(metrolicious.util.formatTime(d.startTime)+" - "+metrolicious.util.formatTime(d.endTime));jQuery(".what",i).text(d.title);jQuery(".where",
i).text(d.location);d.content?jQuery(".content",i).text(d.content):jQuery(".content",i).remove();i.click(function(){x=new Date;F(d);J=d;T(d)});return i}function F(d){s&&s.removeClass("selected");s=K[d.hexuid];s.addClass("selected");if(s[0].offsetTop<n.scrollTop())n.scrollTop(s[0].offsetTop);else s[0].offsetTop+s[0].offsetHeight>n.scrollTop()+n[0].offsetHeight&&n.scrollTop(s[0].offsetTop-n[0].offsetHeight+s[0].offsetHeight)}function y(){if(l.map){L={};v=[];o=null;var d=p.getEntries();d.filter(function(i){return i.coordinates}).forEach(D);
d=d.filter(function(i){return!i.coordinates});d.forEach(E);M.push(window.setTimeout(V,d.length==0?0:2E3))}}function A(){o=null;if(v){v.forEach(function(d){d.infoWindow.hide();d.infoWindow.unload();d.setMap(null)});v=null}L=null}function D(d){if(l.map){var i=new google.maps.LatLng(d.coordinates.lat,d.coordinates.lng),t=new google.maps.Marker({position:i,map:l.map,icon:w[d.hexuid].normal});t.pins=w[d.hexuid];google.maps.event.addListener(t,"click",function(){x=new Date;T(d);J=d;F(d)});L[d.hexuid]=t;
v.push(t);v.sort(function(G,u){return G.getPosition().lat()-u.getPosition().lat()}).forEach(function(G,u){G.setZIndex(-u)});t.infoWindow=new metrolicious.gmaps.InfoWindow(l.map,i,w[d.hexuid].tileBounds);t.infoWindow.load()}}function E(d){metrolicious.gmaps.geocode(d.location,function(i){if(i){d.coordinates={lat:i.lat(),lng:i.lng()};D(d)}})}function V(){if(!(!l.map||x)){var d=metrolicious.gmaps.findBounds(v.map(function(i){return i.getPosition()}),c);l.map.fitBounds(c.contains(d.getSouthWest())&&c.contains(d.getNorthEast())?
d:c)}}function T(d){if(o){o.infoWindow.hide();o.setZIndex(-v.indexOf(o));o.setIcon(o.pins.normal)}o=L[d.hexuid];l.map.panTo(o.getPosition());o.setIcon(o.pins.selected);o.setZIndex(1);o.infoWindow.show()}function W(){x=new Date;o&&o.infoWindow.hide()}function X(){o&&o.infoWindow.onIdle()}function Y(){x=new Date;if(l.map){var d=N;N=l.map.getZoom();o&&metrolicious.gmaps.zoomMapFixedAtPosition(l.map,o.getPosition(),d,N)}}var l=this,M,x,J,B,K,s,L,o,v,w,N,C,U='<tr class="cell"><td><img class="pin" src="'+
r.themeUrl+'transparent.png"></td><td><div class="time"></div><div class="what"></div><div class="where"></div><div class="content"></div></td></tr>';l.show=function(d,i){l.map=d;l.scrollView=i;N=d.getZoom();C=[];C.push(google.maps.event.addListener(d,"click",W));C.push(google.maps.event.addListener(d,"idle",X));C.push(google.maps.event.addListener(d,"zoom_changed",Y));x=null;M=[];I()};l.hide=function(){A();K=s=null;if(B){B.remove();B=null}J=w=null;M.forEach(function(d){window.clearTimeout(d)});x=
M=null;C.forEach(google.maps.event.removeListener);C=null;l.scrollView=null;l.map=null};l.entriesLoaded=function(){I()};p.setObserver(l)}function f(){jQuery("#day-label").text(h.toLocaleDateString());jQuery("#today-button").click(function(){a(e)});jQuery("#next-day-button").click(function(){a(metrolicious.util.adjustDate(h,1))});jQuery("#previous-day-button").click(function(){a(metrolicious.util.adjustDate(h,-1))})}function a(p){k.hide();h=p;jQuery("#day-label").text(h.toLocaleDateString());p=h;var r=
m[google.gdata.DateTime.toIso8601(p)];if(!r){r=new g(new b(basicUrl,p),options);m[google.gdata.DateTime.toIso8601(p)]=r}k=r;k.show(q,n)}function j(p){p=new google.maps.StyledMapType(p,{map:q,name:"mmm"});q.mapTypes.set("mmm",p);q.setMapTypeId("mmm")}var c=new google.maps.LatLngBounds(new google.maps.LatLng(36.992485,-123.000366),new google.maps.LatLng(38.492485,-121.500366)),e,h,k,m={},n,q,O,H;return{init:function(p,r){(new metrolicious.net.URL("http://metrolicious.com")).queryParameters={copyright:"Copyright 2010 Ray Ortigas. All rights reserved. <ray.ortigas@gmail.com> <rayo@metrolicious.com>"};
basicUrl=p;options=r;h=e=metrolicious.util.trimToDate(options&&options.now||new Date);k=new g(new b(basicUrl,h),options);f();n=jQuery("#events_container");O=options&&options.center||new google.maps.LatLng(37.775718,-122.41941);H=options&&options.zoom||11;q=new google.maps.Map(document.getElementById("map_canvas"),{center:O,zoom:H,mapTypeId:google.maps.MapTypeId.ROADMAP,mapTypeControl:false,navigationControlOptions:{style:google.maps.NavigationControlStyle.SMALL}});options&&options.mapStylesUrl&&jQuery.getJSON(options.mapStylesUrl,
j);k.show(q,n)}}}();metrolicious.util={hexEncode:function(b){for(var g=[],f=0;f!=b.length;f++){var a=b.charCodeAt(f).toString(16);g.push(a.length%2==0?a:"0"+a)}return g.join("")},formatTime:function(b){var g=b.getHours();b=b.getMinutes();var f="";f+=g==0?12:g>12?g-12:g;if(b>0){f+=":";f+=b<=10?"0"+b:b}f+=g<12?"am":"pm";return f},trimToDate:function(b){return new Date(b.getFullYear(),b.getMonth(),b.getDate())},adjustDate:function(b,g){return new Date(b.getTime()+g*864E5)}};
metrolicious.net=function(){function b(a){a=g.exec(a);this.scheme=a[2]?decodeURIComponent(a[2]):null;this.authority=a[4]?decodeURIComponent(a[4]):null;this.path=a[5]?decodeURIComponent(a[5]):null;this.queryParameters=a[7]?a[7].split("&").reduce(function(j,c){var e=f.exec(c),h=decodeURIComponent(e[1]);e=decodeURIComponent(e[2]);j[h]=e;return j},{}):null;this.fragment=a[9]?decodeURIComponent(a[9]):null}var g=/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/,f=/(.*)=(.*)/;b.prototype.toString=
function(){var a=[];if(this.scheme){a.push(this.scheme);a.push(":")}if(this.authority){a.push("//");a.push(this.authority)}a.push(this.path);if(this.queryParameters){a.push("?");var j=[];for(var c in this.queryParameters){var e=this.queryParameters[c];j.push(c+"="+(e?e:""))}a.push(j.sort().join("&"))}if(this.fragment){a.push("#");a.push(this.fragment)}return encodeURI(a.join(""))};return{URL:b}}();
metrolicious.gcal=function(){return{createQueryUrl:function(b,g,f,a){b=b.replace(/(.*)\/basic$/,"$1/full");b=new metrolicious.net.URL(b);f={v:"2.3",alt:"json","start-min":google.gdata.DateTime.toIso8601(f),"start-max":google.gdata.DateTime.toIso8601(a),fields:"entry(@gd:*,title,content,gd:when,gd:where,gCal:uid,georss:where,gd:extendedProperty)",singleevents:"true",orderby:"starttime",sortorder:"a",callback:"?"};for(var j in g)if(g.hasOwnProperty(j))f[j]=g[j];b.queryParameters=f;return b},Entry:function(b){this.hexuid=
metrolicious.util.hexEncode(b.gCal$uid.value);this.title=b.title?b.title.$t:null;this.content=b.content?b.content.$t:null;this.location=b.gd$where?b.gd$where[0].valueString:null;extended_properties={};b.gd$extendedProperty&&b.gd$extendedProperty.forEach(function(f){extended_properties[f.name]=f.value});this.extended_properties=extended_properties;var g=b.gd$when;this.startTime=g?google.gdata.DateTime.fromIso8601(g[0].startTime).getDate():new Date;this.endTime=g?google.gdata.DateTime.fromIso8601(g[0].endTime).getDate():
new Date;this.coordinates=(b=extended_properties.twitter_coordinates?jQuery.trim(extended_properties.twitter_coordinates).split(/\s+/):b.georss$where?jQuery.trim(b.georss$where.gml$Point.gml$pos.$t).split(/\s+/):null)?{lat:b[0],lng:b[1]}:null}}}();
metrolicious.gmaps=function(){function b(c,e){var h=new google.search.LocalSearch;h.setResultSetSize(google.search.Search.SMALL_RESULTSET);h.setSearchCompleteCallback(null,function(){e(h.results.length>0?new google.maps.LatLng(parseFloat(h.results[0].lat),parseFloat(h.results[0].lng)):null)});h.execute(c)}function g(c,e){function h(){m&&n&&e(new google.maps.LatLng((m.lat()+n.lat())/2,(m.lng()+n.lng())/2))}function k(q,O,H){q=q+" and "+O;if(H)q+=", "+H;return q}var m,n;b(k(c.main,c.first,c.area),function(q){m=
q;h()});b(k(c.main,c.second,c.area),function(q){n=q;h()})}function f(c){var e=c.getSouthWest();c=c.getNorthEast();var h=c.lng()-e.lng(),k=c.lat()-e.lat();e=new google.maps.LatLng(e.lat()-k,e.lng()-h);c=new google.maps.LatLng(c.lat()+k,c.lng()+h);return new google.maps.LatLngBounds(e,c)}function a(c,e,h){this.map=c;this.point=e;this.pinTileBounds=h;c=new metrolicious.net.URL("http://maps.google.com/maps/api/staticmap");c.queryParameters={sensor:"false",size:"150x150",zoom:"15",center:e.lat()+","+e.lng()};
this.mapImage=c}var j=new google.maps.Geocoder;a.prototype=new google.maps.OverlayView;a.prototype.onAdd=function(){var c=document.createElement("img");c.src=this.mapImage;c.style.width="100%";c.style.height="100%";this.img=c;this.pinIcon=jQuery("<img>");this.pinIcon.attr("src",options.themeUrl+"transparent.png");this.pinIcon.attr("width",this.pinTileBounds.width);this.pinIcon.attr("height",this.pinTileBounds.height);this.pinIcon.css("background-image","url('"+options.themeUrl+"selected-pins.png')");
this.pinIcon.css("background-position",-this.pinTileBounds.x+"px "+-this.pinTileBounds.y+"px");var e=document.createElement("div");e.style.display="none";e.style.backgroundColor="#333333";e.appendChild(c);e.appendChild(this.pinIcon[0]);this.div=e;this.getPanes().floatPane.appendChild(e)};a.prototype.draw=function(){var c=this.getProjection().fromLatLngToDivPixel(this.point),e=this.div;e.style.position="relative";e.style.left=c.x-80+"px";e.style.top=c.y-80+"px";e.style.width="160px";e.style.height=
"160px";c=this.img;c.style.position="absolute";c.style.left="5px";c.style.top="5px";c.style.width="150px";c.style.height="150px";this.pinIcon.css("position","absolute");this.pinIcon.css("left","69.5px");this.pinIcon.css("top","46px")};a.prototype.onRemove=function(){this.div.parentNode.removeChild(this.div);this.div=null};a.prototype.background=new google.maps.Rectangle;a.prototype.load=function(){this.setMap(this.map)};a.prototype.show=function(){this.background.setMap(this.map);if(this.div)this.div.style.display=
"block"};a.prototype.hide=function(){if(this.div)this.div.style.display="none";this.background.setMap(null)};a.prototype.unload=function(){this.setMap(null)};a.prototype.onIdle=function(){this.background.setBounds(f(this.map.getBounds()))};return{geocode:function(c,e){j.geocode({address:c},function(h,k){if(k==google.maps.GeocoderStatus.OK&&h.length>0&&!h[0].partial_match)e(h[0].geometry.location);else{var m;m=(m=/(.*)\s+(between|btw|b\/w)\s+(.*)\s+and\s+(.*)(,\s*(.*))?/.exec(c))?{main:m[1],first:m[3],
second:m[4],area:m[6]}:null;m?g(m,e):b(c,e)}})},zoomMapFixedAtPosition:function(c,e,h,k){k=Math.pow(2,k-h);var m=c.getCenter();h=(m.lat()-e.lat())/k;k=(m.lng()-e.lng())/k;e=new google.maps.LatLng(e.lat()+h,e.lng()+k);c.setCenter(e)},findBounds:function(c,e){if(e)c=c.filter(function(n){return e.contains(n)});var h=c.map(function(n){return n.lat()}),k=c.map(function(n){return n.lng()}),m=new google.maps.LatLng(Math.min.apply(Math,h),Math.min.apply(Math,k));h=new google.maps.LatLng(Math.max.apply(Math,
h),Math.max.apply(Math,k));return new google.maps.LatLngBounds(m,h)},InfoWindow:a}}();

