B1.calendar_new = function() {
  return {
	  
	  page: function() {
	  B1.page();
	  $(function() {
		  B1.calendar_new.scroller();
		  //$('.calendar .cell .graying').show();
    	  /*$('.calendar .cell').hover(function () {
    		$('.graying', this).slideUp();
    	  }, function () {
    		  $('.graying', this).slideDown();
    	  });*/
	  });
  	},
  	
  	refresh: function () {
  	  //$('.calendar .cell .graying').show();
  	 /* $('.calendar .cell.last').hover(function () {
  		$('.graying', this).slideUp();
  	  }, function () {
  		  $('.graying', this).slideDown();
  	  });*/
  	},
	  
	  scroller: function(selector) {
  		var selector = selector || '.scroller .calendar';
  		$(selector).cycle({
  			fx: 'fade',
  			height: 180,
  			timeout:       0,
  			startingSlide: 0,
  			continuous:    0,
  			cleartype: 1,
  			next: '.scroller div.r a',
  			prev: '.scroller div.l a',
  			before: function (curr, next, opts, fwd) {
  				$('.cell .graying').hide();
  			},
  			after: function (curr, next, opts, fwd) {
  				$('.cell .graying').show();
  				
  				var f_id = $(next).children('div.cell:first').attr('id').substring(2);
				var l_id = $(next).children('div.cell:last').attr('id').substring(2);
				
				if (opts.currSlide == (opts.slideCount-1)) {
					//$('.scroller div.r a').hide();
					$('.scroller div.r a').bind('click.scroller', function () {return false;});
  					$.get('/events/next.html?id='+l_id, function (data) {
  						if (data) {
  							opts.addSlide(data, false);
  							B1.calendar_new.refresh();
  							$('.scroller div.r a').unbind('click.scroller');
  							//$('.scroller div.r a').show();
  						} else {
  							$('.scroller div.r a').hide();
  						}
  			  		});
  				} else {
  					$('.scroller div.r a').show();
  				}
				if (opts.currSlide == 0) {
					//$('.scroller div.l a').hide();
					$('.scroller div.l a').bind('click.scroller', function (e) {e.stopImmediatePropagation();return false;});
  					$.get('/events/prev.html?id='+f_id, function (data) {
  						if (data) {
	  						opts.addSlide(data, true);
	  			  			B1.calendar_new.refresh();
	  			  			//$('.scroller div.l a').show();
	  			  			$('.scroller div.l a').unbind('click.scroller');
  						} else {
  							$('.scroller div.l a').hide();
  						}
  			  		});
  				} else {
  					$('.scroller div.l a').show();
  				}	
  			}

  	      });
  	      return this;
	  }
  };
}();



