/**
 * @author wes
 */

$(document).ready(function(){
	if ($.browser.msie) {
   		$('#calYearMonth').css('padding','0 30px 7px 30px !important');
	}	
});

function getUpdatedMonth(dir,year,id,lang,siteRoot) {
		
	$.get('../pages/functions/getmonth.php', {'year':year,'month':id,'lang':lang,'siteRoot':siteRoot}, function(data){
			
		//var scrollNum;
		//determin if it's next or prev
		if(dir == "prev") {
			scrollNum = '401px';
			$('div.prevCal').empty().html(data);
			
			//swap out old calendar arrows with new ones
			var calYArrows = $('div.prevCal #calYearMonth .calArrows').html();
			$('div.currCal #calYearMonth .calArrows').empty().html(calYArrows);
			
			if($('div.currCal #calYearMonth .year').text() != $('div.prevCal #calYearMonth .year').text()) {
				$('div.currCal #calYearMonth .year').animate({'color':'#fff'},200, function () {
					$('div.currCal #calYearMonth .year').text($('div.prevCal #calYearMonth .year').text());
					$('div.currCal #calYearMonth .year').animate({'color':'#aeaeae'},200);
				});
			}
			
			var monthDays = $('div.prevCal #days');
			$('div.currCal #days').addClass('toSlideOut');
			
			$('div.currCal #calYearMonth .month').animate({'color':'#fff'},200, function () {
				$('div.currCal #calYearMonth .month').text($('div.prevCal #calYearMonth .month').text());
				$('div.currCal #calYearMonth .month').animate({'color':'#aeaeae'},200);
				
				$(monthDays).css('margin-left','-401px').insertBefore('div.currCal #days');
				$(monthDays).animate({marginLeft:0},"slow", function() {
					$('.toSlideOut').remove();
				});
			}).show();
			
		} else {
			scrollNum = '-401px';
			$('div.nextCal').empty().html(data);
			
			var thisYear = $('div.currCal #calYearMonth .year').text();
			var nextYear = $('div.nextCal #calYearMonth .year').text();
			
			//swap out old calendar arrows with new ones
			var calYArrows = $('div.nextCal #calYearMonth .calArrows').html();
			$('div.currCal #calYearMonth .calArrows').empty().html(calYArrows);
			
			if(thisYear != nextYear) {
				$('div.currCal #calYearMonth .year').animate({'color':'#fff'},200, function () {
					$('div.currCal #calYearMonth .year').text($('div.nextCal #calYearMonth .year').text());
					$('div.currCal #calYearMonth .year').animate({'color':'#aeaeae'},200);
					
				});
			}
			
			//append the next month days after the current
			var nextMonthDays = $('div.nextCal #days');
			var thisMonthDays = $('div.currCal #days');
			
			$('div.currCal #days').addClass('toSlideOut');
			
			$('div.currCal #calYearMonth .month').animate({'color':'#fff'},200, function () {
					
					$('div.currCal #calYearMonth .month').text($('div.nextCal #calYearMonth .month').text());
					$('div.currCal #calYearMonth .month').animate({'color':'#aeaeae'},200);
					
					$(nextMonthDays).insertAfter(thisMonthDays);
					$('div.currCal .toSlideOut').css('margin-left','0px').animate({marginLeft:scrollNum},"slow", function() {
					//$('div.nextCal').empty();
					$('.toSlideOut').remove();
				});
			});
			
			
		}
		
	}).show();
}
	
//redisplays sifr fonts
function updateFonts() {
	//setTimeout( function(){  
		//alert("hello");
		//sIFR.replace( century, { selector: '#calYearMonth .year',css: [ '.sIFR-root {color:#adadad;}' ],wmode: 'transparent' } );
		//sIFR.replace( century, { selector: '#calYearMonth .month',css: [ '.sIFR-root {color:#adadad;font-weight:bold;text-align:right;}' ],wmode: 'transparent' } );
	//}, 0)
}

//show calendar event info
var checker = false;
function updateEventInfo(year,month,day,lang) {
	//wrap event info 
	$('#rightContent').css("min-height",$('#rightContent').height());
	checker = true;
	$('#eventInfo').fadeOut(400, function() {
		if (checker) {
			$.get('../pages/functions/geteventinfo.php', {
				'year': year,
				'month': month,
				'day': day,
				'lang': lang
			}, function(data){
			
			
				//process info and pass it into the #eventInfo box
				
				//animate it back out
				$('#eventInfo').empty().html(data).fadeIn(400);
				
			});
			checker = false;
		}
	});
}