
var fbO = {
	fallback: null,
	frame: null,
	duration: 900,
	durationSlide: 1300,
	effect: 'easeInOutExpo',
	refresh: function(){
		setTimeout(function(){
			var bodyHeight = jQuery(document.body).height();
			var winHeight = jQuery(window).height();
			fbO.fallback.css({
				height: (winHeight > bodyHeight) ? winHeight : bodyHeight,
				width: jQuery(window).width()
			});
		},200);
	},
	remove: function(){
		fbO.frame.add(fbO.fallback).animate({opacity: 0},fbO.duration,fbO.effect,function(){
			jQuery(this).remove();
		});
	}
}



jQuery(document).ready(function($){
	
	var c = $.cookie('fbOverlay');
	
	if(!c){
	
	
		var oImg = document.createElement('img');
		oImg.onload = function(){//Preload image used in overlay
		
			fbO.frame = $('#fb-overlay');
		
			var bodyHeight = jQuery(document.body).height();
			var winHeight = jQuery(window).height();
		
			fbO.fallback = $('<div></div>')//Create fallback
							.attr('id','fallback')
							.css({
								height: (winHeight > bodyHeight) ? winHeight : bodyHeight,
								width: $(window).width(),
								opacity: 0,
								display: 'block'
							})
							.appendTo(document.body);
						
			fbO.fallback.animate({opacity:0.8},fbO.duration,fbO.effect,function(){

				fbO.frame.find('a').click(function($e){
					var e = $(this);
					if(e.hasClass('close')){$e.preventDefault();}
					fbO.remove();
				});
				
				$.cookie('fbOverlay','yes',{ expires: 30});
			
				fbO.frame.animate({top:'45%'},fbO.durationSlide,fbO.effect, function(){
					$(window).bind('resize',fbO.refresh);
				
				});
			});
		};
		oImg.src = 'images/fb-overlay.png';
	
}	
	
	
	
});
