
$j=jQuery.noConflict();google.load("gdata","1");var firstDate=null;var lastDate=null;var geocoder=null;var entryMap=null;function init(){google.gdata.client.init(handleGDError);}
function setupCalendarService(){var calService=new google.gdata.calendar.CalendarService('wpng-calendar-plugin-1');return calService;}
function getLaterEntries(){lastDate.add(1).days();var start=lastDate.clone();var end=lastDate.clone().add(weeks).weeks();loadCalendar(start,end);}
function getOlderEntries(){firstDate.add(-1).days();var end=firstDate.clone();var start=firstDate.clone().add(-1*weeks).weeks();loadCalendar(start,end);}
function loadCalendarByWeeks(){var start=Date.today();var end=Date.today().add(weeks).weeks();loadCalendar(start,end);}
function loadCalendarEntry(entryURI){var service=setupCalendarService();service.getEventsEntry(entryURI,listEntry,handleGDError);}
function loadCalendar(start,end){var service=setupCalendarService();var query=new google.gdata.calendar.CalendarEventQuery(calendarURL);query.setOrderBy('starttime');query.setSortOrder('ascending');query.setSingleEvents(true);query.setMaxResults(pageMaxResults);var startDateTime=new google.gdata.DateTime(start);var endDateTime=new google.gdata.DateTime(end);query.setMinimumStartTime(startDateTime);query.setMaximumStartTime(endDateTime);service.getEventsFeed(query,listEvents,handleGDError);}
function loadCalendarWidget(){var service=setupCalendarService();var query=new google.gdata.calendar.CalendarEventQuery(calendarURL);query.setOrderBy('starttime');query.setSortOrder('ascending');query.setSingleEvents(true);query.setMaxResults(widgetListSize);var startDateTime=new google.gdata.DateTime(Date.today());var endDateTime=new google.gdata.DateTime(Date.today().add(6).months());query.setMinimumStartTime(startDateTime);query.setMaximumStartTime(endDateTime);service.getEventsFeed(query,listWidgetEvents,handleGDError);}
function listEvents(feedRoot){var entries=feedRoot.feed.getEntries();var eventDiv=document.getElementById('wpng-cal-events');while(eventDiv.firstChild){eventDiv.removeChild(eventDiv.firstChild);}
var prevDateString=null;var len=entries.length;var table=document.createElement('table');var tableBody=document.createElement('tbody');table.setAttribute('className','wpng-page-list-table');table.setAttribute('class','wpng-page-list-table');for(var i=0;i<len;i++){var entry=entries[i];var times=entry.getTimes();var startTime=times[0].getStartTime();var displayTime=startTime.getDate().clone();var dateString=null;if(displayTime.clearTime().equals(Date.today())){dateString='Today';}
else if(displayTime.clearTime().equals(Date.today().add(1).days())){dateString='Tomorrow';}
else{dateString=displayTime.toString('dddd, MMMM d, yyyy');}
if(dateString!=prevDateString){var trHead=document.createElement('tr');var tdHead=document.createElement('td');tdHead.setAttribute('className','wpng-page-list-head');tdHead.setAttribute('class','wpng-page-list-head');tdHead.setAttribute('colSpan','2');tdHead.setAttribute('colspan','2');tdHead.appendChild(document.createTextNode(dateString));trHead.appendChild(tdHead);tableBody.appendChild(trHead);prevDateString=dateString;}
var timeString='All Day Event';if(!startTime.isDateOnly()){timeString=startTime.getDate().toString("h:mm tt")}
var title=entry.getTitle().getText();var uri=entry.getSelfLink().getHref();var anchorTitle=document.createElement('a');anchorTitle.setAttribute('href','javascript:loadCalendarEntry("'+uri+'")');anchorTitle.appendChild(document.createTextNode(title));var locString='';var locations=entry.getLocations();var locTemp=locations[0].getValueString();if(locTemp!=null){locString=" - "+locTemp}
anchorTitle.appendChild(document.createTextNode(locString));var trEntry=document.createElement('tr');var tdEntryTime=document.createElement('td');var tdEntryTitle=document.createElement('td');tdEntryTitle.setAttribute('className','wpng-page-list-title');tdEntryTitle.setAttribute('class','wpng-page-list-title');tdEntryTime.appendChild(document.createTextNode(timeString));tdEntryTitle.appendChild(anchorTitle);trEntry.appendChild(tdEntryTitle);tableBody.appendChild(trEntry);if(i==0){firstDate=displayTime;}
else if(i==(len-1)){lastDate=displayTime;}}
table.appendChild(tableBody);if(len!=0){eventDiv.appendChild(table);}
else{eventDiv.appendChild(document.createTextNode('No events to show.'));}
if(showNav){eventDiv.appendChild(document.createElement('br'));var navTable=document.createElement('table');var navTableBody=document.createElement('tbody');navTable.setAttribute('className','wpng-page-list-table');navTable.setAttribute('class','wpng-page-list-table');var row=document.createElement('tr');var tdOlder=document.createElement('td');var anchorOlder=document.createElement('a');anchorOlder.setAttribute('href','javascript:getOlderEntries()');anchorOlder.appendChild(document.createTextNode('< Show older events'));tdOlder.appendChild(anchorOlder);row.appendChild(tdOlder);var tdLater=document.createElement('td');tdLater.setAttribute('align','right');var anchorLater=document.createElement('a');anchorLater.setAttribute('href','javascript:getLaterEntries()');anchorLater.appendChild(document.createTextNode('Show later events >'));tdLater.appendChild(anchorLater);row.appendChild(tdLater);navTableBody.appendChild(row);navTable.appendChild(navTableBody);eventDiv.appendChild(navTable);}
$j("#wpng-cal-load-page").fadeOut("fast");$j("#wpng-cal-events").slideDown("slow");}
function listEntry(retrievedEntryRoot){var entry=retrievedEntryRoot.entry;var entryDiv=document.createElement('div');entryDiv.setAttribute('id','wpng-tb');var title=document.createElement('h3');title.appendChild(document.createTextNode(entry.getTitle().getText()));entryDiv.appendChild(title);var dateString='All Day Event';var times=entry.getTimes();if(times.length){var startTime=times[0].getStartTime();var endTime=times[0].getEndTime();if(!startTime.isDateOnly()){dateString=startTime.getDate().toString("ddd, MMM d, yyyy h:mm tt");}
else{dateString=startTime.getDate().toString("ddd, MMM d, yyyy");}
dateString+='   -   ';if(!endTime.isDateOnly()){dateString+=endTime.getDate().toString("ddd, MMM d, yyyy h:mm tt")}
else{dateString+=endTime.getDate().toString("ddd, MMM d, yyyy");}}
var dateRow=document.createElement('div');dateRow.setAttribute('className','wpng-entry-label-row');dateRow.setAttribute('class','wpng-entry-label-row');dateLabel=document.createElement('div');dateLabel.appendChild(document.createTextNode('When: '));dateLabel.setAttribute('className','wpng-entry-label');dateLabel.setAttribute('class','wpng-entry-label');dateRow.appendChild(dateLabel);dateDisplay=document.createElement('div');dateDisplay.appendChild(document.createTextNode(dateString));dateDisplay.setAttribute('className','wpng-entry-label-text');dateDisplay.setAttribute('class','wpng-entry-label-text');dateRow.appendChild(dateDisplay);entryDiv.appendChild(dateRow);entryDiv.appendChild(document.createElement('br'));entryDiv.setAttribute('className','wpng-entry-break');entryDiv.setAttribute('class','wpng-entry-break');var locString='No location information';var locations=entry.getLocations();var locTemp=locations[0].getValueString();if(locTemp!=null){locString=locTemp}
var locRow=document.createElement('div');locRow.setAttribute('className','wpng-entry-label-row');locRow.setAttribute('class','wpng-entry-label-row');locLabel=document.createElement('div');locLabel.appendChild(document.createTextNode('Where: '));locLabel.setAttribute('className','wpng-entry-label');locLabel.setAttribute('class','wpng-entry-label');locRow.appendChild(locLabel);locDisplay=document.createElement('div');locDisplay.appendChild(document.createTextNode(locString));locDisplay.setAttribute('className','wpng-entry-label-text');locDisplay.setAttribute('class','wpng-entry-label-text');locRow.appendChild(locDisplay);entryDiv.appendChild(locRow);if(locTemp!=null){var isOpera=false;var isIE=false;var agt=navigator.userAgent.toLowerCase();var appVer=navigator.appVersion.toLowerCase();var iePos=appVer.indexOf('msie');if(typeof(window.opera)!='undefined'){isOpera=true;}
if(!isOpera&&iePos!=-1){isIE=true;};var locMapAnchor=document.createElement('a');locMapAnchor.setAttribute('id','wpng-map-link');locMapAnchor.setAttribute('href','http://maps.google.com/maps?hl=en&q='+locString);locMapAnchor.setAttribute('target','_blank');if(!isIE){locMapAnchor.setAttribute('style','float:right;');}else{locMapAnchor.style.setAttribute('cssText','float:right;');}
locMapAnchor.appendChild(document.createTextNode('Map'));entryDiv.appendChild(locMapAnchor);}
entryDiv.appendChild(document.createElement('br'));var descString='No description';var tempString=entry.getContent().getText();if(tempString!=null){descString=tempString;}
var descDisplay=document.createElement('div');descDisplay.setAttribute('className','wpng-entry-desc');descDisplay.setAttribute('class','wpng-entry-desc');if(parseWiki){var descHTML=Wiky.toHtml(descString);descDisplay.innerHTML=descHTML;}
else{descDisplay.appendChild(document.createTextNode(descString));}
entryDiv.appendChild(descDisplay);tb_show_inner("",entryDiv.innerHTML,"height=500&width=500");}
function listWidgetEvents(feedRoot){var entries=feedRoot.feed.getEntries();var eventDiv=document.getElementById('wpng-cal-widget-events');while(eventDiv.firstChild){eventDiv.removeChild(eventDiv.firstChild);}
var prevDateString=null;var len=entries.length;var ulist=null;for(var i=0;i<len;i++){var entry=entries[i];var times=entry.getTimes();var startTime=times[0].getStartTime();var displayTime=startTime.getDate().clone();var dateString=null;if(displayTime.clearTime().equals(Date.today())){dateString='Today';}
else if(displayTime.clearTime().equals(Date.today().add(1).days())){dateString='Tomorrow';}
else{dateString=displayTime.toString('MMM dd');}
if(dateString!=prevDateString){if(ulist!=null){eventDiv.appendChild(ulist);}
var titleDiv=document.createElement('div');titleDiv.setAttribute('className','wpng-widget-date-title');titleDiv.setAttribute('class','wpng-widget-date-title');titleDiv.appendChild(document.createTextNode(dateString));eventDiv.appendChild(titleDiv);prevDateString=dateString;ulist=document.createElement('ul');}
var title=entry.getTitle().getText();var uri=entry.getSelfLink().getHref();var anchorTitle=document.createElement('a');anchorTitle.setAttribute('className','thickbox');anchorTitle.setAttribute('class','thickbox');anchorTitle.setAttribute('href','javascript:loadCalendarEntry("'+uri+'")');anchorTitle.appendChild(document.createTextNode(title));var item=document.createElement('li');item.appendChild(anchorTitle);ulist.appendChild(item);}
if(ulist!=null){eventDiv.appendChild(ulist);}
if(len==0){eventDiv.appendChild(document.createTextNode('No events to show.'));}
$j("#wpng-cal-load-widget").fadeOut("fast");$j("#wpng-cal-widget-events").slideDown("slow");}
function handleGDError(e){document.getElementById('jsSourceFinal').setAttribute('style','display:none');if(e instanceof Error){alert('Error at line '+e.lineNumber+' in '+e.fileName+'\n'+'Message: '+e.message);if(e.cause){var status=e.cause.status;var statusText=e.cause.statusText;alert('Root cause: HTTP error '+status+' with status text of: '+
statusText);}}else{alert(e.toString());}}
google.setOnLoadCallback(init);