/*
* Copyright (c) 2009 1Calendar ApS
* All Rights Reserved.
* http://www.1calendar.dk
* Date: Fri, 12 Mar 10 14:16:08 +0000
*/

(function($){Function.prototype.bind=function(binding){var self=this;return function(){return self.apply(binding,arguments);};};String.prototype.toTitleCase=function(){return this.replace(/(\b\w)(\S+\s*)/g,function(word){return word.charAt(0).toUpperCase()+
word.substr(1).toLowerCase();});};Weekflow=DUI.Class.create(Messaging.prototype,{__year:Date.today().getFullYear(),__week:null,__last:null,__stop:false,listeners:{},setWeek:function(date){var startDate=date.startOfWeek();var endDate=date.endOfWeek();if(startDate.getMonth()==11&&startDate.getFullYear()==this.__year&&endDate.getMonth()==0){date=startDate;}
this.yearElement.stop();if(this.__week&&this.__week.inSameWeekAs(date))return this;this.__week=date.startOfWeek();if(startDate.getFullYear()!=this.__year){var self=this;self.yearElement.stop();this.yearElement.fadeOut("fast",function(){self.fadeInYear(startDate.getFullYear());self.highlightWeek(startDate);self.focusWeek(startDate,false);});}else{var self=this;this.yearElement.fadeTo(0,1,function(){self.highlightWeek(date);self.focusWeek(date,true);});};this.yearElement.css('opacity',null);return this;},getWeek:function(){return this.__week.clone();},initialize:function(element){this.element=element;this.yearElement=null;this.yearWrapper=$('<div class="year-wrapper"/>').appendTo(element);this.tooltip=$('<div class="tooltip"><div/></div>').appendTo('.headers').hide();this.tooltip.left=function(left){this.css('left',left);};this.tooltip.text=function(text){this.children().eq(0).text(text.toString());};this.navigationElements={prev:$('<a class="navigation prev" href="#">&#32;</a>').appendTo(element),next:$('<a class="navigation next" href="#">&#32;</a>').appendTo(element),year:{prev:$('<a class="navigation year prev" href="#">'+(this.__year-1)+'</a>').appendTo(element),next:$('<a class="navigation year next" href="#">'+(this.__year+1)+'</a>').appendTo(element)}};var self=this;this.navigationElements.prev.bind('mouseover',function(event){self.navigationElements.prev.data('scrollInterval',setInterval(function(){self._scrollYear(+15);},30));});this.navigationElements.next.bind('mouseover',function(event){self.navigationElements.next.data('scrollInterval',setInterval(function(){self._scrollYear(-15);},30));});this.navigationElements.prev.bind('mouseout',function(event){clearInterval(self.navigationElements.prev.data('scrollInterval'));});this.navigationElements.next.bind('mouseout',function(event){clearInterval(self.navigationElements.next.data('scrollInterval'));});function blurAndReturnFalse(){this.blur();return false;};this.navigationElements.next.bind('click',blurAndReturnFalse);this.navigationElements.prev.bind('click',blurAndReturnFalse);this.navigationElements.year.prev.bind('click',function(){self.yearElement.fadeOut("slow",function(){self.fadeInPrevYear();});this.blur();return false;});this.navigationElements.year.next.bind('click',function(){self.yearElement.fadeOut("slow",function(){self.fadeInNextYear();});this.blur();return false;});this._insertYear(this.__year);this.setWeek(Date.today());},fadeInPrevYear:function(){this.fadeInYear(this.__year-1);this.yearElement.css('left',-(this.yearElement.width()-this.yearWrapper.width()));},fadeInNextYear:function(){this.fadeInYear(this.__year+1);this.yearElement.css('left',0);},fadeInYear:function(year){this.yearWrapper.empty();this._insertYear(year);this.yearElement.hide();this.yearElement.fadeIn('slow');this.fire('year-select',[year]);},focusWeek:function(date,isAnimated){var offset=0;if(this.__stop==true){this.__stop=false;return;}
var num=this._weekInUI(date)-1;if(num==-1){offset=this.yearElement.width()-this.yearWrapper.width();}
if(offset==0){var week=this.yearElement.find('.week').eq(num);var offset;if(week.position()!=undefined){offset=week.position().left+week.outerWidth()/2-this.yearWrapper.width()/2;}
else
{offset=0;}
if(offset<0){offset=0;}
if(offset>this.yearElement.width()-this.yearWrapper.width()){offset=this.yearElement.width()-this.yearWrapper.width();}}
var left=-offset;if(isAnimated)
this.yearElement.animate({left:left},"slow");else
this.yearElement.css('left',left);return left;},highlightWeek:function(date){var weekEnd=date.endOfWeek();var month=date.getMonth();this.yearElement.children('.month, .week').removeClass('active');this.yearElement.children('.month').eq(month).addClass('active');if(weekEnd.getFullYear()==this.__year){var weekMonth=weekEnd.getMonth();this.yearElement.children('.month').eq(weekMonth).addClass('active');}
var num=this._weekInUI(date)-1;if(num==-1){this.fadeInPrevYear();this.yearElement.children('.week').eq(52).addClass('active');return;}
if(this.__last!=null){var weeks=this._weekInUI(this.__last)-1;if(weeks==num){this.__stop=true;this.fadeInNextYear();this.yearElement.children('.week').eq(0).addClass('active');this.yearElement.css('left',0);return;}}
this.__last=date;this.yearElement.children('.week').eq(num).addClass('active');},_insertYear:function(number){var year=$('<div class="year"/>').appendTo(this.yearWrapper);year.data('number',number);var months=[];for(var i=0;i<12;i++)
months.push($('<span class="month">'+Date.CultureInfo.abbreviatedMonthNames[i].toTitleCase()+'</span>').appendTo(year));var left=0;var month=0;var startWeekLeft=0;var showTooltip=function(event){var element=$(event.currentTarget);var weekStart=element.data('date').startOfWeek();var weekEnd=weekStart.endOfWeek();var text=weekStart.toString('d. MMM.')+" – "+weekEnd.toString('d. MMM.');this.tooltip.text(text);var left=element.offset().left-this.element.offset().left-this.tooltip.width()/2+element.outerWidth()/2;this.tooltip.left(left);this.tooltip.show();}.bind(this);var hideTooltip=function(event){this.tooltip.hide();}.bind(this);var yearDate=new Date(number,0,1);var nextYear=yearDate.getFullYear()+1;var weeksInYear=yearDate.getWeeksInYear();for(var i=1;i<=weeksInYear;i++){var date=yearDate.clone().setWeek(i);if(i==1)date.setDate(4);var week=$('<a class="week" href="#"><span>'+i+'</span></a>').appendTo(year);week.data('date',date);week.width(week.width());if(month!=date.getMonth()){var endDate=date.endOfWeek();if(months[month])
months[month].width(left-startWeekLeft);if(month<endDate.getMonth()){month=endDate.getMonth();months[month].css('left',left);startWeekLeft=left+week.outerWidth();};};week.bind('click',function(event){var e=$(event.currentTarget);var d=e.data('date');this.setWeek(d);this.fire('week-select',[d]);e.blur();return false;}.bind(this));var fiveRomanNumerals=['i','ii','iii','iv','v'];week.bind('mouseover',function(event){var e=$(event.currentTarget);var p=e.prevAll('.week').slice(0,5);var n=e.nextAll('.week').slice(0,5);$.each(p,function(i,e){$(e).addClass('zoom '+(fiveRomanNumerals[i]));});$.each(n,function(i,e){$(e).addClass('zoom '+(fiveRomanNumerals[i]));});}.bind(this));week.bind('mouseout',function(event){this.element.find('.week').removeClass('zoom '+fiveRomanNumerals.join(' '));}.bind(this));week.bind('mouseover',showTooltip);week.bind('mouseout',hideTooltip);week.css('left',left);left+=week.outerWidth();};months[11].width(left-months[11].position().left);year.width(left);year.css('left',0);this.__year=number;this.yearElement=year;this.navigationElements.year.prev.text(number-1);this.navigationElements.year.next.text(number+1);return year;},_scrollYear:function(offset){var currentLeft=this.yearElement.position().left;var newLeft=currentLeft+offset;var minLeft=-(this.yearElement.width()-this.yearWrapper.width());if(offset>0&&newLeft>0){if(currentLeft<0)newLeft=0;else return false;}
if(offset<0&&newLeft<minLeft){if(currentLeft>minLeft)newLeft=minLeft;else return false;}
this.yearElement.css('left',newLeft);},_weekInUI:function(date){var weekNumber=date.getISOWeek();if(weekNumber==1&&date.getMonth()!=0)
weekNumber=date.getWeeksInYear();return weekNumber;}},true);})(jQuery);
;
(function($){function coincident(startA,durationA,startB,durationB){return(startA.getTime()>=startB.getTime()&&startA.getTime()<startB.plus(durationB).getTime()||startA.getTime()<=startB.getTime()&&startA.plus(durationA).getTime()>startB.getTime());}
function getTimeString(event)
{var fromHour=event.start.getHours().toString();fromHour=fromHour.length==1?'0'+fromHour:fromHour;var fromMinutes=event.start.getMinutes().toString();fromMinutes=fromMinutes.length==1?'0'+fromMinutes:fromMinutes;var fromTime=fromHour+':'+fromMinutes;var toHour=event.start.plus(event.duration).getHours().toString();toHour=toHour.length==1?'0'+toHour:toHour;var toMinutes=event.start.plus(event.duration).getMinutes().toString();toMinutes=toMinutes.length==1?'0'+toMinutes:toMinutes;var toTime=toHour+':'+toMinutes;return fromTime+' - '+toTime;}
Weekview=DUI.Class.create({addOnDate:function(event,date,recurrence,editImmediatly){var dom=$('<div class="event normal">'+'<div class="e_htop ui-resizable-handle ui-resizable-n"></div>'+'<dl>'+'<dt class="cat-color"/>'+'</dl>'+'<div class="e_hbottom ui-resizable-handle ui-resizable-s"></div>'+'</div>');dom.find('dt').text(getTimeString(event));if(event.thumb)
dom.css({'background-image':'url('+event.thumb+')','background-repeat':'no-repeat','background-position':'top right'});if(event.name)
dom.find('dl').append($('<dd />').text(event.name));if(event.location)
dom.find('dl').append($('<dd/>').text(event.location));if(event.description)
dom.find('dl').append($('<dd style="white-space:pre-wrap" />').text(event.description));dom.attr('id',event.repeat?'evt_'+event.Id+'_'+recurrence.getISO8601UTC():'evt_'+event.Id);if(event.categoryId)
dom.addClass('cat_'+event.categoryId);else if(event.editable||!event.editable)
dom.addClass('cat_0');else if(!event.editable)
dom.addClass('cat_uneditable');if(event.locked)
dom.addClass('locked');if(!event.editable)
dom.addClass('uneditable');dom.addClass('evt_'+event.Id);dom.addClass($.isArray(event.calendarId)?event.calendarId[0]+'_'+event.calendarId[1]:'cal_'+event.calendarId);dom.data('event',event);dom.data('start',date);if(recurrence)
dom.data('recurrence',recurrence);dom.css({'display':'none','height':'0px','z-index':0});dom.data('list',dom.find('dl'));$(dom).appendTo('#events');dom.bind('dblclick',function(event){event.stopPropagation();});this.__event_dom_object_set_time(dom,date,event.duration);dom.hide();dom.stop(true,true);dom.fadeIn();dom.bind('mousedown',function(e){if(event.locked||!event.editable)
e.stopImmediatePropagation();});dom.bind('click',function(e){e.stopPropagation();if(dom.data('inTransit')){dom.data('inTransit',false);return;}
if(event.locked)return;Calendar.fire('event-select',[dom.data('event'),dom,dom.data('start'),false]);});if(editImmediatly==true)
{Calendar.fire('event-select',[dom.data('event'),dom,dom.data('start'),true]);}
if(!event.repeat&&event.editable){dom.draggable({containment:'parent',handle:'dl',scroll:true,scrollSensitivity:60,scrollSpeed:20,zIndex:599,start:function(event,ui){Calendar.fire('event-move-start',[ui.helper.data('event')]);Weekview.eventDragging=true;dom.data('inTransit',true);ui.helper.css({'left':ui.helper.position().left+'px','width':(ui.helper.width()/$('#events').width()*100)+'%','right':null});ui.helper.stop(true,true);ui.helper.animate({'width':'14.285%'},{'easing':'easeOutQuad','duration':500}).css('overflow','visible');},drag:function(event,ui){},stop:function(event,ui){Weekview.eventDragging=false;var day=Math.round(ui.position.left/($('#events').width()/7));var left=ui.position.left/$('#events').width()*100;ui.helper.stop(true,true);ui.helper.css({'left':left+'%','right':(85.71428-left)+'%','width':null});if(ui.position.top<0)
ui.position.top=0;var calEvent=ui.helper.data('event');calEvent.start.setDayStartingMonday(day);calEvent.start.setHours(Math.floor(ui.position.top/48),Math.round((ui.position.top%48)*1.25/15)*15);Calendar.move(calEvent,calEvent.start,calEvent.duration);dom.find('dt').text(getTimeString(calEvent));Weekview.__adjust();}});dom.resizable({handles:{n:'.e_htop',s:'.e_hbottom'},minHeight:15*0.8,containment:'parent',start:function(event,ui){Weekview.eventDragging=true;dom.data('inTransit',true);ui.helper.data('formerZIndex',ui.helper.css('zIndex'));ui.helper.css('zIndex',9001);ui.helper.css({'left':ui.helper.position().left+'px','width':(ui.helper.width()/$('#events').width()*100)+'%','right':null});ui.helper.stop(true,true);ui.helper.css('overflow','visible');},resize:function(event,ui){ui.helper.data('list').css('height',ui.size.height-5);},stop:function(event,ui){Weekview.eventDragging=false;ui.helper.css('zIndex',ui.helper.data('formerZIndex'));var calEvent=ui.helper.data('event');var date=calEvent.start;var left=ui.position.left/$('#events').width()*100;ui.helper.stop(true,true);ui.helper.css({'left':left+'%','right':(85.71428-left+0.6)+'%','width':null});if(ui.position.top<0){ui.size.height+=ui.position.top;ui.position.top=0;}
calEvent.duration.hours=Math.floor(ui.size.height/48);calEvent.duration.minutes=Math.round((ui.size.height%48)*1.25/15)*15;calEvent.start.setHours(Math.floor(ui.position.top/48),Math.round((ui.position.top%48)*1.25/15)*15);Calendar.move(calEvent,calEvent.start,calEvent.duration);dom.find('dt').text(getTimeString(calEvent));Weekview.__adjust();}});}
if(event.locked){dom.draggable('disable');dom.resizable('disable');}},__adjust_overlap_all:function(){var events=$.map($.makeArray($('.event.normal:visible:not(.ghost)')),$);for(var i=0;i<events.length;i++){for(var j=i+1;j<events.length;j++){if(coincident(events[j].data('start'),events[j].data('event').duration,events[i].data('start'),events[i].data('event').duration)){events.splice(j,1);}}
this.__adjust_overlap_with_event(events[i],false);}},__group_all_events:function(){var events=$.map($.makeArray($('.event.normal:visible:not(.ghost)')),$);var groups=[];for(var i=0;i<events.length;i++){var group=this.__find_group_of_event(events[i]);groups.push(group);};return groups;},__find_group_of_event:function(firstEvent){var found=[];var events=$.map($.makeArray($('.event.normal:visible:not(.ghost)')),$);var checkEvents=function(startEvent){var group=[];if(found.indexOf(startEvent.data('event').Id)!=-1)
return group;found.push(startEvent.data('event').Id);for(var i=0;i<events.length;i++){var event=events[i];if(found.indexOf(event.data('event').Id)!=-1)
continue;if(coincident(startEvent.data('start'),startEvent.data('event').duration,event.data('start'),event.data('event').duration))
group.push(events[i]);};var duppedGroups=$.extend([],group);for(var i=0;i<duppedGroups.length;i++)
$.merge(group,checkEvents(duppedGroups[i]));return group;};var temp=checkEvents(firstEvent);temp.unshift(firstEvent);return $.unique(temp);},__adjust:function(animate){if(animate===undefined)
animate=true;var groups=this.__group_all_events();for(var i=0;i<groups.length;i++){var group=groups[i];var left=group[0].data('start').getDayStartingMonday()*14.2857;group.sort(function(a,b){var eventA=a.data('event');var eventB=b.data('event');var startA=a.data('start');var startB=b.data('start');return eventA.duration.toTime()<eventB.duration.toTime()?true:eventA.duration.toTime()>eventB.duration.toTime()?false:startA.getTime()>startB.getTime()?true:startA.getTime()<startB.getTime()?false:eventA.Id<eventB.Id;});var step_size=14.2857/2/group.length;for(var j=0;j<group.length;j++){var top=Math.floor(group[j].data('start').getHours()*48+group[j].data('start').getMinutes()*0.8);var height=Math.floor(group[j].data('event').duration.toTime()/75000);group[j].stop(true,true);group[j].css('overflow','visible');if(animate){group[j].animate({'top':top+'px','left':(left+0.3+step_size*j)+'%','right':(85.71428+0.3-left+(step_size*(group.length-j-1)))+'%','height':(height-3)+'px'},{'easing':'easeOutBounce','duration':500}).css({'z-index':50+j,'overflow':'visible'});}else{group[j].css({'top':top+'px','left':(left+0.3+step_size*j)+'%','right':(85.71428+0.3-left+(step_size*(group.length-j-1)))+'%','height':(height-3)+'px','z-index':50+j,'overflow':'visible'});}};};},__get_coincident_events:function(start,duration){var coinciding=[];var _start=start,_end=start.plus(duration);var change=false;$('.event.normal:visible:not(.ghost)').each(function(){var event=$(this);if(coincident(event.data('start'),event.data('event').duration,start,duration)){if(event.data('start')<_start){_start=event.data('start');change=true;}
if(event.data('start').plus(event.data('event').duration)>_end){_end=event.data('start').plus(event.data('event').duration);change=true;}
coinciding.push(event);}});if(change)
return this.__get_coincident_events(_start,_start.differenceTo(_end));return coinciding;},__adjust_overlap_with_event:function(dom,dragging){var coinciding=this.__get_coincident_events(dom.data('start'),dom.data('event').duration);var left=dom.data('start').getDayStartingMonday()*14.2857;if(coinciding.length==1||dragging){dom.animate({'left':(left+0.3)+'%','right':(85.71428-left)+'%'},{'easing':'easeOutQuad','duration':500});dom.css({'z-index':499+(dragging?1:0)});}else{coinciding.sort(function(a,b){var eventA=a.data('event');var eventB=b.data('event');var startA=a.data('start');var startB=b.data('start');return eventA.duration.toTime()<eventB.duration.toTime()?true:eventA.duration.toTime()>eventB.duration.toTime()?false:startA.getTime()>startB.getTime()?true:startA.getTime()<startB.getTime()?false:eventA.Id<eventB.Id;});var step_size=14.2857/2/coinciding.length;for(var i=0;i<coinciding.length;i++){coinciding[i].css({'z-index':50+i});coinciding[i].animate({'left':(left+step_size*i+0.3)+'%','right':(85.71428-left+step_size*(coinciding.length-i-1))+'%'},{'easing':'easeOutBounce','duration':1500});}}},add:function(event){if(event.repeat){if(event.start>Calendar.getWeek().endOfWeek())
return;if(event.end!=null&&event.end<Calendar.getWeek())
return;var end=event.end==null?Calendar.getWeek().endOfWeek():event.end.getTime()<Calendar.getWeek().endOfWeek().getTime()?event.end:Calendar.getWeek().endOfWeek()
var it=new $.ical.repeat(event.repeat,event.start,end);it.skipTo(Calendar.getWeek());var date;while(date=it.next()){this.addOnDate(event,date.clone(),date.clone());}}else if(event.start.sameWeekAs(Calendar.getWeek())){this.addOnDate(event,event.start,null,true);}},__event_dom_object_set_time:function(object,date,duration){var left=date.getDayStartingMonday()*14.2857;var height=Math.floor(duration.toTime()/75000);object.css({'display':'block','top':Math.floor(date.getHours()*48+date.getMinutes()*0.8)+'px','left':left+'%','right':(85.71428-left)+'%','height':(height-3)+'px'});object.data('list').css({'height':(height-5)+'px'});},__get_hovered_date_from_mouse_event:function(event){var x=event.pageX-$('#events').offset().left;var y=event.pageY-$('#events').offset().top-$('#events').scrollTop();var day=Math.floor(x/($('#events').width()/7));var hours=Math.floor(y/48);var minutes=Math.floor((y%48)*1.25);var date=Calendar.getWeek();date.setDayStartingMonday(day);date.setHours(hours,minutes);return date;}},true);$(function(){Weekview.previewEvent=$('<div class="event normal ghost">'+'<div class="e_htop ui-resizable-handle ui-resizable-n"></div>'+'<dl><dt>'+ss.i18n._t('WeekView.NEW_EVENT')+'</dt></dl>'+'<div class="e_hbottom ui-resizable-handle ui-resizable-s"></div>'+'</div>').css('z-index',10000).attr('id',0).appendTo('#events');Weekview.previewEvent.data('list',Weekview.previewEvent.find('dl'));Weekview.eventDragging=false;Weekview.mousedown=false;$('#events').bind('click',function(event){Calendar.fire('event-deselect',[]);});$('#events').bind('dblclick',function(event){if(!Weekview.eventDragging){var start=Weekview.__get_hovered_date_from_mouse_event(event);start.setMinutes(start.getMinutes()-start.getMinutes()%15);var duration;if(start.getHours()<23){duration=new DateInterval(0,0,0,1,0,0);}else if(start.getMinutes()>0){duration=new DateInterval(0,0,0,0,60-start.getMinutes(),0);}
if(duration){Calendar.create(ss.i18n._t('WeekView.NEW_EVENT'),start,duration);Weekview.__adjust();}}});$('#events').bind('mousedown',function(event){if(!Weekview.eventDragging){Weekview.mousedown=true;Weekview.mousedownDate=Weekview.__get_hovered_date_from_mouse_event(event);Weekview.mousedownDate.setMinutes(Weekview.mousedownDate.getMinutes()-Weekview.mousedownDate.getMinutes()%15);};});$('#events').bind('mousemove',function(event){if(Weekview.eventDragging){Weekview.mousedown=false;}else if(Weekview.mousedown){var date=Weekview.__get_hovered_date_from_mouse_event(event);if(date.onSameDateAs(Weekview.mousedownDate)){var duration=date.differenceTo(Weekview.mousedownDate);if(duration.toTime()>15*60*1000){var start=new Date(Math.min(date.getTime(),Weekview.mousedownDate.getTime()));Weekview.__event_dom_object_set_time(Weekview.previewEvent,start,duration);return;};};};Weekview.previewEvent.css('display','none');});$('#events').bind('mouseup',function(event){Weekview.previewEvent.css('display','none');Weekview.mousedown=false;var date=Weekview.__get_hovered_date_from_mouse_event(event);if(!Weekview.eventDragging&&Weekview.mousedownDate&&date.onSameDateAs(Weekview.mousedownDate)){var duration=date.differenceTo(Weekview.mousedownDate);if(duration.toTime()>900000){var start=new Date(Math.min(date.getTime(),Weekview.mousedownDate.getTime()));start.setMinutes(start.getMinutes()-start.getMinutes()%15);duration.minutes-=duration.minutes%15;Calendar.create(ss.i18n._t('WeekView.NEW_EVENT'),start,duration);Weekview.__adjust();};};Weekview.mousedownDate=false;Weekview.mousedown=false;});$('#events').bind('mouseleave',function(event){Weekview.previewEvent.css('display','none');Weekview.mousedown=false;});});})(jQuery);
;
(function($){Allday=DUI.Class.create({addOnDate:function(event,date,recurrence){var dom=$('<div class="event">'+'<div class="e_htop"></div>'+'<div class="e_hleft ui-resizable-handle ui-resizable-w"></div>'+'<div class="e_hright ui-resizable-handle ui-resizable-e"></div>'+'<dl>'+'<dt class="cat-color"/>'+'</dl>'+'<div class="e_hbottom"></div>'+'</div>');dom.find('dt').text(event.name);dom.attr('id',event.repeat?'evt_'+event.Id+'_'+recurrence.getTime():'evt_'+event.Id);if(event.categoryId)
dom.addClass('cat_'+event.categoryId);else
dom.addClass('cat_0');if(!event.editable)
dom.addClass('uneditable');dom.addClass('evt_'+event.Id);dom.addClass('cal_'+event.calendarId);dom.data('event',event);dom.data('start',date);dom.data('isBeingDragged',false);dom.css('display','none');dom.data('list',dom.find('dl'));dom.appendTo('#allday-events');this.__event_dom_object_set_time(dom,date,event.duration);dom.hide();dom.fadeIn();dom.bind('click',function(event){event.stopPropagation();if(dom.data('isBeingDragged')){dom.data('isBeingDragged',false);return;}
Calendar.fire('event-select',[dom.data('event'),dom,dom.data('start')]);});dom.bind('dblclick',function(event){event.stopPropagation();});dom.draggable({delay:100,handle:'dl',scroll:true,scrollSensitivity:60,scrollSpeed:20,zIndex:500,start:function(event,ui){dom.data('isBeingDragged',true);ui.helper.css({'left':ui.helper.position().left+'px','width':(ui.helper.width()/$('#allday-events').width()*100)+'%','right':null});ui.helper.stop(true,true);ui.helper.css('overflow','visible');},drag:function(event,ui){},stop:function(event,ui){var day=Math.round(ui.position.left/($('#allday-events').width()/7));var left=ui.position.left/$('#allday-events').width()*100;var right=(85.71428-left-((ui.helper.data('event').duration.days-1)*14.2857));var weekOffset=ui.helper.data('start').getWeek()-Calendar.getWeek().getWeek();ui.helper.stop(true,true);ui.helper.css({'left':left+'%','right':right+'%','width':null});if(day>=7)day=6;if(day<0&&-day>=ui.helper.data('event').duration.days)
day=-ui.helper.data('event').duration.days+1;ui.helper.data('start').setTime(ui.helper.data('start').getTime()+(new DateInterval('P1D').toTime()*(day-ui.helper.data('start').getDayStartingMonday()-(weekOffset*7))));Calendar.move(ui.helper.data('event'),ui.helper.data('start'),ui.helper.data('event').duration);Allday.__adjust();}});dom.resizable({handles:{e:'.e_hright',w:'.e_hleft'},start:function(event,ui){ui.helper.data('formerZIndex',ui.helper.css('zIndex'));ui.helper.css('zIndex',9001);ui.helper.css({'left':ui.helper.position().left+'px','width':(ui.helper.width()/$('#allday-events').width()*100)+'%','right':null});ui.helper.stop(true,true);ui.helper.css('overflow','visible');},stop:function(event,ui){ui.helper.css('zIndex',ui.helper.data('formerZIndex'));var day=Math.round(ui.position.left/($('#allday-events').width()/7));var endDay=Math.round((ui.position.left+ui.size.width-(($('#allday-events').width()/7)))/($('#allday-events').width()/7));var newDuration=endDay-day+1;ui.helper.data('event').duration.days=newDuration>1?newDuration:1;var left=ui.position.left/$('#allday-events').width()*100;var right=(85.71428-left-((ui.helper.data('event').duration.days-1)*14.2857));ui.helper.stop(true,true);ui.helper.css({'left':left+'%','right':right+'%','width':null});ui.helper.data('start').setDayStartingMonday(day);Calendar.move(ui.helper.data('event'),ui.helper.data('start'),ui.helper.data('event').duration);Allday.__adjust();}});if(!event.editable||event.locked||event.repeat){dom.draggable('disable');dom.resizable('disable');};dom.css('display','');},add:function(event){if(event.repeat){if(event.start>Calendar.getWeek().endOfWeek())
return;if(event.end!=null&&event.end<Calendar.getWeek().minus(event.duration))
return;var end=event.end==null?Calendar.getWeek().endOfWeek():event.end.getTime()<Calendar.getWeek().endOfWeek().getTime()?event.end:Calendar.getWeek().endOfWeek()
var it=new $.ical.repeat(event.repeat,event.start,end);it.skipTo(Calendar.getWeek().minus(event.duration));var date;while(date=it.next()){if(date.getTime()==Calendar.getWeek().minus(event.duration).getTime())
continue;this.addOnDate(event,date.clone(),date.clone());}}else if(event.start.getTime()>Calendar.getWeek().minus(event.duration).getTime()&&event.start.getTime()<Calendar.getWeek().endOfWeek().getTime()){this.addOnDate(event,event.start);}},clear:function(){},__compare_event_overlap:function(events,group,other,banned){var banned=banned||[];var start=other.data('start').getTime();var end=other.data('start').plus(other.data('event').duration).getTime();for(var d=0;d<events.length;d++){if(events[d]==other||banned.indexOf(events[d])!=-1)continue;var dStart=events[d].data('start').getTime();var dEnd=events[d].data('start').plus(events[d].data('event').duration).getTime();if(dStart>=start&&dStart<end||dStart<=start&&dEnd>start){banned.push(events[d]);};};var done=false;do{for(var d=0;d<events.length;d++){if(events[d]==other||banned.indexOf(events[d])!=-1)continue;var dStart=events[d].data('start').getTime();var dEnd=events[d].data('start').plus(events[d].data('event').duration).getTime();if(!(dStart>=start&&dStart<end||dStart<=start&&dEnd>start)){var temp=events[d];group.push(temp);events.splice(d,1);this.__compare_event_overlap(events,group,temp,banned);break;};};if(d>=events.length)
done=true;}while(!done);return true;},__adjust:function(){var groups=[];var events=$.map($.makeArray($('#allday-events .event:visible')),$);while(events.length!=0){var group=[events.pop()];this.__compare_event_overlap(events,group,group[0]);groups.push(group);};groups.sort(function(a,b){var aSum=0,bSum=0;for(var i=0;i<a.length;i++){aSum+=a[i].data('event').duration.toTime();};for(var i=0;i<b.length;i++){bSum+=b[i].data('event').duration.toTime();};return bSum-aSum;});var top=3;for(var g=0;g<groups.length;g++){var group=groups[g];for(var i=0;i<group.length;i++){var weekOffset=group[i].data('start').getWeek()-Calendar.getWeek().getWeek();var top=((parseInt(group[i].height())+4)*g)+3;var left=(group[i].data('start').getDayStartingMonday()*14.2857)-(-weekOffset*100);var right=(85.71428-left-((group[i].data('event').duration.days-1)*14.2857));group[i].css('z-index',50+i);group[i].css({'top':top+'px','left':(left+0.1)+'%','right':(right+0.2)+'%'});var labelTextIndent=weekOffset>=0?0:((100/group[i].data('event').duration.days)*((-weekOffset*7)-group[i].data('start').getDayStartingMonday()));if(labelTextIndent>0||parseInt(group[i].find('dl dt').css('paddingLeft'))>0){group[i].find('dl dt').animate({'paddingLeft':(labelTextIndent)+'%'},{'easing':'easeOutQuad','duration':500});};};};$('.headers').stop().animate({'height':(top+18+17)+'px'});$('#weekview').stop().animate({'top':(top+18+17+3)+'px'});},__event_dom_object_set_time:function(object,date,duration){var left=date.getDayStartingMonday()*14.2857;var right=(85.71428-left-((duration.days-1)*14.2857));object.css({'display':'block','top':Math.floor(date.getHours()*48+date.getMinutes()*0.8)+'px','left':left+'%','right':right+'%'});}},true);$(function(){$('#allday-events').dblclick(function(event){var day=Math.floor((event.pageX-$('#allday-events').offset().left)/$('#allday-events').width()*7);var start=Calendar.getWeek();start.setDayStartingMonday(day);Calendar.create(ss.i18n._t('WeekView.NEW_EVENT'),start,new DateInterval('P1D'));});});Calendar.listen('event-remove',function(event,instanceOnly,recurrence){if(event.repeat&&instanceOnly){$('#evt_'+event.Id+'_'+recurrence.getTime()).remove();}else{$('#evt_'+event.Id).remove();}});Calendar.listen(['event-lock','event-unlock'],function(event,locked,instanceOnly,recurrence){var elem=$('#evt_'+event.Id+(event.repeat&&instanceOnly?'_'+recurrence.getTime():''));var op=locked?'dis':'en';elem.draggable(op+'able');elem.resizable(op+'able');});})(jQuery);
;
(function($){var closeAll;function showEditBox(view,event)
{view.dom().replaceWith($.form().add([ss.i18n._t('Editbox.START'),ss.i18n._t('Editbox.END'),ss.i18n._t('Editbox.ALLDAY')],{'name':['start','duration','all-day'],'type':'date-range','start':event.start,'duration':event.duration,'hasTime':!Calendar.isAllday(event)}).add(ss.i18n._t('Editbox.NAME'),{'name':'name','id':'nameField','type':'text','value':event.name}).add(ss.i18n._t('Editbox.CATEGORY'),{'name':'categoryId','type':'select','default':event.categoryId||0,'options':Categories.categories}).add(ss.i18n._t('Editbox.REPEAT'),{'name':'repeat','type':'text-parse','format':$.ruleToText,'parse':$.textToRule,'edit':function(rule){if(!rule)
return ss.i18n._t('LangRepeat.EVERY')+' ';return $.ruleToText(rule);},'value':event.repeat||null}).add('Tip',$(ss.i18n._t('LangRepeat.TEMPTIP'))).add(ss.i18n._t('Editbox.LOCATION'),{'name':'location','type':'text','value':event.location||''}).add(ss.i18n._t('Editbox.URL'),{'name':'url','type':'text','value':event.url||'','test':function(){return/^https?:\/\/.*$/.test(this);}}).add(ss.i18n._t('Editbox.DESCRIPTION'),{'name':'description','type':'text-area','rows':3,'value':event.description||''}).add([{'type':'submit','enter':true,'use-require-icon':true,'require':['name'],'class':'small','value':ss.i18n._t('Editbox.DONE'),'action':function(form,fields){var changes={};if(event.categoryId!=fields.categoryId)
changes.categoryId=parseInt(fields.categoryId);$.each(['name','location','description','url'],function(){if(event[this]||''!=fields[this])
changes[this]=fields[this];});if(event.start.getTime()!=fields.start.getTime())
changes.start=fields.start;if(event.duration.toTime()!=fields.duration.toTime()){changes.duration=fields.duration;}
if($.ical.text(event.repeat)!=$.ical.text(fields.repeat))
changes.repeat=fields.repeat;Calendar.edit(event,changes);Calendar.fire('event-deselect',[fields.event]);closeAll();}},{'type':'button','use-require-icon':true,'require':['name'],'class':'small','value':ss.i18n._t('Editbox.DELETE'),'action':function(){$.form(ss.i18n._t('Editbox.DELETE_EVENT')).set('event',event).text(ss.i18n._t('Editbox.DO_YOU_WANT_TO_DELETE_THE_EVENT_NAMED')+' '+event.name+'?').add([{'type':'button','value':ss.i18n._t('Editbox.DELETE'),'enter':true,'action':function(form,fields){Calendar.fire('event-deselect',[fields.event]);Calendar.remove(fields.event);form.close();}},{type:'cancel',value:ss.i18n._t('Editbox.CANCEL')}]).open({modal:true,center:[.5,150]});}}]).dom());$('#nameField').focus();}
Calendar.listen(['week-change','event-move-start','event-remove'],closeAll=function(){$('.editbox').each(function(){$(this).data('close')()});});Calendar.listen('event-select',function(event,dom,recurrence,editimmediately){closeAll();if(!Calendar.isAllday(event)&&($('#weekview').scrollTop()/48>event.start.getHours()+event.duration.hours/2||$('#weekview').scrollTop()/48+$('#weekview').height()/48<event.start.getHours()+event.duration.hours))
$('#weekview').scrollTop(48*event.start.getHours());var view=$.form().add(ss.i18n._t('Editbox.START'),event.start.toString(Calendar.isAllday(event)?'dd/MM/yyyy':'dd/MM/yyyy HH:mm')).add(ss.i18n._t('Editbox.END'),(Calendar.isAllday(event)?event.start.plus(event.duration).minus('P1D'):event.start.plus(event.duration)).toString(Calendar.isAllday(event)?'dd/MM/yyyy':'dd/MM/yyyy HH:mm')).add(ss.i18n._t('Editbox.NAME'),event.name.length>80?event.name.substr(0,80)+'...':event.name).add(ss.i18n._t('Editbox.CATEGORY'),Categories.find(event.categoryId).name).add(ss.i18n._t('Editbox.REPEAT'),event.repeat?$.ruleToText(event.repeat):ss.i18n._t('Editbox.NEVER')).add(ss.i18n._t('Editbox.LOCATION'),event.location||'').add(ss.i18n._t('Editbox.URL'),event.url?$('<a/>').attr({'href':event.url,'target':'_blank'}).text(event.url):'').add(ss.i18n._t('Editbox.DESCRIPTION'),$('<div style="overflow: auto; width: 150px; height: 48px; display: block"/>').text(event.description||''));if(event.editable){view.add([{'type':'button','class':'small','value':ss.i18n._t('Editbox.EDIT'),'action':function(form){showEditBox(view,event)}}]);}else if(event.calendarId[0]=='location'){view.add([{'type':'button','class':'small','value':'Unsubscribe','action':function(form){$.form('Unsubscribe from Event').set('event',event).text('Do you want to unsubscribe from the event named '+event.name+'?').add([{'type':'button','value':'Unsubscribe','enter':true,'action':function(form,fields){Calendar.fire('event-deselect',[fields.event]);Calendar.remove(fields.event);form.close();}},{type:'cancel',value:ss.i18n._t('Editbox.CANCEL')}]).open({modal:true,center:[.5,150]});}}]);}
view.dom().css({'width':240});view.open({'class':'editbox',alignment:($(dom).offset().left+$(dom).width()+300<=$(window).width())?'left':'right',sideOffset:0.5-
($(dom).offset().top+$(dom).height()/2<250?.3:($(window).height()-$(dom).offset().top)+$(dom).height()/2<350?-.35:0),margin:[40,260,60,40],clickOutsideCloses:true,link:dom});if(editimmediately&&event.editable)
{showEditBox(view,event);}});})(jQuery);
;
Calendar.listen('event-remove',function(event,instanceOnly,recurrence){Weekview.__adjust();Allday.__adjust();});Calendar.listen('event-select',function(event,dom,recurrence){$('#calendar .event').removeClass('selected');dom.addClass('selected');});Calendar.listen('event-deselect',function(){$('#calendar .event').removeClass('selected');});Calendar.listen(['event-lock','event-unlock'],function(event,locked,instanceOnly,recurrence){var doms;if(instanceOnly){doms=$('#evt_'+event.Id+'_'+recurrence.getTime());}else{doms=$('.evt_'+event.Id);}
doms.draggable(locked?'disable':'enable');doms.resizable(locked?'disable':'enable');if(locked){doms.addClass('locked');}else{doms.removeClass('locked');}});var evt_add_sgl=function(){if(this.start.getHours()==0&&this.start.getMinutes()==0&&this.start.getSeconds()==0&&this.duration.seconds==0&&this.duration.minutes==0&&this.duration.hours%24==0){Allday.add(this);Allday.__adjust();}else{Weekview.add(this);}}
Calendar.listen(['week-change','load','shared-load','shared-removed'],function(events){$('#calendar .event:not(.ghost)').remove();Calendar.$inRange(Weekview,Allday,Calendar.getWeek(),new DateInterval('P7D'));Allday.__adjust();Weekview.__adjust(false);});Calendar.listen('event-add',function(event){evt_add_sgl.apply(event);if(event.categoryId==0){var home=Categories.find(0);if(!home.visible)
Categories.toggle(home,true);}});Calendar.listen('event-id-update',function(oldId,newId){$('#evt_'+oldId).attr('id','evt_'+newId);$('#evt_'+newId).removeClass('evt_'+oldId);$('#evt_'+newId).addClass('evt_'+newId);});Calendar.listen('event-remove',function(event,instanceOnly,recurrence){if(event.repeat&&instanceOnly){$('#evt_'+event.Id+'_'+recurrence.getTime()).remove();}else{$('.evt_'+event.Id).remove();}});Calendar.listen('event-edit',function(event,changes){$('.evt_'+event.Id).remove();evt_add_sgl.apply(event);Allday.__adjust();Weekview.__adjust();});SharedSubscriptions.listen(['shared-add'],function(sharesubscription){$.rule('.event.cat_'+sharesubscription.categoryId+' .cat-color {}').css({'background-color':sharesubscription.color});$.rule('.event.cat_'+sharesubscription.categoryId+'{ display:'+(sharesubscription.visible?'block':'none')+' !important; }');});SharedSubscriptions.listen(['item-show','item-hide'],function(item,shown){$.rule('.event.cat_'+item.categoryId).text('display:'+(shown?'block':'none')+' !important');if($.browser.msie)
$.rule('.event.cat_'+item.categoryId+'{ display:'+(shown?'block':'none')+' !important; }');Weekview.__adjust()
Allday.__adjust()});SharedSubscriptions.listen('load',function(subscriptions){$.each(subscriptions,function(){$.rule('.event.cat_'+this.categoryId+' .cat-color {}').css({'background-color':this.color});$.rule('.event.cat_'+this.categoryId+'{ display:'+(this.visible?'block':'none')+' !important; }');});});SharedSubscriptions.listen('shared-id-update',function(oldId,newId){$('#shared_'+oldId).attr('id','shared_'+newId);Calendar.loadShared(newId,new Date('Jan 1 1970 00:00:00 GMT'),new DateInterval('P75Y'));});SharedSubscriptions.listen('shared-remove',function(sharedSubscription){$('#shared_'+sharedSubscription.Id).hide('explode');Calendar.removeShared(sharedSubscription);Weekview.__adjust(false);Allday.__adjust();});Categories.listen(['item-show','item-hide'],function(item,shown){if(Categories.itemIsSubscription(item)){$.rule('.event.'+item.Id[0]+'_'+item.Id[1]).text('display:'+(shown?'block':'none')+' !important');if($.browser.msie)
$.rule('.event.'+item.Id[0]+'_'+item.Id[1]+'{ display:'+(shown?'block':'none')+' !important; }');}else{$.rule('.event.cat_'+item.Id).text('display:'+(shown?'block':'none')+' !important');if($.browser.msie)
$.rule('.event.cat_'+item.Id+'{ display:'+(shown?'block':'none')+' !important; }');}
Weekview.__adjust()
Allday.__adjust()});Categories.listen('category-remove',function(category){$('.cat_'+category.Id).each(function(){$(this).removeClass('cat_'+category.Id);$(this).addClass('cat_0');});});Categories.listen('load',function(categories,subscriptions){$.each(categories,function(){$.rule('.event.cat_'+this.Id+' .cat-color {}').css({'background-color':this.color});$.rule('.event.cat_'+this.Id+'{ display:'+(this.visible?'block':'none')+' !important; }');});$.rule('.event.cal_fb_attending{ display:block !important; }');$.rule('.event.cal_fb_unsure{ display:block !important; }');$.rule('.event.cal_fb_birthday{ display:block !important; }');$.each(subscriptions,function(){$.rule('.event.'+this.Id[0]+'_'+this.Id[1]+'{ display:'+(this.visible?'block':'none')+' !important; }');});});Categories.listen('category-edit',function(category){$.rule('.event.cat_'+category.Id+' .cat-color {}').css({'background-color':category.color});if(category.shared){$('#shared_cat_'+category.Id).addClass('shared');}else{$('#shared_cat_'+category.Id).removeClass('shared');}});Categories.listen('category-id-update',function(oldId,newId){$('.cat_'+oldId).addClass('cat_'+newId);$('.cat_'+newId).removeClass('cat_'+oldId);$.rule('.event.cat_'+newId+' .cat-color {}').css({'background-color':Categories.find(newId).color});$.rule('.event.cat_'+newId+'{ display:'+(Categories.find(newId).visible?'block':'none')+' !important; }');});
;
(function($){$(function(){$('.HasVHandle').each(function(){var el=$(this);var handle=$('<div class="Handle" />');handle.attr('title',ss.i18n._t('ui.SHOW'));handle.click(function(){if(el.is(':hidden')){handle.attr('title',ss.i18n._t('ui.HIDE'));}else{handle.attr('title',ss.i18n._t('ui.SHOW'));};el.slideToggle('slow');});el.after(handle);});});})(jQuery);
;
(function($){$(function(){$('.MyCalendar').each(function(){var el=$(this);var handle=$('<img class="myCalHandle" src="/themes/onecalendar/images/mycalendar_arrow.gif" />');handle.attr('title',ss.i18n._t('ui.SHOW'));handle.click(function(){var ul=$(this).find('~ul');if(ul.is(':hidden')){$(this).attr({title:ss.i18n._t('ui.HIDE'),src:'/themes/onecalendar/images/mycalendar_arrow_down.gif'});}else{$(this).attr({title:ss.i18n._t('ui.SHOW'),src:'/themes/onecalendar/images/mycalendar_arrow.gif'});}
if($.browser.msie)
ul.toggle();else
ul.slideToggle('fast');});el.find('ul').hide();el.prepend(handle);handle.click();});});SharedSubscriptions.listen('load',function(sharedSubscriptions){$('#mycals_shared').empty();$.each(sharedSubscriptions,function(i,subscription){var anchor=this;var li=$('<li class="mycals_items" />').attr('id','shared_'+this.Id);var check=$('<input type="checkbox" />').attr('checked',this.visible).click(function(){this.blur()}).change(function(){SharedSubscriptions.toggle(subscription,check.attr('checked'));}).appendTo(li);var text=$('<span style="cursor: pointer"/>').text(this.displayname).appendTo(li);$('<img class="icons" height="14px" width="14px" src="/themes/onecalendar/images/delete.png" style="cursor: pointer" />').attr('id','shared_sub_'+this.Id).click(function(){$.form('Really delete?').text('Are you sure you want to delete the shared subscription '+anchor.displayname+'?').add([{'type':'submit','value':ss.i18n._t('uil.DELETE'),'action':function(form,fields){SharedSubscriptions.remove(anchor)
form.close();}},{'type':'cancel','value':ss.i18n._t('uil.CANCEL')}]).open({modal:true,center:[.5,150]});}).appendTo(li);$('#mycals_shared').append(li);li.hide();li.show('slow');});});SharedSubscriptions.listen('shared-add',function(sharedSubscription){var li=$('<li class="mycals_items" />').data('sharedSubscription',sharedSubscription).attr('id','shared_'+sharedSubscription.Id);var check=$('<input type="checkbox" />').attr('checked',sharedSubscription.visible).click(function(){this.blur()}).change(function(){SharedSubscriptions.toggle(sharedSubscription,check.attr('checked'));}).appendTo(li);var text=$('<span style="cursor: pointer"/>').text(sharedSubscription.displayname).appendTo(li);$('<img class="icons" height="14px" width="14px" src="/themes/onecalendar/images/delete.png" style="cursor: pointer" />').attr('id','shared_sub_'+this.Id).click(function(){$.form('Really delete?').text('Are you sure you want to delete the shared subscription '+sharedSubscription.displayname+'?').add([{'type':'submit','value':ss.i18n._t('uil.DELETE'),'action':function(form,fields){SharedSubscriptions.remove(sharedSubscription)
form.close();}},{'type':'cancel','value':ss.i18n._t('uil.CANCEL')}]).open({modal:true,center:[.5,150]});}).appendTo(li);$('#mycals_shared').append(li);li.hide();li.show('slow');});Categories.listen('load',function(categories,subscriptions){$('#mycals_study').empty();$.each(subscriptions,function(i,subscription){var li=$('<li class="mycals_items" />').attr('id','sub_'+this.Id[0]+'_'+this.Id[1]);var check=$('<input type="checkbox" />').attr('checked',this.visible).click(function(){this.blur()}).change(function(){Categories.toggle(subscription,check.attr('checked'));}).appendTo(li);var text=$('<span style="cursor: pointer"/>').text(this.name).appendTo(li);$('#mycals_study').append(li);li.hide();li.show('slow');});$('#mycals_private').empty();$.each(categories,function(i,category){var li=$('<li class="mycals_items" />').attr('id','cat_'+this.Id).data('category',category);var check=$('<input type="checkbox" />').attr('checked',this.visible).click(function(){this.blur()}).change(function(){Categories.toggle(category,check.attr('checked'));}).appendTo(li);var text=$('<span style="cursor: pointer" class="editCategory" />').css('color',this.color).text(this.name).appendTo(li);var shared=$('<img class="noView icons" height="14px" width="14px" src="/themes/onecalendar/images/share.png" style="cursor: pointer" />').attr('id','shared_cat_'+this.Id).appendTo(li);if(this.shared=='1')shared.removeClass('noView');$('#mycals_private').append(li);li.hide();li.show('slow');});});Categories.listen('category-add',function(category){var li=$('<li class="mycals_items" />').data('category',category).attr('id','cat_'+category.Id);var check=$('<input type="checkbox" />').attr('checked',category.visible).click(function(){this.blur()}).change(function(){Categories.toggle(category,check.attr('checked'));}).appendTo(li);var text=$('<span style="cursor: pointer" class="editCategory" />').css('color',category.color).text(category.name).appendTo(li);var shared=$('<img class="icons noView" height="14px" width="14px" src="/themes/onecalendar/images/share.png" style="cursor: pointer" />').attr('id','shared_cat_'+category.Id).appendTo(li);if(category.shared=='1')shared.removeClass('noView');$('#mycals_private').append(li);li.hide();li.show('slow');});$('.editCategory:not(#cat_0 span)').live('click',function(){var category=$(this).parent().data('category');if(!category.locked){$.form(ss.i18n._t('mycalendars.js.EDIT_CATEGORY')).add(ss.i18n._t('uil.NAME'),{name:'name',type:'text',value:category.name}).add(ss.i18n._t('mycalendars.js.COLOR'),{name:'color',type:'color-picker',value:category.color,colors:['#f2b1b2','#fffbab','#cabbe8','#7c89a4','#d62430','#f06d15','#d8aa40','#c5c000','#44a639','#3cb08b','#869a55','#3365b4','#6648b0','#a44f79']}).add('Shared Calendar',{name:'shared',value:'1',type:'checkbox',checked:(category.shared==true)}).add([{type:'button',require:['name','color'],value:ss.i18n._t('uil.SAVE'),action:function(form,fields){Categories.edit(category,fields);form.close();}},{type:'button',value:'Delete',action:function(form){form.close();$.form('Really delete?').text('Are you sure you want to delete the category '+category.name+'?').add([{'type':'submit','value':ss.i18n._t('uil.DELETE'),'action':function(form,fields){Categories.remove(category);form.close();}},{'type':'cancel','value':ss.i18n._t('uil.CANCEL')}]).open({modal:true,center:[.5,150]});}},{type:'cancel',value:'Close'}]).open({link:$(this),alignment:'left'});}});Categories.listen('category-id-update',function(oldId,newId){$('#cat_'+oldId).attr('id','cat_'+newId);$('#shared_cat_'+oldId).attr('id','shared_cat_'+newId);});Categories.listen('category-edit',function(category,changes){var anchor=$('#cat_'+category.Id);var label=$('#cat_'+category.Id+' span');if(changes.color)
label.css('color',changes.color);if(changes.shared==true){$('.icons',anchor).removeClass('noView');}else{$('.icons',anchor).addClass('noView');}
if(changes.name)
label.text(changes.name);});Categories.listen('category-remove',function(category){$('#cat_'+category.Id).hide('explode');});Categories.listen(['item-lock','item-unlock'],function(item,locked){if(Categories.itemIsSubscription(item)){$('#sub_'+item.Id[0]+'_'+item.Id[1]+' input').attr('disabled',locked);}else{$('#cat_'+item.Id+' input').attr('disabled',locked);}});Categories.listen(['item-hide','item-show'],function(item,shown){if(Categories.itemIsSubscription(item)){$('#sub_'+item.Id[0]+'_'+item.Id[1]+' input').attr('checked',shown);}else{$('#cat_'+item.Id+' input').attr('checked',shown);}});})(jQuery);
;
$(function(){function fbLoadUserEvents(uid){var subQuery='SELECT eid FROM event_member WHERE uid = '+uid+' AND rsvp_status = "attending"';var query='SELECT eid, name, host, start_time, end_time FROM event WHERE eid IN ('+subQuery+')';var tzo=new Date().getTimezoneOffset()*60;FB.Facebook.apiClient.fql_query(query,function(result){$.each(result,function(index,event){var start=new Date((event.start_time-25200+tzo)*1000);var duration=start.differenceTo(new Date((event.end_time-25200+tzo)*1000));var event;if(!start.onSameDateAs(new Date((event.end_time-25200+tzo)*1000))){start.clearTime();duration=start.differenceTo(new Date((event.end_time-25200+tzo)*1000).clearTime());duration.days++;}
Calendar.events.push(event={'Id':100000000000+parseInt(event.eid),'locked':false,'editable':false,'calendarId':'fb_attending','categoryId':0,'start':start,'end':null,'overrides':[],'duration':duration||new DateInterval('P1D'),'repeat':null,'name':event.name,'description':event.host?'Host: '+event.host:null,'location':null,'url':null,'thumb':null});});Calendar.fire('load',[Calendar.events]);$('#fb_attending').show('slow');});var subQuery='SELECT eid FROM event_member WHERE uid = '+uid+' AND rsvp_status = "unsure"';var query='SELECT eid, name, host, start_time, end_time FROM event WHERE eid IN ('+subQuery+')';FB.Facebook.apiClient.fql_query(query,function(result){$.each(result,function(index,event){var start=new Date((event.start_time-25200+tzo)*1000);var duration=start.differenceTo(new Date((event.end_time-25200+tzo)*1000));var event;if(!start.onSameDateAs(new Date((event.end_time-25200+tzo)*1000))){start.clearTime();duration=start.differenceTo(new Date((event.end_time-25200+tzo)*1000).clearTime());duration.days++;}
Calendar.events.push(event={'Id':100000000000+parseInt(event.eid),'locked':false,'editable':false,'calendarId':'fb_unsure','categoryId':0,'start':start,'end':null,'overrides':[],'duration':duration||new DateInterval('P1D'),'repeat':null,'name':event.name,'description':event.host?'Host: '+event.host:null,'location':null,'url':null,'thumb':null});});Calendar.fire('load',[Calendar.events]);$('#fb_unsure').show('slow');});var subQuery='SELECT uid2 FROM friend WHERE uid1 = '+uid;var query='SELECT uid, first_name, last_name, birthday_date FROM user WHERE uid IN ('+subQuery+') AND birthday_date != ""';FB.Facebook.apiClient.fql_query(query,function(result){$.each(result,function(index,user){var matches=user.birthday_date.match(/(\d{2})\/(\d{2})(\/(\d{4}))?/);var start=new Date(matches[4]||1970,matches[1]-1,matches[2]);var duration=new DateInterval('P1D');var event;Calendar.events.push(event={'Id':200000000000+parseInt(user.uid),'locked':false,'editable':false,'calendarId':'fb_birthday','categoryId':0,'start':start,'end':null,'overrides':[],'duration':duration||new DateInterval('P1D'),'repeat':$.ical.rule('FREQ=YEARLY'),'name':user.first_name+' '+user.last_name+'\'s birthday','description':null,'location':null,'url':null,'thumb':null});});Calendar.fire('load',[Calendar.events]);$('#fb_birthday').show('slow');});$.each([{Id:'fb_attending',name:'Attending events',color:'#6fa4ff'},{Id:'fb_unsure',name:'Unsure events',color:'#d9e4ff'},{Id:'fb_birthday',name:'Birthdays',color:'#ff9f5b'}],function(){var self=this;var li=$('<li class="fb_items" />').attr('id',this.Id);var check=$('<input type="checkbox" />').attr('checked',true).change(function(){$.rule('.event.cal_'+self.Id).text('display:'+(check.attr('checked')?'block':'none')+' !important');Weekview.__adjust();Allday.__adjust();}).appendTo(li);var text=$('<span />').css('color',this.color).text(this.name).appendTo(li);$('#fbconnect_sections').append(li);li.hide();});}
var fbUserNeedsToPressFBConnectButton=false;try{FB_RequireFeatures(['XFBML'],function(){FB.init('53ab405205d721f5fdf07aa6768eb0aa','/calendar/receiver',{doNotUseCachedConnectState:true,ifUserConnected:function(uid){if(fbUserNeedsToPressFBConnectButton){$('#fbconnect-login-button').fadeOut('slow');fbLoadUserEvents(uid);}else{$('<button class="small" style="margin-left:auto;margin-right:auto; display: block" />').text('Sync with Facebook').click(function(){$(this).fadeOut('slow');fbLoadUserEvents(uid);}).insertAfter('#fbconnect-login-button');}},ifUserNotConnected:function(){fbUserNeedsToPressFBConnectButton=true;FB.XFBML.Host.addElement(new FB.XFBML.LoginButton($('#fbconnect-login-button')[0]));}});FB.XFBML.Host.autoParseDomTree=false;});}catch(e){$('#fbconnect-login-button').parent().remove();}});
;
(function($){var MyagendaWidget=DUI.Class.create({__date:null,init:function(element){this.element=element;this.element.find('.navigation.prev').click(function(){this.__changeWeek(-1);}.bind(this));this.element.find('.navigation.next').click(function(){this.__changeWeek(+1);}.bind(this));this.setDate(Date.today());Calendar.listen('event-add',function(event){this.__update();}.bind(this));Calendar.listen('event-edit',function(event,changes){this.__update();}.bind(this));Calendar.listen('event-move',function(event,changes){this.__update();}.bind(this));Calendar.listen('event-remove',function(event,instanceOnly,recurrance){this.element.find('tr').each(function(index,elem){var elem=$(elem);if(elem.data('eventId')==event.Id)
elem.fadeOut('slow',function(){$(this).remove();});});}.bind(this));},setDate:function(date){this.__date=date;this.__update();},getDate:function(){return this.__date;},__changeWeek:function(offset){var date=this.getDate().clone();date.setMonth(date.getMonth()+offset);this.setDate(date);return date;},__update:function(){this.__events=$.grep($.unique(Calendar.events),function(event){return event.start.getMonth()==this.__date.getMonth()&&event.start.getFullYear()==this.__date.getFullYear();}.bind(this)).sort(function(a,b){return a.start.getTime()-b.start.getTime();});this.element.find('.header h1').text(this.__date.toString('MMMM yyyy').toTitleCase());this.element.children(':not(.header)').remove();var weekElem=$();var dateElem=$();var eventsElem=$();var containerElem=$('<div class="wrapper"/>').appendTo(this.element);$.each(this.__events,function(index,event){if(!event||this.__isEventAllday(event))
return;var start=event.start;var week=start.getWeek();var date=start.getDate();if(weekElem.data('week')!=week){weekElem=$('<div class="week"><h2>Uge '+week+'</h2></div>');weekElem.data('week',week);weekElem.appendTo(containerElem);};if(dateElem.data('date')!=date){dateElem=$('<div class="day"><h3>'+start.toString('dddd').toTitleCase()+'<span class="date">'+start.format('%d/%m/%Y')+'</span></h3></div>')
dateElem.data('date',date);dateElem.appendTo(weekElem);eventsElem=$('<table class="events"/>').appendTo(dateElem);};var rowElem=$('<tr/>').data('eventId',event.Id).appendTo(eventsElem);var formattedTime=this.__isEventAllday(event)?ss.i18n._t('MyAgendaWidget.ALLDAY'):start.format('%H:%M');$('<th class="time">'+formattedTime+'</th>').appendTo(rowElem);$('<td class="name">'+event.name+'</td>').appendTo(rowElem);}.bind(this));},__isEventAllday:function(event){return(event.start.getHours()==0&&event.start.getMinutes()==0&&event.start.getSeconds()==0&&event.duration.seconds==0&&event.duration.minutes==0&&event.duration.hours%24==0);}});$(function(){Calendar.listen('load',function(){$('.MyagendaWidget').each(function(index,elem){new MyagendaWidget($(elem));});});});})(jQuery);
;