function changeView(type, section) {

	if (type == "list") 
	{
		$("#typelink").html("<a onclick='changeView(\"calendar\", \""+section+"\")' href='#'>Calendar View</a>");
	}
	
	if (type == "calendar") 
	{
		$("#typelink").html("<a onclick='changeView(\"list\", \""+section+"\")' href='#'>List View</a>");
	}


	$.ajax({
	   		type: "POST", 
	   		url: "/index.php?c=control&m=eventtype&type="+type+"&section="+section+"&cache=" + Number(new Date()),
	   		success: function(dataBack) {    			   		
				if (dataBack != '')	{				
					$("#view").html(dataBack);
					if (type=="calendar") initCalendar(section);			
				} else {
					$("#view").html("Failed to load");
				}
	   		}
		});
}

function initCalendar(section) {

	$('#calendar').fullCalendar({
		header: {
				left: '',
				center: 'prev, title, next',
				right: ''
		},
	
		editable: false,
		
		events: "/index.php?c=control&m=events&section="+section,
		
		loading: function(bool) {
			if (bool) $('#loading').show();
			else $('#loading').hide();
		},
		
		eventMouseover: function(calevent, e) {
			var event = $(this).find('a').attr('title');
			eventtext = event.split('-+');
			leftVal = $(this).css('left');
			topVal = $(this).css('top');
			$('#popupDate .head').html("<strong>"+eventtext[1]+"</strong> "+eventtext[0] );
			$('#popupDate .location').html("<em>"+eventtext[2]+"</em");
			$('#popupDate').css({left:leftVal,top:topVal}).fadeIn(150);
		},
		
		eventMouseout: function() {
			$('#popupDate').hide();
		},

		eventClick: function(event) {
			if ($(this).find('a').attr('href') == "#") return false;
		}		
		
	});  
}