function goToMonth(el) {
	window.location.href = "calendar.php?start=" + $(el).val();
}

$(document).ready(function(){
   $('div.dayContainerMonth').hover(
		function(event) {
			$(this).removeClass('dayContainerMonth');
         $(this).addClass('dayHover');
		},
		function(event) {
			// check if the item isnt the current slected item
			if (!$(this).is('.eventSelected')) {
				$(this).removeClass('dayHover');
            $(this).addClass('dayContainerMonth');
			};
		}  
   );
   
   $('div.eventContent').hover(
		function(event) {
			$(this).removeClass('eventContent');
         $(this).addClass('eventHover');
		},
		function(event) {
			// check if the item isnt the current slected item
			if (!$(this).is('.eventSelected')) {
				$(this).removeClass('eventHover');
            $(this).addClass('eventContent');
			};
		}  
   );
   
    $('#selectMonth').bind("change", function(event) {
     goToMonth($(this));
   });  
   $('#selectMonth').bind("blur", function(event) {
      goToMonth($(this));
   }); 

   $('#selectYear').bind("change", function(event) {
     goToMonth($(this));
   });  
   $('#selectYear').bind("blur", function(event) {
      goToMonth($(this));
   });  
   
   $('div.dayContainerMonth').bind('click', function(event) {
      $('div.dayClick').removeClass('dayClick').addClass('dayContainerMonth');
      id = getDayId($(this));
      $('.hiddenDaySelected').hide().removeClass('hiddenDaySelected');
      $('#hiddenDay_'+id).show().addClass('hiddenDaySelected');
      $('div.eventText').hide();
      $('div.selectedEvent').removeClass('selectedEvent').addClass('eventContent');
      $(this).removeClass('dayContainerMonth').addClass('dayClick');
      $('div.einleitung').hide();
   });  
   
   $('div.dayContainerNow').bind('click', function(event) {
      $('div.dayClick').removeClass('dayClick').addClass('dayContainerMonth');
      id = getDayId($(this));
      $('.hiddenDaySelected').hide().removeClass('hiddenDaySelected');
      $('#hiddenDay_'+id).show().addClass('hiddenDaySelected');
      $('div.eventText').hide('fast');
      $('div.selectedEvent').removeClass('selectedEvent').addClass('eventContent');
      $('div.einleitung').hide();
   });  
   
   $('div.eventContent').bind('click', function(event) {
      id = getDayId($(this));
      if (!$(this).is('.selectedEvent')) {
         $('div.eventText').hide();
         $('div.selectedEvent').removeClass('selectedEvent').addClass('eventContent');
         $('#eventText_'+id).show('fast');
         $(this).removeClass('eventContent').addClass('selectedEvent');
      }
      else {
         $('div.eventText').hide();
         $(this).removeClass('selectedEvent').addClass('eventContent');
      }
   });
});

function getDayId(jEl) {
	return jEl.attr('id').split('_')[1];
}

