if (typeof BMX === 'undefined') {
	var BMX = {};
}

BMX.adBox = (function() {
	var that = this;
	var cookieName = 'bmx-ad-shown';
	var moveOverlays = function() {
		$('.overlay').appendTo('body');
	}
	var adboxes = [];
	return {
		init : function() {
			moveOverlays();
			if ($('.adbox').length == 1) {
				//Execute only one time each day (BMXRA-724-729)
				var alreadyShown = $.cookie(cookieName);
				if (alreadyShown) {
					return;
				}
				var current = new Date();
				var tomorrow = new Date(current.getFullYear(), current.getMonth(), current.getDate()+1);
				$.cookie(cookieName, "1", {expires: tomorrow});
				$('.adbox').each(function() {
					$(this).hide();
					adboxes.push($(this).overlay({
						"api" : true,
						"expose" : "#000000"
					}).load());
				});
			}
		},
		close : function() {
			var i = 0, adbox;
			for (i = 0; i < adboxes.length; i++) {
				adbox = adboxes[i];
				adbox.close();
			}
		}
	}
})();

