// type - destination of banner code putting
function WormBanner(placeId, type, swfTimeout, playcountMax, nohide) {
	this.elementVideoAd = document.getElementById(placeId);
	this.hideMaxi = true;
	this.showMaxi = false;
	
	this.isHovered = false;                                 // flag of banner hovering

	this.getMovie = function() {
		if (window.document[movieName]) {
			movie = window.document[placeId+'Embed'];
		}

		if (navigator.appName.indexOf("Microsoft Internet") == -1) {
			if (document.embeds && document.embeds[placeId+'Embed'])
				movie = document.embeds[placeId+'Embed'];
		} else {
			movie = document.getElementById(placeId+'Embed');
		}

		return movie;
	}

	this.needStop = function() {
		try {
			isStopped = this.getMovie().GetVariable("_root.stopped");;
		} catch(err) {
			swfTimeout = 5;
			this.forceStop();
			return;
		}

		if (isStopped == 'true') {
			this.makeMini();

		} else {
			var thisDescr = this;
			setTimeout(function() {
				thisDescr.needStop();
			}, 100);
		}
	}
	
	this.forceStop = function() {
		var thisDescr = this;
		setTimeout(function() {
				thisDescr.makeMini();
			}, 1000*swfTimeout);
	}

	this.hoverChecker = function(isHovered) {
		this.isHovered = isHovered;

		if (isHovered) {
			var thisDescr = this;
			setTimeout(function() {
				thisDescr.switchMini2Maxi();
			}, 100);
		}
	}

	this.switchMini2Maxi = function() {
		if (this.isHovered) {
			this.isHovered = false;
			this.makeMaxi(true);
		}
	}

	this.getBannerHTML = function(src, width, height, wmode, offsetY, offsetX, looping) {
		var string = '<center><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
			' id="' + placeId + 'Embed" width="' + width + '" height="' + height + '">' +
			' <param name="movie" value="' + src + '" />' +
			' <param name="wmode" value="' + wmode +'" />' +
			' <param name="menu" value="false" />' +
			' <param name="quality" value="high" />' +
			' <param name="loop" value="true" />' +
			' <param name="bgcolor" value="#000000" />' +
			' <embed name="' + placeId + 'Embed" src="' + src +'" width="' + width +
			'" height="' + height + '" type="application/x-shockwave-flash" ' +
			'quality="high" bgcolor="#000000" menu="false" wmode="' + wmode +
			'" pluginspage="http://www.macromedia.com/go/getflashplayer" loop="true"' +
			'</embed></object></center>';
		return string;
	}

	this.fetchPixel = function(pixelSrc) {
		if (pixelSrc) {
			var i = new Image();
			i.src = pixelSrc;
		}
	}

	this.setMain = function() {
		var a = arguments;
		this.src = a[0];
		this.width = a[1];
		this.height = a[2];
		this.wmode = a[3];
		this.pixel = a[4];
		this.transparentPart = a[5];
	}
	
	this.setMaxi = function() {
		var a = arguments;
		this.srcBig = a[0];
		this.widthBig = a[1];
		this.heightBig = a[2];
		this.wmodeBig = a[3];
		this.pixelBig = a[4];
		this.transparentPartBig = a[5];
	}
	
	this.setMini = function() {
		var a = arguments;
		this.srcSmall = a[0];
		this.widthSmall = a[1];
		this.heightSmall = a[2];
		this.wmodeSmall = a[3];
		this.pixelSmall = a[4];
	}
	
	this.makeMain = function(looping) {
		var thisDescr = this;
		var elementVideoAd = this.elementVideoAd;
		var timeout; // timout for mouseout - for script working in moz2

		this.fetchPixel(this.pixel);
		
		if (type == 'teaser') {
			elementVideoAd.style.position = 'relative';
			elementVideoAd.style.marginBottom = '-' + this.transparentPart + 'px';
		}
		
		if (type == 'fullscreen') {
			document.body.style.overflow = 'hidden';
			elementVideoAd = document.getElementById('fullscreen');
			elementVideoAd.style.position = 'absolute';
			elementVideoAd.style.width = '100%';
			elementVideoAd.style.height = '100%';
			elementVideoAd.style.top = '0';
			elementVideoAd.style.left = '0';
			elementVideoAd.style.zIndex = '150';
		}

		elementVideoAd.innerHTML = this.getBannerHTML(this.src, this.width, this.height, this.wmode, false);
		
		if (looping) {
			elementVideoAd.onmouseover = function(e) { clearTimeout(timeout); };
			elementVideoAd.onmouseout = function(e) {
				timeout = setTimeout( function() {
					thisDescr.makeMini()
				}, 500);
			}

		} else {
			if (!nohide) {
				if(swfTimeout) {
					thisDescr.forceStop();
				}
				else {
					setTimeout(function() {
						thisDescr.needStop();
					}, 1000);
				}
			}
		}
	}
	
	this.makeMaxi = function(looping) {
		var thisDescr = this;                                  // to avoid 'this'-mixing
		var elementVideoAd = this.elementVideoAd;              // to avoid 'this'-mixing
		var timeout;                                           // timout for mouseout - for script working in moz2

		this.fetchPixel(this.pixelBig);
		
		
		if (type == 'teaser') {
			elementVideoAd.style.position = 'relative';
			elementVideoAd.style.marginBottom = '-' + this.transparentPartBig + 'px';
		}
		
		elementVideoAd.innerHTML = this.getBannerHTML(this.srcBig, this.widthBig, this.heightBig, this.wmodeBig, false);
		
		if (looping) {
			elementVideoAd.onmouseover = function(e) { clearTimeout(timeout); };
			elementVideoAd.onmouseout = function(e) {
				timeout = setTimeout( function() {
					thisDescr.makeMini()
				}, 100);
			}
		}
	}

	this.makeMini = function() {
		if (type == 'fullscreen') {
			document.body.style.overflow = '';
			document.getElementById('fullscreen').style.display = 'none';
		}
		
		var thisDescr = this;
		var elementVideoAd = this.elementVideoAd;

		this.fetchPixel(this.pixelSmall);
		
		if (type == 'teaser') {
			elementVideoAd.style.marginBottom = '0';
		}
		
		elementVideoAd.innerHTML   = this.getBannerHTML(this.srcSmall, this.widthSmall, this.heightSmall, this.wmodeSmall);
		
		elementVideoAd.onmouseover = function(e) { thisDescr.hoverChecker(true); };
		elementVideoAd.onmouseout  = function(e) { thisDescr.hoverChecker(false); };
	}

	this.isDisplayed = function() {
		var reg = new RegExp(placeId + '=[0-9]+');
		if (document.cookie.match(reg)) {
			var matched = document.cookie.match(reg).toString();
			var crap = new RegExp(placeId + '=');
			matched = (matched.replace(crap, '')).toString();
			return matched;
		}
		return 0;
	}
	
	var cookieDays = 1;
	
	this.setDisplayed = function(days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = placeId + '=' + (this.isDisplayed()*1 + 1).toString() + expires + '; path=/';
	}

	this.start = function() {
		if (this.isDisplayed()*1 < playcountMax*1) {
			this.makeMain(false);
			this.setDisplayed(cookieDays);
		}
		else {
			this.makeMini();
		}
	}
}
