$(document).ready( function () {
  //handle CSS
  $('#calendar').fullCalendar('option', 'height', $('.nav-left')[0].offsetHeight);

  //setup models
  var Event = new function() {
    this.newPath = $("#newEventPath").html();
    this.createPath = $("#eventCreatePath").html();
    this.new = function(date){
      return $.ajax({
        method: 'GET',
        url: Event.newPath,
        data: {date: date}
      });
    };
    this.create = function(formData){
      return $.ajax({
        method: 'POST',
        url: Event.createPath,
        data: formData
      })
    };
    this.options = {allDay: true};
  };

  //setup controller
  $('#calendar').fullCalendar({
    events: jQuery.parseJSON($("#eventsJson").html()),
    eventRender: function (event, element) {
      currentTitle = element.find(".fc-event-title");
      var icon = ""
      switch (event.event_type) {
        case "Anniversary":
          icon = "<i class='fa fa-diamond'></i>";
          break;
        case "Birthday":
          icon = "<i class='fa fa-fast-forward'></i>";
          break;
        default :
          icon = "<i class='fa fa-thumbs-up'></i>";
      }
      currentTitle.html(icon + " " + currentTitle.html());
    },
    dayClick: function(date, jsEvent, view) {
      Event.new(date).done(function(data){
        $(".formDrop").html( data );
        $('#newEvent').modal('toggle');
        $(".formDrop form").submit( function(event){
          document.submitEvent();
          event.preventDefault();
        });
      });
    },
    eventClick: function(event, element) {
      event.title = "CLICKED!";

      $('#calendar').fullCalendar('updateEvent', event);
    }
  });

  this.submitEvent = function () {
    Event.create( $(".formDrop form").serialize()).done(function (data){
      if(data instanceof Object) {
        //success
        $('#newEvent').modal('toggle');
        $('#calendar').fullCalendar('renderEvent', jQuery.extend(data, Event.options));
      } else {
        //invalid
        $(".formDrop").html( data );
      }
    });
  };
});

@@ -152,19 +152,18 @@
 var 
-Event = new
+Calendar =
  fun
@@ -185,95 +185,495 @@
 his.
-newPath = $(%22#newEventPath%22).html();%0A    this.createPath = $(%22#eventCreatePath%22).html()
+events = function()%7B%0A      return jQuery.parseJSON($(%22#eventsJson%22).html()).map(function(obj)%7B%0A        return calendar.wrapEvent(obj);%0A      %7D);%0A    %7D;%0A    this.wrapEvent = function(event) %7B%0A      event.allDay = true;%0A      switch (event.event_type) %7B%0A        case %22Anniversary%22:%0A          event.color = %22red%22;%0A          break;%0A        case %22Birthday%22:%0A          event.color = %22black%22;%0A          break;%0A        default :%0A          event.color = %22green%22;%0A      %7D%0A      return event;%0A    %7D
 ;%0A  
@@ -682,16 +682,21 @@
 this.new
+Event
  = funct
@@ -768,21 +768,31 @@
 rl: 
+calendar.new
 Event
-.new
 Path
+()
 ,%0A  
@@ -842,22 +842,199 @@
    this.
-create
+newEventPath = function()%7B%0A      return $(%22#newEventPath%22).html();%0A    %7D;%0A    this.createEventPath = function()%7B%0A      return $(%22#eventCreatePath%22).html();%0A    %7D;%0A    this.createEvent
  = funct
@@ -1111,24 +1111,34 @@
 rl: 
-Event
+calendar
 .create
+Event
 Path
+()
 ,%0A  
@@ -1180,44 +1180,127 @@
 ;%0A  
-  this.options = %7BallDay: true%7D;%0A  %7D
+%7D;%0A  var Event = function() %7B%0A    this.createPath = $(%22#eventCreatePath%22).html();%0A  %7D;%0A%0A  var calendar = new Calendar()
 ;%0A%0A 
@@ -1367,48 +1367,24 @@
 ts: 
-jQuery.parseJSON($(%22#eventsJson%22).html()
+calendar.events(
 ),%0A 
@@ -1927,17 +1927,25 @@
     
+calendar.new
 Event
-.new
 (dat
@@ -2384,20 +2384,28 @@
     
-Event
+calendar
 .create
+Event
 ( $(
@@ -2450,20 +2450,21 @@
 nction (
-data
+event
 )%7B%0A     
@@ -2467,20 +2467,21 @@
      if(
-data
+event
  instanc
@@ -2544,32 +2544,58 @@
 odal('toggle');%0A
+        //add colors here%0A
         $('#cale
@@ -2633,41 +2633,32 @@
 t', 
-jQuery.extend(data, Event.options
+calendar.wrapEvent(event
 ));%0A
@@ -2711,36 +2711,37 @@
 ormDrop%22).html( 
-data
+event
  );%0A      %7D%0A    

Refactor calendar js class