function listEvents(data) {
	  var html = $.ajax({
		type: 'POST',
		url: "config/indexEvent.php",
		data: "dataevent="+ data,
		async: false
	   }).responseText;
	  
	  return html;
	}


(function($) {
 $(document).ready(function() {
	  
	if ($('#events-scroll').width()>0) {
	  document.getElementById('events-scroll').innerHTML = listEvents('nms');
	  $('#events-control').html('');
	  startcycle();		
	}
		
	function startcycle() {
	  $('#events-scroll').cycle({
					  fx: 'fade',
					  speed: 4500,
					  timeout: 1,
					  cleartype: 1,
					  slideExpr: 'div.event-item',
					  pager: '#events-control',
					  
				  });
	  }
		
	function disableAllDays(date) {
		for (i = 0; i < natDays.length; i++) {
			if (date.getFullYear() == natDays[i][0] && date.getMonth() == natDays[i][1] - 1 && date.getDate() == natDays[i][2]) {
				$('.withevent').bind('click', function() { alert($(this).html()) });
				return [true, natDays[i][3] + '_day' + ' withevent', natDays[i][3]];
			}
		}
		return [false, ''];
	}
	
	/* INIT CALENDAR */
	$('#calendar').datepicker({ 
		beforeShowDay: disableAllDays, 
		onSelect: function(dateText) { 
				  document.getElementById('events-scroll').innerHTML = listEvents(dateText);
				  $('#events-control').html('');
				  startcycle();
				}
	});

	$('#calendar').datepicker('option', 'monthNames', ['Ianuarie', 'Februarie', 'Martie', 'Aprilie', 'Mai', 'Iunie', 'Iulie', 'August', 'Septembrie', 'Octombrie', 'Noiembrie', 'Decembrie']);
	$('#calendar').datepicker('option', 'dayNamesMin', ['D', 'L', 'M', 'M', 'J', 'V', 'S']);
	$('#calendar').datepicker('option', 'minDate', new Date(2009, 1 - 1, 1));
	$('#calendar').datepicker('option', 'maxDate', '+1m');
	$('#calendar').datepicker('option', 'hideIfNoPrevNext', true);
	$('#calendar').datepicker('option', 'prevText', '');
	$('#calendar').datepicker('option', 'nextText', '');
	$('#calendar').datepicker('option', 'firstDay', 1);
	$('#calendar').datepicker('option', 'dateFormat', 'yy-mm-dd');     

 });
})(jQuery);
