var cookieList = function(cookieName) {
  var cookie = $.cookie(cookieName);
  var items = cookie ? cookie.split(/,/) : new Array();


  return {
    "add": function(val) {
      //Add to the items.
      items.push(val);
      //Save the items to a cookie.
      $.cookie(cookieName, items);
    },
    "remove": function(val) {
      match = $.inArray(val, items);
      if(match > -1){
        items.splice(match, 1);
        $.cookie(cookieName, items);
      }
    },
    "clear": function() {
      //clear the cookie.
      items = new Array();
      $.cookie(cookieName, items);
    },
    "items": function() {
      //Get all the items.
      return items;
    }
  }
}

$(document).ready(function(){
  var list = new cookieList('lolwandsCookie');

  $.each(list.items(), function(k, v){
    $('#' + v).addClass('clickedEntry');
  });


  $('.timetableEntry').click(function() {
    // Cookie
    if($(this).hasClass('clickedEntry')){
      // remove from cookie
      list.remove($(this).attr('id'));
    }
    else {
      // add to cookie
      list.add($(this).attr('id'));
    }
    $(this).toggleClass('clickedEntry', 500);
  });


  $('#clearSelection').click(function() {
    list.clear();
    $('.timetableEntry').removeClass('clickedEntry');
    return false;
  });


});
