if (typeof BMX === 'undefined'){
	var BMX = {};
}

BMX.adBox = (function(){
	var that = this;
	var cookieName = 'bmx-ad-shown';
	var moveOverlays = function(){
		$('.overlay').appendTo('body');
	}
	return {
		init: function(){
			moveOverlays();
			if ($('.adbox').length == 1){
				// TODO: Execute only on first request during session
				var alreadyShown = $.cookie(cookieName);
				if (alreadyShown){
					return;
				}
				$('.adbox').each(function(){
					$(this).hide();
					$(this).overlay({
						"api": true, 
						"expose": "#000000"
					}).load();
				});
				$.cookie(cookieName, "1", {expires: 0, path: window.location.pathname});
			}
		}
	}
})();
