
	var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
	var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

	function Cplb_ControlVersion()
	{
		var version;
		var axo;
		var e;
		
		try {
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
			version = axo.GetVariable("$version");
		} catch (e) {
		}

		if (!version)
		{
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				version = "WIN 6,0,21,0";		
				axo.AllowScriptAccess = "always";
				version = axo.GetVariable("$version");
			} catch (e) {
			}
		}

		if (!version)
		{
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
				version = axo.GetVariable("$version");
			} catch (e) {
			}
		}

		if (!version)
		{
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
				version = "WIN 3,0,18,0";
			} catch (e) {
			}
		}

		if (!version)
		{
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				version = "WIN 2,0,0,11";
			} catch (e) {
				version = -1;
			}
		}
		
		return version;
	}

	function Cplb_GetSwfVer(){
		var flashVer = -1;
		
		if (navigator.plugins != null && navigator.plugins.length > 0) {
			if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
				var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
				var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;			
				var descArray = flashDescription.split(" ");
				var tempArrayMajor = descArray[2].split(".");
				var versionMajor = tempArrayMajor[0];
				var versionMinor = tempArrayMajor[1];
				if ( descArray[3] != "" ) {
					tempArrayMinor = descArray[3].split("r");
				} else {
					tempArrayMinor = descArray[4].split("r");
				}
				var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
				var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
			}
		}
		else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
		else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
		else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
		else if ( isIE && isWin && !isOpera ) {
			flashVer = Cplb_ControlVersion();
			flashVer = flashVer.replace(/WIN /,"").replace(/,/g, ".");
		}	
		return flashVer;
	}

	// check color depth of user sreen
	function Cplb_colorDepth () {
		if( self.screen ) {
			if ( screen.pixelDepth ) {
				colors = screen.pixelDepth;
			}
			else {
				colors = screen.colorDepth;
			}
			
			return colors;
		}
		else {
			return false;
		}
	}
	
	// check screen resolution
	function Cplb_screenResolution () {
		return screen.width + 'x' + screen.height;
	}
	
	// creating link
	function Cplb_createLink () {
		var referrer = escape (document.referrer);
		var colors = Cplb_colorDepth ();
		var resolution = Cplb_screenResolution ();
		var swfVer = Cplb_GetSwfVer ();
		var webpageFromJs = escape (location.href);
		var url = 'cd=' + colors + '&res=' + resolution + '&fv=' + swfVer + '&ref=' + referrer + '&wfjs=' + webpageFromJs;	
		return url;
	}

	// add parametrs from cleateLink to the banner link
	function Cplb_appendLink (id) {
		var link = document.getElementById ('casinoLink' + id);
		
		if (link.href.indexOf ('?') == -1) {
			url = '?';
		}
		else {
			url = '&';
		}
		
		link.href += url + createLink ();
	}
	
	function Cplb_gotoUrl (url) {
		if (url.indexOf ('?') == -1) {
			link = '?';
		}
		else {
			link = '&';
		}
		window.location = url + link + createLink ();
	}
	
	function Cplb_insertFlash (link, pathToSwf, width, height) {
	
		if (link.indexOf('?') == -1) {
			link = link + '?';
		}
		else {
			link = link + '&';
		}
	
		link = escape (link + Cplb_createLink ());
		
		var protocol = 'http' + (window.location.href.indexOf("https") == 0 ? 's' : '');
		
		document.write ('<object width="'+width+'" height="'+height+'"' + 
			'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"' +
			'codebase="'+protocol+'://fpdownload.macromedia.com/pub/'+
			'shockwave/cabs/flash/swflash.cab#version=8,0,0,0">'+
			'<param name="movie" value="'+pathToSwf+'" />' +
			'<param name="menu" value="false" />' +
			'<param name="quality" value="high" />' +
			'<param name="bgcolor" value="#000000" />' +
			'<param name="wmode" value="transparent"> ' +
			'<param name="allowScriptAccess" value="always"> ' +
			'<param name="flashvars" value="landingPage='+link+'" />' +
			'<embed src="'+pathToSwf+'" width="'+width+'" height="'+height+'"' +
				'menu="false" quality="high" bgcolor="#000000" wmode="transparent" allowscriptaccess="always" ' +
			  	'flashvars="landingPage='+link+'" ' +
			  	'type="application/x-shockwave-flash" pluginspage= ' +
			  	'"'+protocol+'://www.macromedia.com/go/getflashplayer" name="flashLink"/>' +
			'</object>');
			
	}
	
	function Cplb_insertFloatingDiv (link, pathToSwf, width, height, aid) {
		document.write('<style type="text/css">#CplbFixed {z-index: 999;position: fixed; *position:absolute; *top: expression(eval(document.compatMode && document.compatMode=="CSS1Compat") ? documentElement.scrollTop+(documentElement.clientHeight-this.clientHeight) : document.body.scrollTop+(document.body.clientHeight-this.clientHeight));bottom: 0px;right: 15px;width: '+width+'px;height: '+height+'px;}#CplbPop {position: relative;}</style>');
		Cplb_createPopup(link, pathToSwf, width, height, aid);
		document.getElementById('CplbPop').style.top=document.getElementById('CplbPop').style.height;
		Cplb_slideIn ('CplbPop');
	}

	function Cplb_insertFloatingImage (href, title, id, onclick, src, width, height, aid) {
		document.write('<style type="text/css">#CplbFixed {z-index: 999;position: fixed; *position:absolute; *top: expression(eval(document.compatMode && document.compatMode=="CSS1Compat") ? documentElement.scrollTop+(documentElement.clientHeight-this.clientHeight) : document.body.scrollTop+(document.body.clientHeight-this.clientHeight));bottom: 0px;right: 15px;width: '+width+'px;height: '+height+'px;}#CplbPop {position: relative;}</style>');
		var p=document.createElement('div');
		p.id="CplbPop";
		p.style.height=height;
		var newcontent=document.createElement('div');
		newcontent.id="CplbFixed";
		newcontent.appendChild(p);
		p.innerHTML = '<a href="'+href+'" title="'+title+'" id="'+id+'" onclick="'+onclick+'"><img src="'+src+'" width="'+width+'" height="'+height+'" alt="'+title+'" border="0"/></a>';
		var scr=document.getElementById('cplb-'+aid);
		scr.parentNode.insertBefore(newcontent,scr);
		document.getElementById('CplbPop').style.top=document.getElementById('CplbPop').style.height;
		Cplb_slideIn ('CplbPop');
	}
	
	// object handler
	var Cplb_flyingDiv;

	// insert piece of html
	function Cplb_insertFlyingDiv (href, id, onclick, src, width, height, aid) {
		var box = document.createElement ('div');
		box.id = id+'box';
		box.style.width = width;
		box.style.height = height;
		box.style.position = 'absolute';
		box.style.left = '-1000px';
		box.style.zIndex = 1001;
		
		var link = document.createElement ('a');
		link.id = id;
		link.target = '_blank';
		link.href = href;
		link.setAttribute ('onclick', onclick);
		
		var img = document.createElement ('img');
		img.border = 0;
		img.src = src;
		
		link.appendChild (img);
		box.appendChild (link);
		
		var scr = document.getElementById ('flyban-' + aid);
		scr.parentNode.insertBefore (box, scr);
		
		Cplb_flyingDiv = new Cplb_flyingDivObj (box.id, width, height);
		Cplb_moveFlyingDiv ('Cplb_flyingDiv');
	}
	
	// main object
	function Cplb_flyingDivObj (id, width, height) {
		// configuration
		this.vmin = 2;
		this.vmax = 5;
		this.vr = 2;
		
		// initialization
		this.itemId = id;
		this.vx = this.vmin + this.vmax * Math.random ();
		this.vy = this.vmin + this.vmax * Math.random ();
		this.w = width + 20;
		this.h = height;
		this.xx = 0;
		this.yy = 0;
	}

	// moving banner 
	function Cplb_moveFlyingDiv (item) {
		if (!document.getElementById) {
			return;
		}
		
		var pagePosX, pagePosY, pageWidth, pageHeight;
		
		eval("obj=" + item);
		
		if (window.innerWidth || window.opera){
			pagePosX = window.pageXOffset;
			pageWidth = window.innerWidth - 40;
			pagePosY = window.pageYOffset;
			pageHeight = window.innerHeight - 20;
		}
		
		else if (document.body) {
			pagePosX = Cplb_getIeParentObj().scrollLeft;
			pageWidth = Cplb_getIeParentObj().offsetWidth - 40;
			pagePosY = Cplb_getIeParentObj().scrollTop;
			pageHeight = Cplb_getIeParentObj().offsetHeight - 20;
	    } 

		obj.xx = obj.xx + obj.vx;
		obj.yy = obj.yy + obj.vy;

		obj.vx += obj.vr * (Math.random () - 0.5);
		obj.vy += obj.vr * (Math.random () - 0.5);
		
		if (obj.vx > (obj.vmax + obj.vmin))
			obj.vx = (obj.vmax + obj.vmin) * 2 - obj.vx;
		if (obj.vx < (-obj.vmax - obj.vmin)) 
			obj.vx = (-obj.vmax - obj.vmin) * 2 - obj.vx;
		if (obj.vy > (obj.vmax + obj.vmin))
			obj.vy = (obj.vmax + obj.vmin) * 2 - obj.vy;
		if (obj.vy < (-obj.vmax - obj.vmin))
			obj.vy = (-obj.vmax - obj.vmin) * 2 - obj.vy;

		if (obj.xx <= pagePosX) {
			obj.xx = pagePosX;
			obj.vx = obj.vmin + obj.vmax * Math.random ();
		}

		if (obj.xx >= pagePosX + pageWidth - obj.w) {
			obj.xx = pagePosX + pageWidth - obj.w;
			obj.vx = -obj.vmin - obj.vmax * Math.random ();
		}

		if (obj.yy <= pagePosY) {
			obj.yy = pagePosY;
			obj.vy = obj.vmin + obj.vmax * Math.random ();
		}

		if (obj.yy >= pagePosY + pageHeight - obj.h) {
			obj.yy = pagePosY + pageHeight - obj.h;
			obj.vy = -obj.vmin - obj.vmax * Math.random ();
		}

		document.getElementById(obj.itemId).style.left = obj.xx + "px";
		document.getElementById(obj.itemId).style.top = obj.yy + "px";

		setTimeout ("Cplb_moveFlyingDiv('Cplb_flyingDiv')", 100);
	}

	function Cplb_createPopup (link, pathToSwf, width, height, aid) {

		if (link.indexOf('?') == -1) {
			link = link + '?';
		}
		else {
			link = link + '&';
		}
	
		link = escape (link + Cplb_createLink ());
		
		var protocol = 'http' + (window.location.href.indexOf("https") == 0 ? 's' : '');
		var str = '<object width="'+width+'" height="'+height+'"' + 
			'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"' +
			'codebase="'+protocol+'://fpdownload.macromedia.com/pub/'+
			'shockwave/cabs/flash/swflash.cab#version=8,0,0,0">'+
			'<param name="movie" value="'+pathToSwf+'" />' +
			'<param name="menu" value="false" />' +
			'<param name="quality" value="high" />' +
			'<param name="bgcolor" value="#000000" />' +
			'<param name="wmode" value="transparent"> ' +
			'<param name="allowScriptAccess" value="always"> ' +
			'<param name="flashvars" value="landingPage='+link+'" />' +
			'<embed src="'+pathToSwf+'" width="'+width+'" height="'+height+'"' +
				'menu="false" quality="high" bgcolor="#000000" wmode="transparent" allowscriptaccess="always" ' +
			  	'flashvars="landingPage='+link+'" ' +
			  	'type="application/x-shockwave-flash" pluginspage= ' +
			  	'"'+protocol+'://www.macromedia.com/go/getflashplayer" name="flashLink"/>' +
			'</object>';

			var p=document.createElement('div');
			p.id="CplbPop";
			p.style.height=height;
			var newcontent=document.createElement('div');
			newcontent.id="CplbFixed";
			newcontent.appendChild(p);
			p.innerHTML=str;
			var scr=document.getElementById('cplb-'+aid);
			scr.parentNode.insertBefore(newcontent,scr);
	}

	function Cplb_slideIn (obj) {
		var y = document.getElementById(obj).style;
		var x = parseInt(y.top);
		if(x > 0) {
			var t = parseInt(Math.sin(x*(Math.PI/2)/parseInt(y.height))*10);
			var n=x-((t>0)?t:1)>0?x-((t>0)?t:1):0;y.top=n+'px';
			if(n>0) 
				setTimeout( function () {Cplb_slideIn (obj)},33);
		}
	}
	
	// gets proper object (IE only)
	function Cplb_getIeParentObj () {
		return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
	}


	if (typeof (ControlVersion) 	== 'undefined') { var ControlVersion = function () {return Cplb_ControlVersion ();};}
	if (typeof (GetSwfVer) 			== 'undefined') { var GetSwfVer = function () {return Cplb_GetSwfVer ();};}
	if (typeof (colorDepth) 		== 'undefined') { var colorDepth = function () {return Cplb_colorDepth ();};}
	if (typeof (screenResolution) 	== 'undefined') { var screenResolution = function () {return Cplb_screenResolution ();};}
	if (typeof (createLink) 		== 'undefined') { var createLink = function () {return Cplb_createLink ();};}
	if (typeof (appendLink) 		== 'undefined') { var appendLink = function (id) {return Cplb_appendLink (id);};}
	if (typeof (insertFlash) 		== 'undefined') { var insertFlash = function (a1, a2, a3, a4) {return Cplb_insertFlash (a1, a2, a3, a4);};}
