var Calendar=new Class({aMonths:new Array("januari","februari","maart","april","mei","juni","juli","augustus","september","oktober","november","december"),aWeekDays:new Array("zo","ma","di","wo","do","vr","za"),iDaysInThePast:3,iMonthsInCalendar:5,resultsInitialised:false,initialize:function(sCalendarName){this.calendarHolder=$(sCalendarName);this._drawCalendar();},_drawCalendar:function(){var oDate=new Date();var iCurrentDay=oDate.getDate();var iCurrentMonth=oDate.getMonth();var iCurrentYear=oDate.getFullYear();var aDateData=new Array();var aYearsInCalendar;var iMonthCount=(iCurrentMonth+this.iMonthsInCalendar);var iMaxYear;var iYear=iCurrentYear;for(i=0;i<iMonthCount;i++){if(i==0&&iYear==iCurrentYear){i=iCurrentMonth;}if(i>11){iMonth=i-12;if(iMonth==0){iYear++;}}else{iMonth=i;}iMaxYear=iYear;if(typeof (aDateData[iYear])=="undefined"){aDateData[iYear]=new Array();}aDateData[iYear][iMonth]=new Array();iDaysInMonth=this._getDaysInMonth(iMonth,iYear);for(j=1;j<(iDaysInMonth+1);j++){oCurrent=new Date(iYear,iMonth,j);iWeekDay=oCurrent.getDay();if(iWeekDay==0){iWeekDay=7;}if(typeof (aDateData[iYear][iMonth][iWeekDay])=="undefined"){aDateData[iYear][iMonth][iWeekDay]=new Array();}aDateData[iYear][iMonth][iWeekDay].push(j);}}var sMonthHTMLTotal="";var iMonthCounter=1;for(iYear=iCurrentYear;iYear<=iMaxYear;iYear++){for(iMonth=0;iMonth<aDateData[iYear].length;iMonth++){if(aDateData[iYear][iMonth]){sMonthHTML="<table class=\"calendermonth\" id=\"month"+iYear+"_"+iMonth+"\" cellspacing=\"0\" cellpadding=\"0\">\n<tr>\n <td colspan=\"7\" class=\"label_month_nav\">  <div class=\"label_nav_previous_month\">";if(iMonthCounter!=1){sMonthHTML+="  <a href=\"#\" onclick=\"oCalendar.NavPreviousMonth("+iYear+","+iMonth+");\"><<<</a>";}sMonthHTML+="  </div>  <div class=\"label_month\">"+this.aMonths[iMonth]+" </div>  <div class=\"label_nav_next_month\">";if(iMonthCounter!=this.iMonthsInCalendar){sMonthHTML+=" <a href=\"#\" onclick=\"oCalendar.NavNextMonth("+iYear+","+iMonth+");\">>>></a>";}sMonthHTML+="  </div> </td>\n</tr>\n";var iTotalCellsToFill=0;for(iWeekDay=1;iWeekDay<aDateData[iYear][iMonth].length;iWeekDay++){iTotalCellsToFill=(aDateData[iYear][iMonth][iWeekDay].length+1);if(iMonth==8){iTotalCellsToFill=5;}}var oCurrent=new Date(iYear,iMonth,1);iStartWeekDay=(oCurrent.getDay()==0)?7:oCurrent.getDay();iDayInPreviousMonth=this._getDaysInMonth((iMonth-1),iYear);var iNextMonthDay=1;for(iWeekDay=1;iWeekDay<aDateData[iYear][iMonth].length;iWeekDay++){sWeekDay=(iWeekDay==7)?this.aWeekDays[0]:this.aWeekDays[iWeekDay];aDays=aDateData[iYear][iMonth][iWeekDay];sMonthHTML+="<tr>\n <td class=\"label_weekday\">"+sWeekDay+"</td>\n";var iTotalCellsFilled=0;if(iStartWeekDay>iWeekDay){iPreviousDay=(iDayInPreviousMonth-(iStartWeekDay-(iWeekDay+1)));sMonthHTML+=" <td class=\"label_day_previous_month\">"+iPreviousDay+"</td>\n";iTotalCellsFilled++;}for(iDay=0;iDay<aDays.length;iDay++){var day_class=(aDays[iDay]==iCurrentDay&&iMonth==iCurrentMonth&&iYear==iCurrentYear)?"label_current_day":"label_day";bIsClickAble=((aDays[iDay]>=(iCurrentDay-this.iDaysInThePast)&&iMonth==iCurrentMonth)||(iMonth!=iCurrentMonth));if(bIsClickAble){sMonthHTML+=" <td class=\""+day_class+"\"><a href=\"#\" onclick=\"oCalendar.ShowAgendaItems("+iYear+","+iMonth+","+aDays[iDay]+")\">"+aDays[iDay]+"</a></td>\n";}else{sMonthHTML+=" <td class=\""+day_class+"\">"+aDays[iDay]+"</td>\n";}iTotalCellsFilled++;}for(i=iTotalCellsFilled;i<iTotalCellsToFill;i++){sMonthHTML+=" <td class=\"label_day_previous_month\"><a href=\"#\" onclick=\"oCalendar.ShowAgendaItems("+iYear+","+(iMonth+1)+","+iNextMonthDay+")\">"+iNextMonthDay+"</a></td>\n";iNextMonthDay++;}sMonthHTML+="</tr>\n";if(iWeekDay==0){iWeekDay=7;}}sMonthHTML+="</table>\n";sMonthHTMLTotal+=sMonthHTML;iMonthCounter++;}}}this.calendarHolder.innerHTML=sMonthHTMLTotal;oCalendarResultDiv=$("calendar_result");var myFx=new Fx.Style(oCalendarResultDiv,"opacity").set(0);this.showCurrentMonth(iCurrentMonth,iCurrentYear);},showCurrentMonth:function(iCurrentMonth,iCurrentYear){oTableMonth=$("month"+iCurrentYear+"_"+iCurrentMonth);oTableMonth.style.display="block";},_getDaysInMonth:function(iMonth,iYear){return(32-new Date(iYear,iMonth,32).getDate());},_getEventsPerDay:function(iMonth,iYear){return Array(6,11,13);},ShowAgendaItems:function(iYear,iMonth,iDay){iMonth++;if(iMonth<10){iMonth="0"+iMonth;}if(iDay<10){iDay="0"+iDay;}document.location.href="/agenda-resultaten/?date="+iYear+"-"+iMonth+"-"+iDay;},NavPreviousMonth:function(iYear,iMonth){this.HideCalendarMonths();if(iMonth==0){iNewMonth=11;iNewYear=iYear-1;}else{iNewMonth=iMonth-1;iNewYear=iYear;}this.showCurrentMonth(iNewMonth,iNewYear);},NavNextMonth:function(iYear,iMonth){this.HideCalendarMonths();if(iMonth==11){iNewMonth=0;iNewYear=iYear+1;}else{iNewMonth=iMonth+1;iNewYear=iYear;}this.showCurrentMonth(iNewMonth,iNewYear);},HideCalendarMonths:function(){aTables=this.calendarHolder.getElements("table");aTables.each(function(element){element.style.display="none";});}});Calendar.implement(new Events);Calendar.implement(new Options);var oCalendar;window.addEvent("domready",function(){oCalendar=new Calendar("calendar");});

