(function(z){var x="icalendar";var u="icalendar-flash-copy";function a(){this._defaults={sites:[],icons:"icalendar.png",iconSize:16,target:"_blank",compact:false,popup:false,popupText:"Send to my calendar...",tipPrefix:"",echoUrl:"",echoField:"",start:null,end:null,title:"",summary:"",description:"",location:"",url:"",contact:"",recurrence:null,copyConfirm:"The event will be copied to your clipboard. Continue?",copySucceeded:"The event has been copied to your clipboard",copyFailed:"Failed to copy the event to the clipboard\n",copyFlash:"clipboard.swf",copyUnavailable:"The clipboard is unavailable, please copy the event details from below:\n"};this._sites={google:{display:"Google",icon:0,override:null,url:"http://www.google.com/calendar/event?action=TEMPLATE&amp;text={t}&amp;dates={s}/{e}&amp;details={d}&amp;location={l}&amp;sprop=website:{u}"},icalendar:{display:"iCalendar",icon:1,override:null,url:"echo"},outlook:{display:"Outlook",icon:2,override:null,url:"echo"},yahoo:{display:"Yahoo",icon:3,override:i,url:"http://calendar.yahoo.com/?v=60&amp;view=d&amp;type=20&amp;title={t}&amp;st={s}&amp;dur={p}&amp;desc={d}&amp;in_loc={l}&amp;url={u}&amp;rpat={r}"}}}var w=[{method:"Seconds",factor:1},{method:"Minutes",factor:60},{method:"Hours",factor:3600},{method:"Date",factor:86400},{method:"Month",factor:1},{method:"FullYear",factor:12},{method:"Date",factor:604800}];var j=0;var e=1;var B=2;var I=3;var b=4;var d=5;var H=6;z.extend(a.prototype,{markerClassName:"hasICalendar",setDefaults:function(K){E(this._defaults,K||{});return this},addSite:function(O,N,M,K,L){this._sites[O]={display:N,icon:M,override:L,url:K};return this},getSites:function(){return this._sites},_attachICalendar:function(L,K){L=z(L);if(L.hasClass(this.markerClassName)){return}L.addClass(this.markerClassName);this._updateICalendar(L,K)},_changeICalendar:function(L,K){L=z(L);if(!L.hasClass(this.markerClassName)){return}this._updateICalendar(L,K)},_updateICalendar:function(P,L){L=E(z.extend({},this._defaults,z.data(P[0],x)||{}),L);z.data(P[0],x,L);var O=L.sites||this._defaults.sites;if(O.length==0){z.each(this._sites,function(Q){O[O.length]=Q})}var M=function(S,V){var U={t:encodeURIComponent(L.title),d:encodeURIComponent(L.description),s:z.icalendar.formatDateTime(L.start),e:z.icalendar.formatDateTime(L.end),p:z.icalendar.calculateDuration(L.start,L.end),l:encodeURIComponent(L.location),u:encodeURIComponent(L.url),c:encodeURIComponent(L.contact),r:l(L.recurrence)};if(S.override){S.override.apply(P,[U,L])}var R=S.url;z.each(U,function(Z,X){var Y=new RegExp("\\{"+Z+"\\}","g");R=R.replace(Y,X)});var R=(S.url=="echo"?"#":R);var W=z("<li></li>");var Q=z('<a href="'+R+'" title="'+L.tipPrefix+S.display+'"'+(S.url=="echo"?"":' target="'+L._target+'"')+"></a>");if(S.url=="echo"){Q.click(function(){return z.icalendar._echo(P[0],V)})}var T="";if(S.icon!=null){if(typeof S.icon=="number"){T+='<span style="background: transparent url('+L.icons+") no-repeat -"+(S.icon*L.iconSize)+"px 0px;"+(z.browser.mozilla&&z.browser.version<"1.9"?" padding-left: "+L.iconSize+"px; padding-bottom: "+Math.max(0,(L.iconSize/2)-5)+"px;":"")+'"></span>'}else{T+='<img src="'+S.icon+'"'+((z.browser.mozilla&&z.browser.version<"1.9")||(z.browser.msie&&z.browser.version<"7.0")?' style="vertical-align: bottom;"':(z.browser.msie?' style="vertical-align: middle;"':(z.browser.opera||z.browser.safari?' style="vertical-align: baseline;"':"")))+"/>"}T+=(L.compact?"":"&#xa0;")}Q.html(T+(L.compact?"":S.display));W.append(Q);return W};var N=z('<ul class="icalendar_list'+(L.compact?" icalendar_compact":"")+'"></ul>');var K=this._sites;z.each(O,function(Q,R){N.append(M(K[R],R))});P.empty().append(N);if(L.popup){N.before('<span class="icalendar_popup_text">'+L.popupText+"</span>").wrap('<div class="icalendar_popup"></div>');P.click(function(){var Q=z(this);var R=Q.offset();z(".icalendar_popup",Q).css("left",R.left).css("top",R.top+Q.outerHeight()).toggle()})}},_destroyICalendar:function(K){K=z(K);if(!K.hasClass(this.markerClassName)){return}K.removeClass(this.markerClassName).empty();z.removeData(K[0],x)},_echo:function(O,L){var M=z.data(O,x);var N=D(M);if(M.echoUrl){window.location.href=M.echoUrl+"?content="+escape(N)}else{if(M.echoField){z(M.echoField).val(N)}else{if(!M.copyFlash){alert(M.copyUnavailable+N)}else{if(confirm(M.copyConfirm)){var K="";if(K=J(N,M.copyFlash)){alert(M.copyFailed+K)}else{alert(M.copySucceeded)}}}}}return false},_ensureTwo:function(K){return(K<10?"0":"")+K},formatDate:function(K,L){return(!K?"":""+K.getFullYear()+this._ensureTwo(K.getMonth()+1)+this._ensureTwo(K.getDate()))},formatDateTime:function(L,K){return(!L?"":(K?""+L.getFullYear()+this._ensureTwo(L.getMonth()+1)+this._ensureTwo(L.getDate())+"T"+this._ensureTwo(L.getHours())+this._ensureTwo(L.getMinutes())+this._ensureTwo(L.getSeconds()):""+L.getUTCFullYear()+this._ensureTwo(L.getUTCMonth()+1)+this._ensureTwo(L.getUTCDate())+"T"+this._ensureTwo(L.getUTCHours())+this._ensureTwo(L.getUTCMinutes())+this._ensureTwo(L.getUTCSeconds())+"Z"))},calculateDuration:function(P,L){if(!P||!L){return""}var N=Math.abs(L.getTime()-P.getTime())/1000;var O=Math.floor(N/86400);N-=O*86400;var K=Math.floor(N/3600);N-=K*3600;var M=Math.floor(N/60);N-=M*60;return(P.getTime()>L.getTime()?"-":"")+"P"+(O>0?O+"D":"")+(K||M||N?"T"+K+"H":"")+(M||N?M+"M":"")+(N?N+"S":"")},addDuration:function(P,O){if(!O){return P}var L=new Date(P.getTime());var N=t.exec(O);if(!N){throw"Invalid duration"}if(N[2]&&(N[3]||N[5]||N[6]||N[7])){throw"Invalid duration - week must be on its own"}if(!N[4]&&(N[5]||N[6]||N[7])){throw"Invalid duration - missing time marker"}var K=(N[1]=="-"?-1:+1);var M=function(R,Q,S){R=parseInt(R);if(!isNaN(R)){L["setUTC"+S](L["getUTC"+S]()+K*R*Q)}};if(N[2]){M(N[2],7,"Date")}else{M(N[3],1,"Date");M(N[5],1,"Hours");M(N[6],1,"Minutes");M(N[7],1,"Seconds")}return L},parse:function(M){var N={};var L={};var K=n(M);c(K,0,N,L);if(!N.vcalendar){throw"Invalid iCalendar data"}return N.vcalendar},getWeekOfYear:function(L,K){return p(L,K)},_parseParams:function(K,L){return r(K,L)}});function E(M,L){z.extend(M,L);for(var K in L){if(L[K]==null){M[K]=null}}return M}z.fn.icalendar=function(L){var K=Array.prototype.slice.call(arguments,1);return this.each(function(){if(typeof L=="string"){z.icalendar["_"+L+"ICalendar"].apply(z.icalendar,[this].concat(K))}else{z.icalendar._attachICalendar(this,L||{})}})};z.icalendar=new a();function i(L,N){var O=function(Q){return(Q<10?"0":"")+Q};var M=(N.end?(N.end.getTime()-N.start.getTime())/60000:0);L.p=(M?O(Math.floor(M/60))+""+O(M%60):"");if(L.r){var K=(N.recurrence.by&&N.recurrence.by[0].type=="day"?N.recurrence.by[0].values.join("").toLowerCase():"");var P={daily:"dy",weekly:"wk",monthly:"mh",yearly:"yr"}[N.recurrence.freq];L.r=(K||P?O(N.recurrence.interval||1)+(K||P):"")}}function D(L){var K=function(N){var M="";while(N.length>75){M+=N.substr(0,75)+"\n";N=" "+N.substr(75)}M+=N;return M};return"BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:jquery.icalendar\nMETHOD:PUBLISH\nBEGIN:VEVENT\nUID:"+new Date().getTime()+"@"+(window.location.href.replace(/^[^\/]*\/\/([^\/]*)\/.*$/,"$1")||"localhost")+"\nDTSTAMP:"+z.icalendar.formatDateTime(new Date())+"\n"+(L.url?K("URL:"+L.url)+"\n":"")+(L.contact?K("MAILTO:"+L.contact)+"\n":"")+K("TITLE:"+L.title)+"\nDTSTART:"+z.icalendar.formatDateTime(L.start)+"\nDTEND:"+z.icalendar.formatDateTime(L.end)+"\n"+(L.summary?K("SUMMARY:"+L.summary)+"\n":"")+(L.description?K("DESCRIPTION:"+L.description)+"\n":"")+(L.location?K("LOCATION:"+L.location)+"\n":"")+(L.recurrence?l(L.recurrence)+"\n":"")+"END:VEVENT\nEND:VCALENDAR"}function l(L){if(!L){return""}var M="";if(L.dates){M="RDATE;VALUE=DATE:";if(!s(L.dates)){L.dates=[L.dates]}for(var K=0;K<L.dates.length;K++){M+=(K>0?",":"")+z.icalendar.formatDate(L.dates[K])}}else{if(L.times){M="RDATE;VALUE=DATE-TIME:";if(!s(L.times)){L.times=[L.times]}for(var K=0;K<L.times.length;K++){M+=(K>0?",":"")+z.icalendar.formatDateTime(L.times[K])}}else{if(L.periods){M="RDATE;VALUE=PERIOD:";if(!s(L.periods[0])){L.periods=[L.periods]}for(var K=0;K<L.periods.length;K++){M+=(K>0?",":"")+z.icalendar.formatDateTime(L.periods[K][0])+"/"+(L.periods[K][1].constructor!=Date?L.periods[K][1]:z.icalendar.formatDateTime(L.periods[K][1]))}}else{M="RRULE:FREQ="+(L.freq||"daily").toUpperCase()+(L.interval?";INTERVAL="+L.interval:"")+(L.until?";UNTIL="+z.icalendar.formatDateTime(L.until):(L.count?";COUNT="+L.count:""))+(L.weekStart!=null?";WKST="+["SU","MO","TU","WE","TH","FR","SA"][L.weekStart]:"");if(L.by){if(!s(L.by)){L.by=[L.by]}for(var K=0;K<L.by.length;K++){if(!s(L.by[K].values)){L.by[K].values=[L.by[K].values]}M+=";BY"+L.by[K].type.toUpperCase()+"="+L.by[K].values.join(",")}}}}}return M}function J(M,K){z("#"+u).remove();try{z("body").append('<div id="'+u+'"><embed src="'+K+'" FlashVars="clipboard='+encodeURIComponent(M)+'" width="0" height="0" type="application/x-shockwave-flash"></embed></div>');return""}catch(L){return L}}var v=/^\s(.*)$/;var C=/^([^:]+):(.*)$/;var y=/^(\d{4})(\d\d)(\d\d)$/;var g=/^(\d{4})(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)(Z?)$/;var A=/^(\d{4})(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)(Z?)\/(\d{4})(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)(Z?)$/;var q=/^([+-])(\d\d)(\d\d)$/;var t=/^([+-])?P(\d+W)?(\d+D)?(T)?(\d+H)?(\d+M)?(\d+S)?$/;var m=["class"];function n(M){var K=M.replace(/\r\n/g,"\n").split("\n");for(var L=K.length-1;L>0;L--){var N=v.exec(K[L]);if(N){K[L-1]+=N[1];K[L]=""}}return z.map(K,function(O,P){return(O?O:null)})}function c(S,O,L,P){if(O>=S.length||S[O].indexOf("BEGIN:")!=0){throw"Missing group start"}var R={};var K=S[O].substr(6);G(L,K.toLowerCase(),R);O++;while(O<S.length&&S[O].indexOf("END:")!=0){if(S[O].indexOf("BEGIN:")==0){O=c(S,O,R,P)}else{var Q=k(S[O]);G(R,Q._name,(Q._simple?Q._value:Q))}O++}if(K=="VTIMEZONE"){var M=q.exec(R.standard.tzoffsetto);if(M){P[R.tzid]=(M[1]=="-"?-1:+1)*(parseInt(M[2],10)*60+parseInt(M[3],10))}}else{for(var N in R){o(R[N],P)}}if(S[O]!="END:"+K){throw"Missing group end "+K}return O}function o(N,M){if(!N){return}if(N.tzid&&N._value){var O=M[N.tzid];var K=function(P,Q){P.setMinutes(P.getMinutes()-O);P._type=Q};if(s(N._value)){for(var L=0;L<N._value.length;L++){K(N._value[L],N.tzid)}}else{if(N._value.start&&N._value.end){K(N._value.start,N.tzid);K(N._value.end,N.tzid)}else{K(N._value,N.tzid)}}}else{if(s(N)){for(var L=0;L<N.length;L++){o(N[L],M)}}}}function G(K,L,M){if(typeof M=="string"){M=M.replace(/\\n/g,"\n")}if(z.inArray(L,m)>-1){L+="_"}if(K[L]){if(!s(K[L])||K["_"+L+"IsArray"]){K[L]=[K[L]]}K[L][K[L].length]=M;if(K["_"+L+"IsArray"]){K["_"+L+"IsArray"]=undefined}}else{K[L]=M;if(s(M)){K["_"+L+"IsArray"]=true}}}function k(K){var L={};var M=C.exec(K);if(!M){throw"Missing entry name: "+K}var N=M[1].split(";");L._name=N[0].toLowerCase();L._value=h(M[2]);L._simple=true;r(L,N.slice(1));return L}function r(L,N){N=(s(N)?N:N.split(";"));L._simple=true;for(var M=0;M<N.length;M++){var K=N[M].split("=");L[K[0].toLowerCase()]=h(K[1]||"");L._simple=false}}function h(L){var K=g.exec(L);if(K){return f(K)}K=A.exec(L);if(K){return{start:f(K),end:f(K.slice(7))}}K=y.exec(L);if(K){return f(K.concat([0,0,0,""]))}return L}function f(L){var K=new Date(L[1],L[2]-1,L[3],L[4],L[5],L[6]);K._type=(L[7]?"UTC":"float");return F(K)}function F(K){K.setMinutes(K.getMinutes()-K.getTimezoneOffset());return K}function p(O,M){M=(M||M==0?M:1);var P=new Date(O.getFullYear(),O.getMonth(),O.getDate(),(O.getTimezoneOffset()/-60));var N=new Date(P.getFullYear(),1-1,4);var L=N.getDay();N.setDate(4+M-L-(M>L?7:0));if(P<N){P.setDate(P.getDate()-3);return p(P,M)}else{if(P>new Date(P.getFullYear(),12-1,28)){var K=new Date(P.getFullYear()+1,1-1,4);L=K.getDay();K.setDate(4+M-L-(M>L?7:0));if(P>=K){return 1}}}return Math.floor(((P-N)/(w[I].factor*1000))/7)+1}function s(K){return(K&&K.constructor==Array)}})(jQuery);