var webrop;

var Webropol = function() {
	this.webCookie ='kopiostoWebropol32538321a',
	this.clickCookie = 'kopiostoClicks28ak3826s',
	this.clicksRequired = 1; // number of clicks before showing the query popup
	this.detectDisplay = function() {
		var clicks = this.addClick();
		// popup already shown
		if(this.cookieExists()) {
			return;
		}
		// not enough clicks
		if(clicks <= this.clicksRequired)
			return;
		
		var viewport = document.viewport.getDimensions();
		var scrWidth = viewport.width;
		// adjust the cloak width to screen and set transparency
		$('black_cloak').setStyle({ width: scrWidth + "px", opacity: 0.7});
		$('black_cloak').show();
		$('webropol_container').show();
	},
	// check for poll cookie
	this.cookieExists = function() {
		if(Cookie.exists(this.webCookie) && Cookie.get(this.webCookie) == 1) {
			return true;
		}
		return false;
	},
	this.setCookie = function() {
		Cookie.set(this.webCookie, 1);
	},
	this.close = function() {
		$('black_cloak').hide();
		$('webropol_container').hide();
		this.setCookie();
	},
	// updates the number of clicks stored in the cookie
	this.addClick = function() {
		if(!Cookie.exists(this.clicksCookie)) {
			Cookie.set(this.clicksCookie, 1);
			return 1;
		}
		var clicks = Cookie.get(this.clicksCookie);
		clicks = parseInt(clicks) + 1;
		Cookie.set(this.clicksCookie, clicks);
		return clicks;
	}
}

function initWebropol() {
	webrop = new Webropol();
	webrop.detectDisplay();
}

window.onload = initWebropol;
