var monthNameTable=[
	{short:'jan',long:'January'},
	{short:'feb',long:'February'},
	{short:'mar',long:'March'},
	{short:'apr',long:'April'},
	{short:'may',long:'May'},
	{short:'jun',long:'June'},
	{short:'jul',long:'July'},
	{short:'aug',long:'August'},
	{short:'sep',long:'September'},
	{short:'oct',long:'October'},
	{short:'nov',long:'November'},
	{short:'dec',long:'December'}
];

var ToolTipDisplayed = false;

jQuery(document).ready(function(){
	//Load the default Month/Year
	jQuery('#CalendarDate').html(monthNameTable[eval(jQuery.cookie('CalendarMonth')) - 1].long+" "+jQuery.cookie('CalendarYear'));
	jQuery("#EventsCalendarTableContainer").load("../../Assets/PHP/Calendar/Calendar.php?Month="+jQuery.cookie('CalendarMonth')+"&Year="+jQuery.cookie('CalendarYear'),'',function(){SetupEvents();});
	jQuery("#CalendarItems").load("../../Assets/PHP/Calendar/CalendarCount.php?Month="+jQuery.cookie('CalendarMonth')+"&Year="+jQuery.cookie('CalendarYear'),'',function(){SetupEvents();});
	
	//Run this when they click "Next"
	jQuery("#Next").click(function(){
		if (jQuery.cookie('CalendarMonth') == 12) {
			jQuery.cookie('CalendarMonth', 1);
			jQuery.cookie('CalendarYear', eval(jQuery.cookie('CalendarYear'))+1);
		} else {
			jQuery.cookie('CalendarMonth', eval(jQuery.cookie('CalendarMonth'))+1);
		}
		jQuery('#CalendarDate').html(monthNameTable[eval(jQuery.cookie('CalendarMonth')) - 1].long+" "+jQuery.cookie('CalendarYear'));
		jQuery("#EventsCalendarTableContainer").load("../../Assets/PHP/Calendar/Calendar.php?Month="+jQuery.cookie('CalendarMonth')+"&Year="+jQuery.cookie('CalendarYear'),'',function(){SetupEvents();});
		jQuery("#CalendarItems").load("../../Assets/PHP/Calendar/CalendarCount.php?Month="+jQuery.cookie('CalendarMonth')+"&Year="+jQuery.cookie('CalendarYear'),'',function(){SetupEvents();});
	});
	
	//Run this when they click "Previous"
	jQuery("#Previous").click(function(){
		if (jQuery.cookie('CalendarMonth') == 1) {
			jQuery.cookie('CalendarMonth', 12);
			jQuery.cookie('CalendarYear', eval(jQuery.cookie('CalendarYear'))-1);
		} else {
			jQuery.cookie('CalendarMonth', eval(jQuery.cookie('CalendarMonth'))-1);
		}
		jQuery('#CalendarDate').html(monthNameTable[eval(jQuery.cookie('CalendarMonth')) - 1].long+" "+jQuery.cookie('CalendarYear'));
		jQuery("#EventsCalendarTableContainer").load("../../Assets/PHP/Calendar/Calendar.php?Month="+jQuery.cookie('CalendarMonth')+"&Year="+jQuery.cookie('CalendarYear'),'',function(){SetupEvents();});
		jQuery("#CalendarItems").load("../../Assets/PHP/Calendar/CalendarCount.php?Month="+jQuery.cookie('CalendarMonth')+"&Year="+jQuery.cookie('CalendarYear'),'',function(){SetupEvents();});
	});
	
	//Show the tooltip whenever someone hovers over a image icon
	//SetupEvents();
}); 

function SetupEvents(){
	jQuery('#EventsCalendarTableContainer a.Icon').each(function(i){
		jQuery(this).bind('mouseenter',function(event){
			if (!ToolTipDisplayed) {
				if(!jQuery.browser.msie){
					jQuery('#ToolTipWrapper',this).fadeOut(
						'fast',function(){jQuery(this).remove();}
					);
				} else {
					jQuery('#ToolTipWrapper',this).remove();
				}
				if (jQuery(this).attr('class') == "Day1" || jQuery(this).attr('class') == "Day2") {
					var ToolTipWrapper=jQuery("<div id='ToolTipWrapper' class='alt'>"+"<div id='ToolTip' class=''></div>"+"</div>").hide();
				} else {
					var ToolTipWrapper=jQuery("<div id='ToolTipWrapper'>"+"<div id='ToolTip' class=''></div>"+"</div>").hide();
				}
				var ToolTip=jQuery('#ToolTip',ToolTipWrapper);
				jQuery.ajax({
					type: "POST",
					url: "../../../Assets/PHP/Calendar/LoadEvent.php",
					data: "ID="+jQuery(this).attr('rel'),
					success: function(msg){
						ToolTip.append(msg);
					}
				});
				jQuery(this).prepend(ToolTipWrapper);
				ToolTipWrapper.fadeIn('fast');
				ToolTipDisplayed = true;
			}
		})
	});
	jQuery('#EventsCalendarTableContainer li').each(function(i){
		jQuery(this).bind('mouseleave',function(event) {
			if(!jQuery.browser.msie){
				jQuery('#ToolTipWrapper',this).fadeOut(
					'slow',function(){jQuery(this).remove();}
				);
			} else {
				jQuery('#ToolTipWrapper',this).remove();
			}
			ToolTipDisplayed = false;
		});
	});
};


