 jQuery(function ($) 
	{

	$(".quickDateChanger").on("change",function()
		{
		var newM = $("#selChangeM").val();
		var newY = $("#selChangeY").val();
		window.location = "?M="+newM+"&Y="+newY;
		})


	BCACeventWidths();
	var bcacWinSize=setInterval(function () {BCACeventWidths()}, 1000);
	setTimeout(function() { clearInterval(bcacWinSize); }, 9000);
	$( window ).resize(function(){	BCACeventWidths();	});
	
	function BCACeventWidths()
		{
		var dayW = ($(".grid-calendar").width()/7.00);
		$(".BCAC-eventd1").css("width",dayW*1-2);
		$(".BCAC-eventd2").css("width",dayW*2-2);
		$(".BCAC-eventd3").css("width",dayW*3-2);
		$(".BCAC-eventd4").css("width",dayW*4-2);
		$(".BCAC-eventd5").css("width",dayW*5-2);
		$(".BCAC-eventd6").css("width",dayW*6-2);
		$(".BCAC-eventd7").css("width",dayW*7-2);
		}

	$('.BCAC-AC-event').click(function()
		{
		var thisE = $(this).data("eid");
		var thisT = $(this).data("title");
		var d = new Date();
		var n = d.getTime(); 
		var toPost = 'ts='+n+'&e='+thisE;
		$("#eventModal-headerH3").html(thisT + '<Br /><small style="font-size:0.5em">EventID # ' + thisE + '</small>');

		var postSecure = '';
		if (location.protocol == 'https:')	{	postSecure = 's';	}
		
//		$.post('?showE=Y&ACResultsRender='+thisE+'&now='+n,toPost,function(res)
//			{
//			console.log('fetching event modal page (ACResultsRender) for event id# '+thisE);
//			$("#eventModal-body").html(res);
//			$('#eventModal').modal({show:true});
//			});

		$.post('http'+postSecure+'://alpinecalendar.ca/api/eventBSModal/?e='+thisE,toPost,function(res)
			{
			console.log('fetching event modal page for event id# '+thisE);
			$("#eventModal-body").html(res);
			$('#eventModal').modal({show:true});
			});

		});


	var hash = window.location.hash;
	if( hash )
		{
		var thisE = hash.replace("#","");
		$("#eventClickID"+thisE).click();
		}

	$(".eventModalLiteral").on('hidden.bs.modal', function (e) 
		{
		parent.location.hash = 'null';
		});


	});
	