	//eventsCalendar.js
	dojo.addOnLoad(function(){
		init();
	});
	
	var date = new Date();
	var today = date.getDate();
	var currentMonth = date.getMonth();
	var currentYear = date.getFullYear();
	var todayLayer = 'day' + today;
	var config = {
		initialMonth 		: currentMonth,
		initialYear			: currentYear,
		year 				: currentYear,
		month 				: currentMonth,
		day 				: today,
		today				: today,
		currentWeek			: 1,
		displayLayer		: 'content',
		pagingLayer 		: 'pagingTop',
		bottomPagingLayer 	: 'pagingBottom',
		monthLayer 			: 'monthYear',
		monthLayerBottom 	: 'monthYearBottom',
		tabs				: ['Day','Week','Month'],
		viewMode 			: 'month',
		az					: 'all',
		age					: '',
		cat 				: '',
		audience			: '',
		eventType			: '',
		mediaType			: '',
		newsType			: '',
		topic				: '',			
		subcat				: '',
		type				: 'events',
		links				: 7,
		query				: '',
		numPerPage 			: 50,
		href 				: '/assets/processing/eventsXmlProxy.aspx',
		search				: 'events',
		reloadCount			: 0		
	};
	
	var mySearch;
	
	var catConfig = {
		az			: '',
		age			: '',
		audience	: '',
		eventType	: '',
		mediaType	: '',
		newsType	: '',
		topic		: '',
		year		: '',
		month		: '',
		cat 		: '245',		
		subcat		: '',
		type		: 'events',
		links		: 7,
		query		: '',
		numPerPage 	: 50,
		href 		: '/assets/processing/eventsXmlProxy.aspx',
		search		: 'events'
	};
	var myCategories;
	var qs;
	var eventType;
	var audience;
	var catName;
		
	init = function (){
		//var myQs = new com.mgh.FacetedSearchQueryString(config,'events');
		//config = myQs.setParameters();
		
		//12/01 mod
		eventType = '';
		audience = '';
		catName = '';
		
		try {
			qs = new com.mgh.QueryString(null);
			eventType = qs.get('eventType').replace('#','');
			audience = qs.get('audience').replace('#','');
			catName = qs.get('catName').replace('#','');
			
			//12/01 mod
			config.eventType = eventType;
			config.audience = audience;
			catConfig.eventType = eventType;
			catConfig.audience = audience;
		} catch (e) {
			console.log(e);	
		}
		mySearch = new com.mgh.Events(config);
		myCategories = new com.mgh.EventsCategories(catConfig);
		myCategories.buildFilter1();		
		showTimer();		

		registerEvents ();	
		
		dojo.connect(dojo.byId('showDescriptions'),'onclick',function(){
			showDescriptions();
		});
		
		dojo.connect(dojo.byId('clearResults'),'onclick',function(){
			reloadPage();
		});	
		
		dojo.connect(dojo.byId('keyWordButton'),'onclick',function (){
			keyWordSearch();			
		}); 								
	}
	
	calendarDataReady = function (response){
		mySearch.dataReady(response);
		if (mySearch.reloadCounter == 0){
			if (mySearch.queryParams.viewMode == 'month'){
				mySearch.defaultMonthView();
			} else if (mySearch.queryParams.viewMode == 'week') {
				mySearch.defaultWeekView();
			} else {
				mySearch.defaultDayView();
			}

			dojo.connect(dojo.byId('previousMonth'),'onclick', function (){
				previousPage();
			});
			
			dojo.connect(dojo.byId('previousMonthBottom'),'onclick', function (){
				previousPage();
			});		
			
			dojo.connect(dojo.byId('nextMonth'),'onclick',function (){
				nextPage();
			});
			
			dojo.connect(dojo.byId('nextMonthBottom'),'onclick',function (){
				nextPage();
			});	
			mySearch.reloadCounter ++;
			hideTimer();

		} else {
			mySearch.reset();
			if (mySearch.queryParams.viewMode == 'month'){
				mySearch.updateMonthView();
			} else if (mySearch.queryParams.viewMode == 'week') {
				mySearch.updateWeekView();
			} else {
				mySearch.updateDayView();
			}
			hideTimer();			
		}
	}
	
	workingSimpleCalendar = function () {
		//base calendar, it has dummy lorem ipsum text
		mySearch = new com.mgh.Calendar(config);	
		
		//derived class events
		
		if (mySearch.queryParams.viewMode == 'month'){
			mySearch.defaultMonthView();
		} else {
			mySearch.defaultWeekView();
		}	
		dojo.connect(dojo.byId('previousMonth'),'onclick', function (){
			previousPage();
		});
		
		dojo.connect(dojo.byId('previousMonthBottom'),'onclick', function (){
			previousPage();
		});		
		
		dojo.connect(dojo.byId('nextMonth'),'onclick',function (){
			nextPage();
		});
		
		dojo.connect(dojo.byId('nextMonthBottom'),'onclick',function (){
			nextPage();
		});
	}
	
	nextPage = function (){
		if (mySearch.queryParams.viewMode == 'month'){
			showTimer();
			mySearch.nextMonth();
			myCategories.queryParams.year = mySearch.queryParams.year;
			myCategories.queryParams.month = mySearch.queryParams.month;
		} else if (mySearch.queryParams.viewMode == 'week') {
			mySearch.nextWeek();
		} else {
			mySearch.nextDay();
		}		
	}
	
	previousPage = function (){
		if (mySearch.queryParams.viewMode == 'month'){
			showTimer();			
			mySearch.previousMonth();
			myCategories.queryParams.year = mySearch.queryParams.year;
			myCategories.queryParams.month = mySearch.queryParams.month;			
		} else if (mySearch.queryParams.viewMode == 'week') {
			mySearch.previousWeek();
		} else  {
			mySearch.previousDay();
		}
	}
	
	switchView = function (type){
		var tab = type + 'Tab';
		if (type == 'month'){
			mySearch.updateMonthView();
		} else if (type == 'week') {
			mySearch.updateWeekView();
		} else {
			mySearch.updateDayView();
		}
		mySearch.resetHighlights();
		dojo.byId(tab).className = 'active';
	}
	
	calendarDetailView = function (day){
		mySearch.dayCount = day;
		mySearch.updateDayView();
		switchView('day');
	}