/* CONFIG/ GLOBALS */function debug(e){DEBUG&&DEBUG===1&&console.log(e)}function trimStartingZero(e){e+="";e.substring(0,1)==="0"&&(e=e.substring(1,e.length));return parseInt(e,10)}function parseDT(e){if(e.length===0){debug("dt elem does not exist:"+e);return}var t,n,r;t=e.attr("datetime");t||(t=e.attr("title"));if(!t){debug("could not find time in datetime or title.");debug("dt class:"+e.attr("class"));return}dtSplit=t.split("T");n=dtSplit[0].split("-");if(n===null){debug("didn't recognize DT in: "+t);return}return[n,r]}function findHCalendarEvents(){if(!document.getElementById||!document.createElement){debug("No DOM!");return}if($(".hcal_tables")===null){debug("calendar data not found!");return}$(".vevent").each(function(){var e,t,n={summary:$(this).find(".summary").html(),description:$(this).find(".description").html(),time:$(this).find(".time:first").text(),location:$(this).find(".location:first").text()};e=parseDT($(this).find(".dtstart:first"))[0];t=$(this).find(".dtend:first");t.length>0?t=parseDT(t)[0]:t=e;var r=e[2],i=t[2];if(n.summary)if(e[0]<t[0]||e[1]<t[1]||t[1]>e[1]){i=getMonthLength(e[0],e[1]);addEventHashToGlobalDateHash(n,e,r,i);r=1;i=parseInt(t[2],10);addEventHashToGlobalDateHash(n,t,r,i)}else addEventHashToGlobalDateHash(n,e,r,i)});for(var e in globalDateHash)for(var t in globalDateHash[e])$(".hcal_tables").append(makeMonthTable(globalDateHash[e][t],e,t))}function addEventHashToGlobalDateHash(e,t,n,r){for(var i=trimStartingZero(n);i<=trimStartingZero(r);i++){globalDateHash[t[0]]||(globalDateHash[t[0]]={});globalDateHash[t[0]][t[1]]||(globalDateHash[t[0]][t[1]]={});globalDateHash[t[0]][t[1]][i]||(globalDateHash[t[0]][t[1]][i]=[[]]);globalDateHash[t[0]][t[1]][i].push(e)}}function makeMonthTable(e,t,n){var r=getMonthLength(t,n),i=getMonthLength(t,n-1),s=new Date,o=s.getFullYear(),u=s.getMonth()+1,a=s.getDate(),f=new Array(r+1),l=document.createElement("table");$(l).append("<caption>"+monthNames[trimStartingZero(n)-1]+" "+t+"</caption>");var c='<tr class="longDays">';for(var h=0;h<dayNames.length;h++)c+='<th scope="col" >'+dayNames[h]+"</th>";c+='</tr><tr class="abbrDays">';for(h=0;h<dayAbbrevs.length;h++)c+='<th scope="col" ><abbr title="'+dayNames[h]+'">'+dayAbbrevs[h]+"</abbr></th>";$(l).append("<thead>"+c+"</tr></thead>");var p=document.createElement("tbody");$(l).append(p);for(h=1;h<=r;h++){f[h]=document.createElement("td");o==t&&u==n&&a==h&&(f[h].className+=" calDayToday");$(f[h]).append('<a href="/happenings/'+n+"/"+h+"/"+t+'/" class="calDayLabel">'+h+"</a>")}for(var d in e){var v='<div class="events">';for(h=0;h<e[d].length;h++){dayTD=f[d-0];if(e[d][h].summary){$(dayTD).addClass("has_events");v+='<div class="event"><h3>'+e[d][h].summary+"</h3> ";var m='<div class="eventDetails"><p>'+$.trim(e[d][h].time)+" "+$.trim(e[d][h].location)+"</p>";e[d][h].description&&(m+='<p class="calEventDesc">'+e[d][h].description+"</p>");m+="</div>";v+=m+"</div>"}}$(dayTD).hasClass("has_events")&&$(dayTD).append(v+"</div>")}var g=new Date;g.setYear(t);g.setDate(1);g.setMonth(n-1);var y=g.getDay(),b=p.appendChild(document.createElement("tr"));for(h=0;h<y;h++){var w=i-(y-h-1);isNaN(w)&&(w="");$(b).append('<td class="outOfRange"><div class="calDayLabel"> '+w+"</div></td>")}for(h=1;h<=r;h++){b.childNodes.length===7&&(b=p.appendChild(document.createElement("tr")));(b.childNodes.length===0||b.childNodes.length===6)&&$(f[h]).addClass("weekend");b.appendChild(f[h])}var E=1;while(b.childNodes.length<7){$(b).append('<td class="outOfRange"><div class="calDayLabel">'+E+"</div></td>");E++}return l}var DEBUG=0,dayNames=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"),dayAbbrevs=new Array("S","M","T","W","T","F","S"),monthNames=new Array("January","February","March","April","May","June","July","August","September","October","November","December"),monthLength=new Array(31,28,31,30,31,30,31,31,30,31,30,31),firstDayOfWeek=0,globalDateHash={},month_tables="";getMonthLength=function(e,t){return monthLength[t-1]};$(document).ready(findHCalendarEvents);