var promotionOverlay = {
	fallback: null,
	frame: null,
	duration: 900,
	durationSlide: 1100,
	effect: 'easeInOutExpo',
	refresh: function(){
		setTimeout(function(){
			promotionOverlay.fallback.css({
				height: jQuery(window).height(),
				width: jQuery(window).width()
			});
		},200);
	},
	remove: function(){
		promotionOverlay.frame.add(promotionOverlay.fallback).animate({opacity: 0},promotionOverlay.duration,promotionOverlay.effect,function(){
			jQuery(this).remove();
		});
	}
}

jQuery.noConflict();

jQuery(document).ready(function(){
	
	jQuery('<a class="close link-x-right" href="#" title="Close">Close</a>').appendTo('#overlay-promotion');
	
	var c = jQuery.cookie('promoOverlay');
	
	if(!c){
	
		var oImg = document.createElement('img');
		oImg.onload = function(){//Preload image used in overlay
		
			promotionOverlay.frame = jQuery('#overlay-promotion');
		
			promotionOverlay.fallback = jQuery('<div></div>')//Create fallback
							.attr('id','fallback')
							.css({
								height: jQuery(document.body).height(),
				                width: jQuery(document.body).width(),
								opacity: 0,
								display: 'block',
								'background-color': '#1a1a1a'
							})
							.appendTo(document.body);
						
			promotionOverlay.fallback.animate({opacity:0.8},promotionOverlay.duration,promotionOverlay.effect,function(){

				promotionOverlay.frame.find('a').click(function($e){
					var e = jQuery(this);
					if(e.hasClass('close')){$e.preventDefault();}
					promotionOverlay.remove();
				});

				jQuery.cookie('promoOverlay','yes',{ expires: 2});

				promotionOverlay.frame.animate({top:'45%'},promotionOverlay.durationSlide,promotionOverlay.effect, function(){
					jQuery(window).bind('resize',promotionOverlay.refresh);

				});
			});
		};
		oImg.src = '/img/layout/bg-newsletter-promotion.jpg';

	}

});
