function Popup (content) {
	this.content = content;	
}
Popup.prototype = {
	init: function() {
		this.create();
	},
	create: function() {
		var body = as.getBTN("body")[0];
		var _self_ = this;
		this.overlay = as.create("div");
		this.overlay.className = "js-popup-overlay";
		as.style(
			this.overlay,
			{
				height:	document.documentElement.offsetHeight+"px"
			}
		);
		this.popup = as.create("div");
		as.style(
			this.popup,
			{
				top: document.documentElement.scrollTop + 100 + "px"	
			}
		)
		this.closer = as.create("a");
		this.closer.innerHTML = "Закрыть";
		this.closer.className = "js-popup-closer";
		this.closer.href = "#";
		this.closer.onclick = function() {
			_self_.hide();
			return false;
		}
		this.popup.className = "js-popup";
		this.popup.appendChild(this.closer);
		this.popup.appendChild(this.content);
		body.appendChild(this.overlay);
		body.appendChild(this.popup);
	},
	show: function() {
		this.overlay.className += " visible";
		this.popup.className += " visible";
	},
	hide: function() {
		this.overlay.className = this.overlay.className.replace(/\bvisible\b/,"");
		this.popup.className = this.popup.className.replace(/\bvisible\b/,"");
	},
	remove: function() {
		as.removeChild(this.overlay);
		as.removeChild(this.popup);
	}
}



function popups() {
	var popupLinks = as.getBCN("js-popup-link","a");
	if (!popupLinks.length) { return; }
	
	function createPrizesPopup(plink) {
		plink.onclick = function() {
			if (this.jsPopup) {
				this.jsPopup.show();	
			}
			else {
				var popupContent = as.create("div");
				popupContent.className = "js-popup-content under-construction";
				var h2 = as.create("h2");
				var p = as.create("p");
				popupContent.appendChild(h2);
				popupContent.appendChild(p);
				this.jsPopup = new Popup(popupContent);
				this.jsPopup.init();
				this.jsPopup.show();
			}
			return false;
		}
	}
	
	function createRulesPopup(plink) {
		plink.onclick = function() {
			if (this.jsPopup) {
				this.jsPopup.show();	
			}
			else {
				var popupContent = as.create("div");
				popupContent.className = "js-popup-content under-construction";
				var h2 = as.create("h2");
				var p = as.create("p");
				p.className = "rules";
				popupContent.appendChild(h2);
				popupContent.appendChild(p);
				this.jsPopup = new Popup(popupContent);
				this.jsPopup.init();
				this.jsPopup.show();
			}
			return false;
		}
	}
	
	as.map(
		popupLinks,
		function(plink) {
			if (plink.className.match(/\bprize\b/)) {
				createPrizesPopup(plink);	
			}
			if (plink.className.match(/\brules\b/)) {
				createRulesPopup(plink);	
			}
		}
	);
}





as.ready.add(popups);
as.ready.init();