$(document).ready(function() {

	// for FontSizer
	var options = { min: -5.5, max: 2.5};
	//Initialize the font sizer for the site.
	$.FontSizer.Init(options);
	
	
	// for PageScroller
	
	//$('a[@href*=#top]').click(function() {
	$('a[href*=#top]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		  && location.hostname == this.hostname) {
		   var $target = $(this.hash);
		   $target = $target.length && $target || $('[@name=' + this.hash.slice(1) +']');
		   if ($target.length) {
			   $target.ScrollTo(400);
			   return false;
		   }
		};
	  });

	if ($('.helpArea').length > 0) {
		$('.formHelp').mouseover(function(){
			$(this).next('.helpArea').fadeIn('fast');								  
		});
		$('.formHelp').mouseout(function(){
			$(this).next('.helpArea').fadeOut('fast');								  
		});
	}
	else {
		$('.formHelp').mouseover(function(){
			$('.CVVhelp').fadeIn('fast');								  
		});
		$('.formHelp').mouseout(function(){
			$('.CVVhelp').fadeOut('fast');								  
		});		
	}	
	
	// document download opens a new window
	$('.downloadBtn').click(function(){
		open(this.href);
		return false;
	});
	
	
	var calCookieStatus = 0;
	
	// check calendarToggle cooke 'on" or 'off'
	if($.cookie('calendarCookie') == 'on'){
		$('.eventCalendar').show();
		$('.calendarDrop').attr( { src: '/images/icons/calendarDrop_up.gif' });
		calCookieStatus = 1;
	}

	if(calCookieStatus == 1){
		$('.calendarDrop').toggle(
			function(){ 
				calFadeOut('fast'); 
			},
			function(){	
				calFadeIn('fast');  
			}
		);
	}
	else{
		$('.calendarDrop').toggle(
			function(){	
				calFadeIn('fast'); 
				$.cookie('calendarCookie', 'on', { expires: parseFloat(0.007) });  //stores cookie
			},
			function(){	
				calFadeOut('fast'); 
				$.cookie('calendarCookie', '', { expires: -1 }); //delete the cookie 
			}
		);
	}
	
	// when an event date is clicked.
	$('.calendarWrapper .TableLayout td a').click(function(){
		calCookieStatus = 0;
		$.cookie('calendarCookie', '', { expires: -1 });
	});
	
	function calFadeIn(){
		$('.eventCalendar').fadeIn('fast');
		$('.calendarDrop').attr( { src: '/images/icons/calendarDrop_up.gif' });
	}
	function calFadeOut(){
		$('.eventCalendar').fadeOut('fast');
		$('.calendarDrop').attr( { src: '/images/icons/calendarDrop.gif' });
	}
	
});

$(window).unload(function(){ 
	/*$.cookie('calendarCookie', '', { expires: -1 });*/
	calCookieStatus = 0;
});