var rwdgWidget4 = function (sRootUrl, sWidgetId, aBanners) {
	this.sRootUrl = sRootUrl;
	this.sWidgetId = sWidgetId;

	this.aBanners = [];

	for (var k = 0; k < aBanners.length; k ++) {
		this.aBanners.push(new rwdgBanner4(aBanners[k]));
	}

	this.oContainer = document.createElement('div');
	this.oContainer.className = 'rwdg-widget';
	this.oContainer.id = 'rwdg-' + this.sWidgetId;
	this.oContainer.style.display = 'block';

	this.oBannersContainer = document.createElement('div');
	this.oBannersContainer.style.textAlign = 'center';
	this.oContainer.appendChild(this.oBannersContainer);

	this.oLink = document.createElement('a');
	this.oLink.className = 'rwdg-link';
	this.oLink.href = this.sRootUrl + 'kup,' + this.sWidgetId + '.html';
	this.oLink.target = '_blank';
	this.oLink.style.display = 'block';
	this.oLink.style.textAlign = 'center';
	this.oLink.innerHTML = '&middot; wykup reklamê na tej stronie &middot;';
	this.oContainer.appendChild(this.oLink);

	for (k = 0; k < this.aBanners.length; k ++) {
		var link = document.createElement('a');

		link.style.display = 'inline-block';

		link.href = this.aBanners[k].aData['url'] == 'http://varia.pl/bannery/' ? 'javascript:none' : this.aBanners[k].aData['url'];
		link.target = '_blank';

		var img = this.aBanners[k].getImageElement();
		link.appendChild(img);

		this.oBannersContainer.appendChild(link);
	}

	this.getScript().parentNode.insertBefore(this.oContainer, this.getScript());
	
	setTimeout(rwdgWidget4.ref(this, function () {
		this.oContainer.style.display = 'inline-block';
		this.oContainer.style.margin = '0 auto';
		this.oContainer.style.textAlign = 'center';
	}), 100);
};

rwdgWidget4.prototype.sRootUrl = null;
rwdgWidget4.prototype.sWidgetId = null;
rwdgWidget4.prototype.aBanners = null;

rwdgWidget4.prototype.getScript = function () {
	return document.getElementById('rwdg' + this.sWidgetId) ? document.getElementById('rwdg' + this.sWidgetId) : document.getElementById('rwdgWidget' + this.sWidgetId);
};

rwdgWidget4.ref = function (object, method) {
	return function () {
		return method.apply(object, arguments);
	};
};

rwdgWidget4.attachEvent = function (o, sEventName, oCallback) {
	if (typeof o.addEventListener != 'undefined') {
	  o.addEventListener(
		sEventName,
		oCallback,
		false
	  );
	} else if (typeof o.attachEvent != 'undefined') {
	  o.attachEvent(
		'on' + sEventName,
		oCallback
	  );
	}
};

rwdgWidget4.onWindowLoad = function (func, wnd) {
	wnd = wnd||window;

	if (rwdgWidget4.isIe()) {
		rwdgWidget4.attachEvent(wnd.document, 'readystatechange', rwdgWidget4.ref({func:func, wnd:wnd}, function () {
			if (/loaded|complete/.test(this.wnd.document.readyState)) {
				this.func();
			}
		}));
	} else if (rwdgWidget4.isWebKit()) {
		rwdgWidget4._onWindowLoad_timer = setInterval(rwdgWidget4.ref({func:func, wnd:wnd}, function () {
			if (/loaded|complete/.test(this.wnd.document.readyState)) {
				clearInterval(rwdgWidget4._onWindowLoad_timer);
				this.func();
			}
		}), 500);
	} else {
		rwdgWidget4.attachEvent(wnd.window, 'load', rwdgWidget4.ref({func:func}, function () {
			this.func();
		}));
	}
};

rwdgWidget4.getAgent = function () {
	return navigator.userAgent.toLowerCase();
};

rwdgWidget4.isIe = function () {
	return (!rwdgWidget4.isPresto() && !rwdgWidget4.isGecko() && document.all) ? true : false;
};

rwdgWidget4.isIe6 = function () {
	return (!rwdgWidget4.isPresto() && !rwdgWidget4.isGecko() && document.all && !/MSIE (7|8)/.test(navigator.userAgent)) ? true : false;
};

rwdgWidget4.isWebKit = function () {
	return rwdgWidget4.getAgent().match(/webkit/i);
};

rwdgWidget4.isGecko = function () {
	return rwdgWidget4.getAgent().match(/gecko/i);
};

rwdgWidget4.isPresto = function () {
	return rwdgWidget4.getAgent().match(/presto/i);
};

rwdgWidget4.regexpEscape = function(s) {
	return s.replace(new RegExp("[.*+?|()\\[\\]{}\\\\]", "g"), "\\$&");
};

rwdgWidget4.window = null;

rwdgBanner4 = function (aData) {
	this.aData = aData;
};

rwdgBanner4.prototype.getImageElement = function () {
	var e = document.createElement('img');
	e.src = this.aData['src'];
	e.width = this.aData['width'];
	e.height = this.aData['height'];
	e.style.border = 'none';

	return e;
};

wo4 = {};

rwdgWidget4.onWindowLoad(function () {
	setTimeout(function () {
		if (!wo4[4]) {
			wo4[4] = new rwdgWidget4("http:\/\/varia.pl\/bannery\/", 4, [{"url":"http:\/\/zdrowaczekolada.pl","src":"http:\/\/varia.pl\/bannery\/banner,30.png","width":"468","height":"60"}]);
		}
	}, 100);
});
