$(document).ready(function(){
   
   $("#accordion").accordion({ autoHeight: false });
   
   var options = { 
        target:        '#output',
        beforeSubmit:  showRequest,
        success:       showResponse
    }; 
    $('#myForm').ajaxForm(options);
    
    
    var date;
    var dateTime;
    var category;
    var categoryType;
    
    $('.datePicker')
		.datePicker({inline:true})
		.bind(
			'dateSelected',
			function(e, selectedDate, $td)
			{
				date = true;
				if (category == true) {
					dateTime = $.datepicker.formatDate('yy-mm-dd', new Date(selectedDate));
					$('#rssOutput').xml({xmlLink:'http://www.millavenue.com/feeds/list_events.pxp?days=13&limit=100', serverSideLink:'snippets/xml.php', day:dateTime, category:categoryType});
				} else {
					dateTime = $.datepicker.formatDate('yy-mm-dd', new Date(selectedDate));
					$('#rssOutput').xml({xmlLink:'http://www.millavenue.com/feeds/list_events.pxp?days=13&limit=100', serverSideLink:'snippets/xml.php', day:dateTime});
				}
			}
	);
	
	$('.accordian_nav ul li a').click(function(){
		categoryType = $(this).attr('name');
	
		if(date==true){
			$('#rssOutput').xml({xmlLink:'http://www.millavenue.com/feeds/list_events.pxp?days=13&limit=100', serverSideLink:'snippets/xml.php',category:categoryType,day:dateTime});	
			$('.accordian_nav ul li a').removeClass('active_events');
			$(this).addClass('active_events');
		} else{
			$('#rssOutput').xml({xmlLink:'http://www.millavenue.com/feeds/list_events.pxp?days=13&limit=100', serverSideLink:'snippets/xml.php',category:categoryType});	
			$('.accordian_nav ul li a').removeClass('active_events');
			$(this).addClass('active_events');
		}
		category = true;
	});
});


function showRequest(formData, jqForm, options) {var queryString = $.param(formData); return true;}
function showResponse(responseText, statusText, xhr, $form)  {} 
