path = './calendar/';

function calendar(){
//id - the ID of the div
//scale - the width of the calendar, which sets the height
//month - the start month of the calendar
//year - the start year of the calendar
//readDB - Allows access to database
//border - the border of the calendar
//font - the font for the calendar
//fontSize - the font of the calendar
//headerBGColor - This is the background color of the header
//headerColor - This is the font color of the header
//headerFormat - The way the header will display the date
//daysHeaderBGColor - The background color of the days header
//daysHeaderColor - The font color of the days header
//emptyDayBoxBGColor - if a month has days before and/or after it of another month, this is the background color of those days
//emptyDayBoxColor - this is the font color of the empty days before and/or after the month
//todayBGColor - If the month displays the current date, this is the background color of that day
//newsBG - (Prerequisite : readDB) the background color of any news articles
//dayBoxColor - the font color of the days
//dayBoxMouseOverBG - when you put your mouse on a day, this is the background color that is displayed
//rowWeekMouseOverBG - when you put your mouse on a week, this is the background color that is displayed
}

//id,scale,month,year,readDB,border,font,fontSize,headerColor,headerFormat,daysHeaderBGColor,daysHeaderColor,emptyDayBoxBGColor,emptyDayBoxColor,todayBGColor,newBG,dayBoxColor,dayBoxMouseOverBG,rowWeekMouseOverBG

function buildCalendar(calendar){
date = new Date();



//GENERAL
if(!(calendar.id)){calendar.id = 'calendar';}
if(!(calendar.scale)){calendar.scale = 400;}
if(!(calendar.month)){calendar.month = date.getMonth()+1}
if(!(calendar.year)){calendar.year = date.getFullYear()}
if(!(calendar.readDB) || calendar.readDB > 1 || calendar.readDB < 0){calendar.readDB = 0}




//GENERAL CSS
if(!(calendar.border)){calendar.border = '#000000';}
if(!(calendar.font)){calendar.font = 'verdana'}
if(!(calendar.fontSize)){calendar.fontSize = 12}

//HEADER CSS
if(!(calendar.headerBGColor)){calendar.headerBGColor = '#FFF'}
if(!(calendar.headerColor)){calendar.headerColor = '#000'}
if(!(calendar.headerFormat)){calendar.headerFormat = 'M Y'}

//DAYS HEADER
if(!(calendar.daysHeaderBGColor)){calendar.daysHeaderBGColor = '#FFF'}
if(!(calendar.daysHeaderColor)){calendar.daysHeaderColor = '#000'}


//EMPTY DAYS CSS
if(!(calendar.emptyDayBoxBGColor)){calendar.emptyDayBoxBGColor = '#D2D2D2';}
if(!(calendar.emptyDayBoxColor)){calendar.emptyDayBoxColor = '#9D9D9D'}

//TODAYS DATE CSS
if(!(calendar.todayBGColor)){calendar.todayBGColor = '#B4AEED'}

//NEWS CSS
if(!(calendar.newsBG) && calendar.newsBG != ''){calendar.newsBG = '#9D9D9D'}

//DAY BOX
if(!(calendar.dayBoxColor)){calendar.dayBoxColor = '#464646'}
if(!(calendar.dayBoxMouseOverBG) && calendar.dayBoxMouseOverBG != ''){calendar.dayBoxMouseOverBG = '#E2E2E2'}

//ROW WEEK
if(!(calendar.rowWeekMouseOverBG) && calendar.rowWeekMouseOverBG != ''){calendar.rowWeekMouseOverBG = '#C7C7C7'}

$('#'+calendar.id).width(calendar.scale).height(calendar.scale)

$.get(path+"calendar.php",{id:calendar.id,scale:calendar.scale,month:calendar.month,year:calendar.year,readDB:calendar.readDB,border:calendar.border,font:calendar.font,
fontSize:calendar.fontSize,headerBGColor:calendar.headerBGColor,headerColor:calendar.headerColor,headerFormat:calendar.headerFormat,daysHeaderBGColor:calendar.daysHeaderBGColor,daysHeaderColor:calendar.daysHeaderColor,emptyDayBoxBGColor:calendar.emptyDayBoxBGColor,
emptyDayBoxColor:calendar.emptyDayBoxColor,todayBGColor:calendar.todayBGColor,newsBG:calendar.newsBG,dayBoxColor:calendar.dayBoxColor,dayBoxMouseOverBG:calendar.dayBoxMouseOverBG,
rowWeekMouseOverBG:calendar.rowWeekMouseOverBG } ,function(data){
$('#'+calendar.id).html(data)
	
	//CHECKS TO SEE IF MONTH IS 12, IF IT ISN'T, SETS NEXT MONTH, IF IT IS 12, THAN SETS TO NEXT YEAR
	if(calendar.month < 12){
	$('.'+calendar.id+'_nextMonth').click(function(){calendar.month++; buildCalendar(calendar)})
	}
	else{
	$('.'+calendar.id+'_nextMonth').click(function(){calendar.month=1; calendar.year++; buildCalendar(calendar)})
	}
	
	//CHECKS TO SEE IF MONTH IS 1, IF IT ISN'T, SETS NEXT MONTH, IF IT IS 1, THAN SETS TO PREVIOUS YEAR
	if(calendar.month > 1){
	$('.'+calendar.id+'_prevMonth').click(function(){calendar.month--; buildCalendar(calendar)})
	}
	else{
	$('.'+calendar.id+'_prevMonth').click(function(){calendar.month=12; calendar.year--; buildCalendar(calendar)})
	}

//ROLLOVER EFFECTS
$('.'+calendar.id+'_rowWeek').mouseenter(function(){$(this).css('background-color',calendar.rowWeekMouseOverBG)}).mouseleave(function(){$(this).css('background-color','')})
$('.'+calendar.id+'_dayBox').mouseenter(function(){$(this).css('background-color',calendar.dayBoxMouseOverBG)}).mouseleave(function(){$(this).css('background-color','')})
$('.news').mouseout(function(){$(this).css('background-color',calendar.news)})

todaysDate = (date.getMonth()+1)+'_'+date.getDate()+'_'+date.getFullYear()
$('#'+calendar.id+'_'+todaysDate).css('background-color', calendar.todayBGColor)
$('#'+calendar.id+'_'+todaysDate).mouseout(function(){$(this).css('background-color', calendar.todayBGColor)})

	$('.calendar_news').mouseout(function(){
			$(this).css('background-color',calendar.newsBG)
			
	})

})


}
//END OF BUILDCALENDAR FUNCTION






