
/*########################################################*/
/*-------------- Travel Advisory --------------------*/
/*
 */
(function ($) {
    $.fn.UrgentTravelAdvisory = function() {

		var $overlay;

		var setup = function() {
			//if the travel advisory div doesn't exist then kick out
			if(!$('.urgent-travel-advisory').exists() || $.cookie($('.urgent-travel-advisory').attr('id')))
				return;

			if($('.travel-advisory').exists())
				$('.travel-advisory').data('height',$('.travel-advisory').height()).animate({height: 0},{duration:350});

			//add in overlay
			$('.urgent-travel-advisory').before('<div class="ui-widget-overlay"></div>')
			
			//fade in overlay for effect
			if($.browser.msie)
				$('.urgent-travel-advisory').show();
			else
				$('.ui-widget-overlay').hide().fadeIn(250,function() {
					$('.urgent-travel-advisory').show();
				});

			//close handler
			$('.urgent-travel-advisory .travel-advisory-close').click(function() {
				destroyUrgentTravelAdvisory();
				return false;
			});

            //window resize handler
			$(window).resize(function(){
                resizeOverlay();
            });

			$(window).scroll(function() { 
                resizeOverlay();
			});

            resizeOverlay();

			$.cookie($('.urgent-travel-advisory').attr('id'), true, { expires: 365, path: '/'});

            //capture escape key to close overlay
			$(document).keyup(function(e) {
                if (e.keyCode == 27) { destroyUrgentTravelAdvisory(); }
            });

		};

		function resizeOverlay() {
			$('.ui-widget-overlay').width($(window).width());
			$('.ui-widget-overlay').height($(document).height());

			//find the center of the page to position the travel advisory in
			var top = Math.round(($(window).height() - $('.urgent-travel-advisory').height()) / 2) + $(window).scrollTop();

			$('.urgent-travel-advisory').css({'top':top+'px'});
		}

        function destroyUrgentTravelAdvisory() {
            $('.ui-widget-overlay').fadeOut(250,function() {
				$(this).empty().remove();
			});
            $('.urgent-travel-advisory').animate({top: '-=100',opacity: 0},250,function() {
				$(this).empty().remove();
			});
			if($('.travel-advisory').exists())
				$('.travel-advisory').animate({height: $('.travel-advisory').data('height')+'px'},350);				
        }

		setup();

    }
})(jQuery);

$(document).ready(function () {
	$.fn.UrgentTravelAdvisory();
});















