$(document).ready(function() {
	hoverDay();
	$(".dayContainerNow").click();
 });


function hoverDay() {
	$("div.monthDay, div.dayContainerNow, div.otherMonthDay").hover(
		function(event) {
			$(this).css({ cursor:"pointer"});
			$(this).addClass('monthDayHover');
		},
		function(event) {
			$(this).removeClass('monthDayHover');
	});
	
	$('div.monthDay, div.dayContainerNow, div.otherMonthDay').bind('click', function(event) {
		dayId = getDayId($(this));
		monthId = getMonthId($(this));
		var check = $("#event_0_" + dayId + "_" + monthId + "").length;
		if (check > 0) {
			$("#flipBox").flip({ speed: 200, direction: 'rl', content:$("#event_0_" + dayId + "_" + monthId + ""), color:$("#event_0_" + dayId + "_" + monthId + "").css('backgroundColor')}); 
		}
		else {
			$("#flipBox").html("");
		}
		$("#bigDateFormat").html($("#day_" + dayId + "_" +  monthId).html());
	});
}

function flipEvent(day, month, eventNr, left) {
		var direction = 'rl';
		
		if (left) {
			direction = 'lr';
		}
		if (month<10) {	// der schei....  Javascript schneidet uanfach die 0 vorne Weg
			month = "0" + month;
		}
		$("#flipBox").flip({ speed: 200, direction: direction, content:$("#event_" + eventNr + "_" + day + "_" + month + ""), color:$("#event_" + eventNr + "_" + day + "_" + month + "").css('backgroundColor')});
}

function getDayId(jEl) {
	return jEl.attr('id').split('_')[1];
}

function getMonthId(jEl) {
	return jEl.attr('id').split('_')[2];
}
