$(document).ready(function(){
	
	var base_path = window.location.pathname.replace('index.html','').split('/calendar/');
		base_path = base_path[0] + '/calendar/';

	
	$('#datepicker').datepicker({
	    keyboardNavigation: false,
	    todayHighlight: true,
	    minViewMode: 0,
	    maxViewMode: 0
	});


	// load new URL on day selection
	$('#datepicker').datepicker().on('changeDate', function(e){
		var go_to_date = e.format(0,'yyyy/mm/dd');
		window.location = base_path + go_to_date;
	});
	
	// load new URL on month selection
/*
	$('#datepicker').datepicker().on('changeMonth',function(e){
		var go_to_date = e.format(0,'yyyy/mm/');
		window.location = base_path + go_to_date;
	});
*/

	$('.datepicker-switch:first').on('click',function(e){
		var month_ts = new Date('1 '+this.innerText);
		
		window.location = base_path + month_ts.getFullYear() + '/' + (month_ts.getMonth() + 1);
	});
	
	
	
	$('#datepicker').datepicker('update',$('#datepicker-widget').attr('data-month'));
	
	var dp_on = false;
	$('#datepicker-widget>.btn').on('click',function(e){
		e.preventDefault();
		
		if(dp_on == false){
			$('#datepicker').removeClass('hide-dp').addClass('show-dp');
			dp_on = true;	
		} else if(dp_on == true){
			$('#datepicker').removeClass('show-dp').addClass('hide-dp');
			dp_on = false;
		}
		
		return false;
	});
	
	
	// highlight current events view
	$('.event-views').find('a').each(function(){
		if($(this).attr('href') == location.pathname){
			$(this).addClass('current-link');
		}
	});
	
	
	
	
	
	
	
	
});
