//created on sep 14 2012
Date.prototype.getWeek = function (dowOffset) {
/*getWeek() was developed by Nick Baicoianu at MeanFreePath: http://www.epoch-calendar.com */

	dowOffset = typeof(dowOffset) == 'int' ? dowOffset : 0; //default dowOffset to zero
	var newYear = new Date(this.getFullYear(),0,1);
	var day = newYear.getDay() - dowOffset; //the day of week the year begins on
	day = (day >= 0 ? day : day + 7);
	var daynum = Math.floor((this.getTime() - newYear.getTime() - (this.getTimezoneOffset()-newYear.getTimezoneOffset())*60000)/86400000) + 1;
	var weeknum;
	//if the year starts before the middle of a week
	if(day < 4) {
		weeknum = Math.floor((daynum+day-1)/7) + 1;
		if(weeknum > 52) {
			nYear = new Date(this.getFullYear() + 1,0,1);
			nday = nYear.getDay() - dowOffset;
			nday = nday >= 0 ? nday : nday + 7;
			/*if the next year starts before the middle of
 			  the week, it is week #1 of that year*/
			weeknum = nday < 4 ? 1 : 53;
		}
	}
	else {
		weeknum = Math.floor((daynum+day-1)/7);
	}
	return weeknum;
};

Date.prototype.daysInMonth = function(){
	var daysArray = [31,28,31,30,31,30,31,31,30,31,30,31];
	if(this.getFullYear()%4 == 0)
		daysArray[1] = 29;

	return daysArray[this.getMonth()];
}

var calendarAPI = function(){
	c = this;
	this.event_create_div = $("#event_create");
	this.event_quick_view_div = $("#event_quick_view");
	this.today = new Date();
	this.cur_month = c.today.getMonth()+1;
	this.cur_year = c.today.getFullYear();
	this.cur_week = c.today.getWeek();
	this.cur_date = c.today.getDate();
	this.view = null;
	this.calendars = new Array();
	this.monthlist = ["","January","February","March","April","May","June","July","August","September","October","November","December"];
	this.initialize = function(){
		$(window).load(function(){
			// c.loadMonthView(c.cur_month,c.cur_year);
			// c.loadWeekView(c.cur_week,c.cur_year);
			// c.loadDayView(c.cur_date,c.cur_month,c.cur_year);
			c.loadAgendaView();
			$(".calendar-filter-btn").each(function(){
				c.calendars.push($(this).attr("href"));
			})
			bindHandlers();
		})
		var bindHandlers = function(){
			$(".event").live("click",function(e){
				var pos = {"x":e.clientX,"y":e.clientY};
				c.displayEvent($(this),pos);
			})
			
			$("#create_event_btn").click(function(){
				if(!$(this).hasClass("active")){
					c.newEvent($(this).attr("href"),$(this).attr("ref"),c.today.getDate(),c.today.getMonth()+1,c.today.getFullYear(),10.5,"AM");
				}else{
					c.event_create_div.hide().empty();
				}
				$(this).toggleClass("active");
				return false;
			})
			$(".click_event").live("click",function(e){
				var dt = $(this).attr("date");
				if(!dt){
					var w = $("td.week_day_body").width();
					var parentOffset = $("table.cell_map").offset(); 
					var relX = e.pageX - parentOffset.left;
					var t = 60;
					for (var i = 0; i <= 6; i++) {		
						if(relX > t && relX < (t + w)){
							console.log(i);
							dt = $("td.week_day_body").eq(i).attr("date");
							break;
						}
						t = t + w;
					};
				}
				var time = $(this).attr("time");
				var ses = $(this).attr("ses");
				if (!time)
					time = 10.5;
				if(!ses)
					ses = "AM";

				c.newEvent($(this).attr("link"),$(this).attr("ref"),dt,c.cur_month,c.cur_year,time,ses);
				$("#create_event_btn").toggleClass("active");
				e.stopPropagation();
			})
			$(".calendar-filter-btn").click(function(){
				$(this).toggleClass("active");
				c.calendars = [];
				$(".calendar-filter-btn").each(function(){
					if($(this).hasClass("active"))
						c.calendars.push($(this).attr("href"));
				})
				c.refresh();
			})

			$("#edit_event_btn").live("ajax:success",function(evt,form){
				c.event_quick_view_div.empty().hide();
				c.updateEvent(form);
			})
			$("#refresh_btn").click(function(){
				c.refresh();
			})
			
			$('.mode_switch').click(function(){
				var target = $(this).text();
				switch(target){
					case 'month':
						c.loadMonthView(c.cur_month,c.cur_year);
					break;
					case 'week':
						c.loadWeekView(c.cur_week,c.cur_year);
					break;
					case 'day':
						c.loadDayView(c.cur_date,c.cur_month,c.cur_year);
					break;
					case 'agenda':
						c.loadAgendaView();
					break;
				}
			})
			$("button#prev_month_btn").click(function(){
				switch (c.view){
					case "month":
						var m,y;
						if(c.cur_month == 1){
							m = 12;
							y = c.cur_year-1;
						}else{
							m = c.cur_month-1;
							y = c.cur_year;
						}
						c.loadMonthView(m,y);
					break;
					case "week":
						var w,y;
						if(c.cur_week == 1){
							w = 52;
							y = c.cur_year - 1;
						}else{
							w = c.cur_week - 1;
							y = c.cur_year;
						}
						c.loadWeekView(w,y);
					break;
					case "day":
						var d,w,y;
						d = c.cur_date - 1;
						m = c.cur_month;
						y = c.cur_year;
						if(d == 0){
							var dx = new Date(c.cur_year,c.cur_month-2);
							d = dx.daysInMonth();
							m--;
						}
						if(m == 0){
							m = 12;
							y = y - 1;
						}
						c.loadDayView(d,m,y);
					break;
				}
				
			})
			$("button#next_month_btn").click(function(){
				switch (c.view){
					case "month":
						var m,y;
						if(c.cur_month == 12){
							m = 1;
							y = c.cur_year+1;
						}else{
							m = c.cur_month+1;
							y = c.cur_year;
						}
						c.loadMonthView(m,y);
					break;
					case "week":
						var w,y;
						
						if(c.cur_week == 52){
							w = 1;
							y = c.cur_year + 1;
						}else{
							w = c.cur_week + 1;
							y = c.cur_year;
						}
						c.loadWeekView(w,y);
					break;
					case "day":
						var d,w,y;
						var dx = new Date(c.cur_year,c.cur_month-1);
						if(c.cur_date == dx.daysInMonth()){
							d = 1;
							m = c.cur_month + 1;
						}else{
							d = c.cur_date + 1;
							m = c.cur_month;
						}

						if(m == 13){
							m = 1;
							y = c.cur_year + 1;
						}else{
							y = c.cur_year;
						}

						c.loadDayView(d,m,y);
					break;
				}
			})
			$("button#today_btn").click(function(){
				switch (c.view){
					case "week":
						c.loadWeekView();
					break;
					case "month":
						c.loadMonthView();
					break;
					case "day":
						c.loadDayView();
					break;
				}
			})
		}
	}
	this.loadMonthView = function(month,year){
		$("#range_selection").hide();
		$("#navigation").show();
		$("#sec1").removeClass("span7").addClass("span3");
		$("#sec3").removeClass("span5").addClass("span4");
		$("#sec2").show();
		c.view = "month";
		if(!month){
			var dt = new Date();
			month = dt.getMonth()+1;
			year = dt.getFullYear();
		}
		// month = 10;
		// year = 2008;
		c.cur_month = month;
		c.cur_year = year;
		$('#view_holder').load("cals/month_view?month="+month+"&year="+year, function() {
			c.getEventsForMonth(month,year);
			$('.current_day_title').text(c.monthlist[c.cur_month]+" "+c.cur_year);
			if($('#calendar_month').length > 0){
				var $c_table = $('#calendar_month');
				var sum_h = 0;
				var context_h = $(window).height() - $('#orbit-bar').height();
				$('#main-wrap > *').not('#orbit_calendar, .modal').each(function(){
					sum_h += $(this).outerHeight();
				});

				$c_table
					// .height(context_h-sum_h-64)
					.find('.month_row')
					.not('.month_row.header')
					.height((context_h-sum_h-92) / 6);
				
				$(window).resize(function(){
					$c_table
						.find('.month_row')
						.not('.month_row.header')
						.height(($('#main-sidebar').outerHeight()-sum_h-92) / 6);
				});
			}
		})
		
	}
	
	
	this.getEventsForMonth = function(month,year){
		$.getJSON("cals/getMonthEvents",{"month":month,"year":year,"calendars":c.calendars},function(events){
			makerow(events);
		})
		var doneEventArray = new Array();		
		var makerow = function(events){

			var $eventrow =null;
			var currow = 0;
			var curdate = 0;
			var allow = false;
			var curparent = null;
			var lastno = 0;
			var indexcount = events.length;
			$.each(events,function(i,evnt){
				indexcount++;
				if($.inArray(evnt.index,doneEventArray) == -1){
					
					var daydom = $("#calendar_month td[date="+evnt.start_date+"]");
					var thisparent = daydom.parent().parent().parent(); 
					var thisrow = thisparent.attr("row");
					var pos = parseInt(daydom.attr("position"));
					var thisno = daydom.attr("no"); 
					if(thisrow != currow){
						if(curparent){
							curparent.append($eventrow);	
						}
						$eventrow = null;
						$eventrow = $("<tr class='event_row destroy'></tr>");
						allow = true;
					}else if(evnt.start_date > curdate){
						allow = true;
						
					}
					var recordcurdate = true;
				
					if(allow){
						if(pos == 1){
							var colspan = 0;
							if(evnt.total_days>7){
								colspan = 7;
								var totaldays = parseInt(evnt.total_days) - colspan;
								var stardate = parseInt(evnt.start_date) + colspan;
								var index = i + 1;
								var tempArray = {"index":indexcount,"id":evnt.id,"start_date":stardate,"total_days":totaldays,"title":evnt.title,"color":evnt.color,"show_link":evnt.show_link};
								events.splice(index,0,tempArray);
								//recordcurdate = false;
							}else{
								colspan = evnt.total_days;
							}
							$eventrow.html('<td colspan="'+colspan+'" class="main_td" pos="'+pos+'"><div class="event" link="'+evnt.show_link+'" style="background-color: '+evnt.color+';">'+evnt.title+'</div></td>');
						}else{
							if($eventrow.html()==""){
									$eventrow.append('<td colspan="'+(pos-1)+'"></td>');
							}else{
								if((lastno+1)!=thisno){
									var inposition = parseInt($eventrow.find("td.main_td:last").attr("pos"));
									var curcolspan = $eventrow.find("td.main_td:last").attr("colspan");
									var colspan = pos - (inposition+parseInt(curcolspan));
									$eventrow.append('<td colspan="'+colspan+'"></td>');
								}
							}
							var colspan = 0;
							if((pos + parseInt(evnt.total_days))-1 > 7){
								colspan = 7-(pos-1);
								var totaldays = parseInt(evnt.total_days) - colspan;
								var stardate = parseInt(evnt.start_date) + colspan;
							
								var index = i + 1;
								var tempArray = {"index":indexcount,"id":evnt.id,"start_date":stardate,"total_days":totaldays,"title":evnt.title,"color":evnt.color,"show_link":evnt.show_link};
								events.splice(index,0,tempArray);								
							//	recordcurdate = false;
								
							}else{
								colspan = evnt.total_days;
							}
							// if(evnt.title == "Again")
							// 	console.log(colspan);
							$eventrow.append('<td colspan="'+colspan+'" class="main_td" pos="'+pos+'"><div link="'+evnt.show_link+'" class="event" style="background-color: '+evnt.color+';">'+evnt.title+'</div></td>');
						}
						lastno = (parseInt(thisno) + parseInt(evnt.total_days)) - 1;
						currow = thisrow;
						curdate =(evnt.start_date + evnt.total_days) - 1;
						allow = false;
						curparent = thisparent;
						if(recordcurdate)
							doneEventArray.push(evnt.index);
				
						
					}
				}

			})
			if(curparent){
				curparent.append($eventrow);
			}
			if(events.length != doneEventArray.length){
				makerow(events);
			}
		}
	}

	this.loadWeekView = function(week,year){
		$("#range_selection").hide();
		$("#navigation").show();
		$("#sec1").removeClass("span7").addClass("span3");
		$("#sec3").removeClass("span5").addClass("span4");
		$("#sec2").show();
		c.view = "week";
		if(!week){
			var dt = new Date();
			week = dt.getWeek();
			year = dt.getFullYear();
		}

		c.cur_week = week;
		c.cur_year = year;

		$('#view_holder').load("cals/week_view?week="+week+"&year="+year, function() { 
			$('.current_day_title').text($("#week_range").text());
			c.getEventsForWeek(week,year);
		})
	}
	this.getEventsForWeek = function(week,year){
		$.getJSON("cals/getWeekEvents",{"week":week,"year":year,"calendars":c.calendars},function(events){
			var height = 15;
			var full_day_count = 0;
			var rowcount = 7;
			var tr = $("<tr class='destroy'></tr>");
			var pre = true;
			$.each(events,function(i,evnt){
				// console.log("rowcount: "+rowcount);
				// console.log("start:"+evnt.start);
				if(rowcount >= (7 - evnt.total_days)){
					if(tr.html()!=""){
						if(rowcount != 7){
							tr.append("<td colspan='"+(7-rowcount)+"'></td>");
						}
						$("table.all_day_event_holder").append(tr);
					}
					tr = null;
					tr = $('<tr class="destroy"></tr>');
					pre = true;
				}

				if(evnt.all_day){
					full_day_count++;

					var precountspan = 7 - evnt.total_days;
					if(pre){
						height+=20;
						$(".head_event_wrapper").height(height);
						$(".head_event_wrapper table").eq(0).height(height);
						tr.append('<td rowspan="1" style="width:60px;">&nbsp;</td>');
						if(precountspan != 0){
							tr.append('<td colspan="'+precountspan+'"></td>');
							pre = false;
						}
					}
					var colcount = evnt.total_days;
					if(evnt.colcount != 0){
						colcount = evnt.colcount;
					}

					rowcount = precountspan + colcount;
					
					tr.append('<td colspan="'+colcount+'" class="all_day_event week_day" ><div class="event half" style="background-color: '+evnt.color+' ;color:#fff;" link="'+evnt.show_link+'"><dl><dt>'+evnt.title+'</dt><dd></dd></dl></div></td>');
					
					// $(".week_day_header[date="+evnt.start_date+"]").append('<div class="event half" link="'+evnt.show_link+'" style="background-color: '+evnt.color+';color:#fff;"><dl><dt>'+evnt.title+'</dt><dd></dd></dl></div>');
				}else{

					var starttime,endtime,displaystarttime,displayendtime;
					if(evnt.start_am_pm == "AM"){
						starttime = evnt.start_time;
						if(starttime == 12)
							starttime = 0;
						if(starttime == 12.5)
							starttime = 0.5;
					}else
						starttime = evnt.start_time + 12;

					if(evnt.end_am_pm == "AM"){
						endtime = evnt.end_time;
						if(endtime == 12)
							endtime = 0;
						if(endtime == 12.5)
							endtime = 0.5;
					}else
						endtime = evnt.end_time + 12;
					
					var temp = parseInt(evnt.start_time);
					
					if (evnt.start_time > temp)
						displaystarttime = temp + ":30 " + evnt.start_am_pm;
					else
						displaystarttime = temp + ":00 " + evnt.start_am_pm;

					temp = parseInt(evnt.end_time);
					
					if (evnt.end_time > temp)
						displayendtime = temp + ":30 " + evnt.end_am_pm;
					else
						displayendtime = temp + ":00 " + evnt.end_am_pm;

					var toppx = ((starttime * 2) * 20) + 1;
					var h = endtime - starttime;
					var halfhour = "";
					if(h == 0.5)
						halfhour = "half";
					h = 17 + 20 + (((h-1) * 2) * 20) + 1;
					var eventdom = $('<div class="event '+halfhour+' destroy" link="'+evnt.show_link+'" style="background-color: '+evnt.color+';color:#fff; top:'+toppx+'px; height:'+h+'px;"><dl><dt>'+displaystarttime+' - '+displayendtime+'</dt><dd>'+evnt.title+'</dd></dl></div>');
					$(".week_day_body[date="+evnt.start_date+"] .inner").append(eventdom);
				}
				if(full_day_count  == 0){
					tr.append('<td rowspan="1" style="width:60px;">');
					$("table.all_day_event_holder").append(tr);
				}

			})
			if(tr.html()!=""){
				if(rowcount != 7){
					tr.append("<td colspan='"+(7-rowcount)+"'></td>");
				}
				$("table.all_day_event_holder").append(tr);
			}
		})
	}
	this.loadDayView = function(day,month,year){
		$("#range_selection").hide();
		$("#navigation").show();
		$("#sec1").removeClass("span7").addClass("span3");
		$("#sec3").removeClass("span5").addClass("span4");
		$("#sec2").show();
		c.view = "day";
		if(!day){
			var dt = new Date();
			week = dt.getWeek();
			year = dt.getFullYear();
			day = dt.getDate();
			month = dt.getMonth()+1;
		}

		c.cur_date = day;
		c.cur_month = month;
		c.cur_year = year;

		$('#view_holder').load("cals/day_view?date="+day+"&month="+month+"&year="+year, function() { 
			$('.current_day_title').text($("#day_header").text());
			c.getEventsForDay(day,month,year);
		})
	}
	this.getEventsForDay = function(day,month,year){
		$.getJSON("cals/getDayEvents",{"date":day,"month":month,"year":year,"calendars":c.calendars},function(events){
			$.each(events,function(i,evnt){
				if(evnt.all_day){
					$(".all_day_event").append('<div class="event destroy" link="'+evnt.show_link+'" style="background-color: '+evnt.color+';color:#fff;">'+evnt.title+'</div>')
				}else{
					var starttime,endtime,displaystarttime,displayendtime;
					if(evnt.start_am_pm == "AM"){
						starttime = evnt.start_time;
						if(starttime == 12)
							starttime = 0;
						if(starttime == 12.5)
							starttime = 0.5;
					}else
						starttime = evnt.start_time + 12;

					if(evnt.end_am_pm == "AM"){
						endtime = evnt.end_time;
						if(endtime == 12)
							endtime = 0;
						if(endtime == 12.5)
							endtime = 0.5;
					}else
						endtime = evnt.end_time + 12;
					
					var temp = parseInt(evnt.start_time);
					
					if (evnt.start_time > temp)
						displaystarttime = temp + ":30 " + evnt.start_am_pm;
					else
						displaystarttime = temp + ":00 " + evnt.start_am_pm;

					temp = parseInt(evnt.end_time);
					
					if (evnt.end_time > temp)
						displayendtime = temp + ":30 " + evnt.end_am_pm;
					else
						displayendtime = temp + ":00 " + evnt.end_am_pm;

					var toppx = ((starttime * 2) * 20) + 1;
					var h = endtime - starttime;
					var halfhour = "";
					if(h == 0.5)
						halfhour = "half";
					h = 17 + 20 + (((h-1) * 2) * 20) + 1;
					var eventdom = $('<div class="inner"><div class="event '+halfhour+' destroy" link="'+evnt.show_link+'" style="background-color: '+evnt.color+';color:#fff; top:'+toppx+'px; height:'+h+'px;"><dl><dt>'+displaystarttime+' - '+displayendtime+'</dt><dd>'+evnt.title+'</dd></dl></div></div>');
					$(".event_holder").append(eventdom);
				}

			})

		})
	}
	this.loadAgendaView = function(start_month,start_year,end_month,end_year){
		c.view = "agenda";
		var url = "cals/agenda_view";
		if(start_month && start_year && end_month && end_year)
			var url = "cals/agenda_view?s_month="+start_month+"&s_year="+start_year+"&e_month="+end_month+"&e_year="+end_year ;

		$('#view_holder').load(url, function() { 
			$("#navigation").hide();
			$("#range_selection").html($("#agenda_date_range").html()).show();
			$("#sec1").removeClass("span3").addClass("span7");
			$("#sec3").removeClass("span4").addClass("span5");
			$("#sec2").hide();
			bindHandlers();
		})
		var bindHandlers = function(){
			$("select[name=start_year]").change(function(){
				var x = parseInt($(this).val()) - parseInt($(this).find("option").eq(0).val());
				$("select[name=end_year] option").removeAttr("disabled");
				for(i=0;i<x;i++){
					$("select[name=end_year] option").eq(i).attr("disabled","disabled");
				}
			})
			$("#range_selection .bt-filter").click(function(){
				var start_month = $("select[name=start_month]").val();
				var start_year = $("select[name=start_year]").val();
				var end_year = $("select[name=end_year]").val();
				var end_month = $("select[name=end_month]").val();
				c.loadAgendaView(start_month,start_year,end_month,end_year);
			})
		}
	}
	this.newEvent = function(url,ref,date,month,year,time,ses){
		var bindHandlers = function(){
			c.event_create_div.find("button.btn-close").click(function(){
				c.event_create_div.hide().empty();
				$("#create_event_btn").removeClass("active");
			})
			c.event_create_div.find("input[for=all_day][type=checkbox]").click(function(){
				if($(this).is(":checked"))
					c.event_create_div.find("#non_all_day").hide()
				else
					c.event_create_div.find("#non_all_day").show()
			})
			$( "#dpfrom" ).datepicker({
	            defaultDate: "+1w",
	            changeMonth: true,
	            numberOfMonths: 3,
	            onSelect: function( selectedDate ) {
	                $( "#dpto" ).datepicker( "option", "minDate", selectedDate );
	            }
        	});
        	$( "#dpto" ).datepicker({
	            defaultDate: "+1w",
	            changeMonth: true,
	            numberOfMonths: 3,
	            onSelect: function( selectedDate ) {
	                $( "#dpfrom" ).datepicker( "option", "maxDate", selectedDate );
	            }
        	});
        	$('#open_tags_panel').click(function(){
        		$('#tags_panel').toggle();
        		$('.my_scroll').tinyscrollbar();
        		return false;
        	});
		}

		c.event_create_div.load(url+"?ref="+ref+"&date="+date+"&month="+month+"&year="+year+"&time="+time+"&ses="+ses,function(){
			c.event_create_div.show();
			bindHandlers();
		})
		
	}

	this.updateEvent = function(form){
		var bindHandlers = function(){
			c.event_create_div.find("button.btn-close").click(function(){
				c.event_create_div.hide().empty();
				$("#create_event_btn").removeClass("active");
				$("#create_event_btn").show();
			})
			c.event_create_div.find("input[for=all_day][type=checkbox]").click(function(){
				if($(this).is(":checked"))
					c.event_create_div.find("#non_all_day").hide()
				else
					c.event_create_div.find("#non_all_day").show()
			})
			$( "#dpfrom" ).datepicker({
	            defaultDate: "+1w",
	            changeMonth: true,
	            numberOfMonths: 3,
	            onSelect: function( selectedDate ) {
	                $( "#dpto" ).datepicker( "option", "minDate", selectedDate );
	            }
        	});
        	$( "#dpto" ).datepicker({
	            defaultDate: "+1w",
	            changeMonth: true,
	            numberOfMonths: 3,
	            onSelect: function( selectedDate ) {
	                $( "#dpfrom" ).datepicker( "option", "maxDate", selectedDate );
	            }
        	});
		}
		c.event_create_div.html(form);
		$("#create_event_btn").hide();
		c.event_create_div.show();
		bindHandlers();
	}

	this.newCalendars = function(){
		if($('.color-picker').length > 0){
			$('.color-picker').miniColors(); // just in category view
		}
		$(".btn-del-a").live("ajax:success",function(){
			var domfor = $(this).attr("data-content");
			$("tr[for="+domfor+"]").remove();
		})
		$(".btn-edit-a").live("ajax:success",function(evt,form){
			$("#edit_area_" + $(this).attr("for")).html(form).slideDown();
			$("#edit_area_" + $(this).attr("for")).find(".color-picker").miniColors();
		})
		$(".bt-cancel").live("click",function(){
			$("#edit_area_" + $(this).attr("for")).html("").slideUp();
		})
	}
	this.displayEvent = function(dom,pos){
		var url = dom.attr("link");
		c.event_quick_view_div.load(url,function(){
			var x = pos.x;
			var y = pos.y;
			var winheight = $(window).height()
			if((x+c.event_quick_view_div.width()) > $(window).width()){
				x = x - c.event_quick_view_div.width();
			}
			if((y+c.event_quick_view_div.height()) > winheight){
				y = y - c.event_quick_view_div.height();
			}
			c.event_quick_view_div.css({"left":x+"px","top":y+"px"}).show()
			c.event_quick_view_div.find(".event-close-btn").click(function(){
				c.event_quick_view_div.empty().hide();
			})
			c.event_quick_view_div.find(".bt-del").bind("ajax:success",function(){
				c.event_quick_view_div.empty().hide();
				dom.remove();
			})
		})
	}
	this.refresh = function(){
		$(".destroy").remove();
		switch (c.view){
			case "week":
				c.loadWeekView(c.cur_week,c.cur_year);
			break;
			case "month":
				c.loadMonthView(c.cur_month,c.cur_year);
			break;
			case "day":
				c.loadDayView(c.cur_date,c.cur_month,c.cur_year);
			break;
		}
	}
	
	c.initialize();
}







