(function swf_container(c) {
	c.id = c.id || ('arbobill_' + Math.random());

	c.wmode = c.wmode || ['opaque', 'window', 'transparent'][parseInt(c.useWindow*1)] || 'opaque'; // window if param, then opaque 
	c.base = c.src;
	c.margin = c.margin || 'auto';
	
	document.write('<div id="' + c.id + '" style="position: relative; top: 0; width: ' + c.width + 'px;margin:' +c.margin+ '">'
		+ '<object type="application/x-shockwave-flash" data="' + c.src + '" width="' + c.width
		+ '" height="' + c.height + '" class="arbo">' + "\n"
			+ '<param name="movie" value="' + c.src + '">' + "\n"
			+ '<param name="allowscriptaccess" value="always">' + "\n"
			+ (c.noBase ? '' : '<param name="base" value="' + c.base + '">')
			+ '<param name="wmode" value="' + c.wmode + '">' + "\n" 
		+ '</object></div>');
	
	if (c.scroll) {
		if (!window.addEventListener) window.addEventListener = function (evtName, callback) {
			return window.attachEvent("on" + evtName, callback);
		};

		new Image().src = 'http://ad.arbomedia.pl/ad/media/x.png';
		
		var e = document.getElementById(c.id), p = e, initialOffset = p.offsetTop;
		while (p = p.offsetParent) initialOffset += p.offsetTop;
		
		var timeout = null;
		window.addEventListener("scroll", function () {
			if (c.x) return arguments.callee = function() {};
			if (timeout) clearTimeout(timeout); else dodajZamykacz();
			if (!e) return c.x = true; // bug?
			var posStep, posStart = parseInt(e.style.top) || 0,
				posEnd	= parseInt(document.body.scrollTop || document.documentElement.scrollTop) || 0;
			if (posEnd > 0) posEnd += 40;
			
			// dont scroll over the bottom!
			posEnd = Math.min(posEnd, Math.max(document.documentElement.scrollHeight,
				document.body.scrollHeight, c.height) - initialOffset - c.height);
			
			e.style.top = Math.round(posStart + (posStep = (posEnd - posStart) /14)) + 'px';
			if (parseInt(Math.abs(posStep))) timeout = setTimeout(arguments.callee, 50);
//			e.style.top = (posStart + (posEnd - posStart) / 14) + 'px';
//			if (posStart != posEnd) timeout = setTimeout(arguments.callee, 50);
		}, true);
		
		var dodajZamykacz = function () {
			var e = document.getElementById(c.id);
			if (!e) return false;
			// z-index:
			e.style.zIndex = 999999;

			var img = document.createElement('img');
			img.src = 'http://ad.arbomedia.pl/ad/media/x.png';
			img.alt = img.title = 'zamknij'; img.style.cursor = 'pointer';
			img.style.position = 'absolute'; img.style.top = '-16px';
			img.style.right = 0; 
			img.onclick = function () {
				e.style.top = 0; c.x = true; img.parentNode.removeChild(img);	
			}
			e.appendChild(img);
		}
	}

})(ARBObillboard);


