/*****
 * 
 * requirements (objects this js file uses):
 * 	currentMonthName -> name of the current month, the variable must be somewhere
 * 	currentMonth -> number of the current month, the variable must be somewhere
	currentYear -> guess what,...
	events -> array containing objects
	* pictureUrl -> url to the basepath containing the categorypicutres
	* sponsorPictureUrl -> url to basepath with sponsor pictures
	* basePath the default basepath
	* dayNames -> array containing all names for given day of month
 * 
 */
 
var currentEventId = -1;
var currentDay = -1;

function goToMonth(el) {
	var month = -1;
	if ($(el)[0]) {
		month = $(el)[0].selectedIndex;	
		// last month of previous year
		if (month == 0) {
			month = 13;
		}
		// first month of neyt year
		else if (month == 13) {
			month = 1;	
		}		
	}
	window.location.href = "calendar.php?start=" + $(el).val() + "&month=" + month;
}

$(document).ready(function(){
   //TODO wegen IE auch für blur registrieren
   $('#monthSelect').bind("change", function(event) {
     goToMonth($(this));
   });  
   $('#monthSelect').bind("blur", function(event) {
      goToMonth($(this));
   });  


	/* click on event */
	$('div.eventItem').bind('click', function(event) {
      var id = getId($(this));
		// only show the content, if it isnt alreaday visible
		if (!$(this).is('.eventSelected')) {
			//showContent($(this));
			//TODO add class, remove when click on ohter entry
			$('.eventTextSelected').hide('fast').removeClass('eventTextSelected');
			$('.eventSelected').removeClass('eventSelected').css('background', '#F2F2F2').css('color', '#4F4F4F');
			var content = $('#eventtext_'+id).val();
			$('#eventItemText_'+id).html(content);	// get the text from input
			$('#eventItemText_'+id).show('fast').addClass('eventTextSelected');
         	$(this).addClass('eventSelected');
		}
		else {
			$('#eventItemText_'+id).hide("fast");
         $('.eventSelected').removeClass('eventSelected');
			//$("div.eventSelected").css('background', '#F5F1F1').removeClass('eventSelected');
		}
	});
	
	/* mouseover/mouseout on event */		
	$('div.eventItem').hover(
		function(event) {
			$(this).css('background', '#E0E0E0').css('color', '#F0652C');
		},
		function(event) {
			// check if the item isnt the current slected item
			if (!$(this).is('.eventSelected')) {
				$(this).css('background', '#F2F2F2').css('color', '#4F4F4F');
			}
		}
	);
   
});

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

/*
	get the day id out of the id attribute
*/
function getDayId(jEl) {
	return jEl.attr('id').split('_')[2];
}
