//gstream.js 6.0
var gsm_gemius_proto = (document.location && document.location.protocol && document.location.protocol=='https:')?'https://':'http://';
if (typeof gsm_gemius_hitcollector == 'undefined') {
	gsm_gemius_hitcollector = 'pro.hit.gemius.pl';
}
var gsm_gemius_host = gsm_gemius_proto+gsm_gemius_hitcollector+'/_';

function gsm_gemius_parameters_fn() {
	var d=document;
	var href=new String(d.location.href);
	var ref;
	var f=0;
	var fv='-';
	if (d.referrer) { ref=new String(d.referrer); } else { ref=''; }
	if (typeof Error!='undefined') {
		var fo;
		eval('try { f=(d==top.document)?1:2; if (typeof top.document.referrer=="string") { ref=top.document.referrer } } catch(e) {f=3;}');
		eval('try { fv=navigator.plugins["Shockwave Flash"].description; } catch (e) {}');
		eval('if (typeof ActiveXObject!="undefined") { try { fo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7"); } catch(e) { try { fo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6"); fv="X"; fo.AllowScriptAccess="always"; } catch(e) { if (fv=="X") { fv="WIN 6,0,20,0"; }} try { fo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); } catch(e) {} } if ((fv=="-" || fv=="X") && fo) { fv=fo.GetVariable("$version"); }}');
	}
	var url='&fr='+f+'&fv='+escape(fv)+'&tz='+(new Date()).getTimezoneOffset()+'&href='+escape(href.substring(0,1024))+'&ref='+escape(ref.substring(0,1024));
	if (screen) {
		var s=screen;
		if (s.width) url+='&screen='+s.width+'x'+s.height;
		if (s.colorDepth) url+='&col='+s.colorDepth;
	}
	return url;
}

var gsm_gemius_parameters = gsm_gemius_parameters_fn();

function gsm_gemius_escape(str,limit) {
	function Hex(n) {
		var hexMap = "0123456789ABCDEF";
		return hexMap.charAt(n>>4)+hexMap.charAt(n&0xF);
	}
	var c,s,uc,ul;
	var dst = "";
	for (var i=0 ; i<str.length ; i++) {
		c = str.charCodeAt(i);
		if ((c>=0xDC00)&&(c<0xE000)) continue;
		if ((c>=0xD800)&&(c<0xDC00)) {
			i++;
			if (i>=str.length) continue;
			s = str.charCodeAt(i);
			if ((s<0xDC00)||(s>=0xE000)) continue;
			c = ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
		}
		if (c<0x80) {
			uc = escape(String.fromCharCode(c)).replace(/\+/g,"%2B").replace(/\//g,"%2F");
			if (c<=0x20) {
				ul=3;
			} else {
				ul=1;
			}
		} else if (c<0x800) {
			uc = "%"+Hex((c>>6)|0xC0)+"%"+Hex((c&0x3F)|0x80);
			ul = 2;
		} else if (c<0x10000) {
			uc = "%"+Hex((c>>12)|0xE0)+"%"+Hex(((c>>6)&0x3F)|0x80)+"%"+Hex((c&0x3F)|0x80);
			ul = 3;
		} else if (c<0x200000) {
			uc = "%"+Hex((c>>18)|0xF0)+"%"+Hex(((c>>12)&0x3F)|0x80)+"%"+Hex(((c>>6)&0x3F)|0x80)+"%"+Hex((c&0x3F)|0x80);
			ul = 4;
		} else {
			uc = "";
			ul = 0;
		} 
		limit -= ul;
		if (limit<0) {
			return dst;
		}
		dst+=uc;
	}
	return dst;
}
/*
 *
 * Gemius Stream v 6.00
 *
 */
if(!gSmDebug){
	var gSmDebug = new function(){
		this.events = new Array();
		this.ready = false;
		this.trace = function(arr){
			if(this.events.length>100) {
				return;
			}
			if(!this.ready){
				this.events.push(arr);
				return;
			}else{
				for(var i=0 ; i<this.events.length ; i++){
					this.send(this.events[i]);
				}
				this.events = new Array();
			}
			this.send(arr);
		}
		this.send = function(arr){}
	}
}
if(!gSmUtil){
	var gSmUtil = new function(){
		this.sid = "";
		this.protectedInterval = 100;
		this.oldSystemTime = (new Date()).getTime();
		this.oldSystemTimeTmp = (new Date()).getTime();
		this.newSystemTime = (new Date()).getTime();
		this.currentTime = 0;
		this.delta = 0;
		this.init = function(){
			while(this.sid.length<10){
				this.sid += Math.round(Math.random()*32).toString(32);
			}
			setTimeout("gSmUtil.updateProtectedTime()", this.protectedInterval);
		}
		this.updateProtectedTime = function(){
			setTimeout("gSmUtil.updateProtectedTime()", gSmUtil.protectedInterval);
			gSmUtil.newSystemTime = (new Date()).getTime();
			var diff = gSmUtil.newSystemTime - gSmUtil.oldSystemTimeTmp - gSmUtil.protectedInterval;
			if(diff < -1000 || diff > 60000){
				gSmUtil.delta += gSmUtil.oldSystemTimeTmp - gSmUtil.newSystemTime + gSmUtil.protectedInterval;
			}
			gSmUtil.oldSystemTimeTmp = gSmUtil.newSystemTime;
			gSmUtil.currentTime = Math.floor((gSmUtil.newSystemTime - gSmUtil.oldSystemTime + gSmUtil.delta)/1000);
		}
		this.formatString = function(string, maxLength, restricted){
			string = (string.length>maxLength)?string.substr(0, maxLength):string;
			for(var i=0 ; i<restricted.length ; i++){
				string = string.replace(restricted[i], " ");
			}
			return string;
		}
		this.getTimeSec = function(){
			return this.currentTime;
		}
		this.isOpera = function(){
			return (window.opera);
		}
		this.isSafari = function(){
			if(this.isChrome()) {
				return false;
			}
			return (navigator.userAgent.toLowerCase().indexOf('safari')!=-1);
		}
		this.isChrome = function(){
			return (navigator.userAgent.toLowerCase().indexOf('chrome')!=-1);
		}
		this.isIE = function(){
			return (navigator.appName.toLowerCase().indexOf("microsoft") != -1);
		}
		this.isFF = function(){
			return (navigator.userAgent.toLowerCase().indexOf("firefox")!=-1);
		}
		this.getBytesLength = function(str) {
			return encodeURIComponent(str).replace(/%../g, 'x').length;
		}
		this.limitBytesLength = function(str, maxBytes, restricted) {
			var currBytes = 0;
			var outStr = "";
			for(var i=0 ; i<restricted.length ; i++){
				str = str.replace(restricted[i], " ");
			}
			for (var i = 0 ; i < str.length ; i++ ) {
				currBytes += gSmUtil.getBytesLength(str.charAt(i));
				if (currBytes > maxBytes) {
					return outStr;
				}
				outStr += str.charAt(i);
			}
			return outStr;
		};
		this.init();
	}
}
if(!gSmNoUnload){
	var gSmNoUnload = new function(){
		this.streams = [];
		this.streamsSlots = 3;
		this.streamsMatch = {};
		this.init = function(){
			if(this.hasUnload())return;
			this.sendAllStreams();
			setTimeout("gSmNoUnload.updateStreams()", 500);
		}
		this.hasUnload = function(){
			if(gSmUtil.isOpera() || gSmUtil.isChrome() || gSmUtil.isSafari())return false;
			return true;
		}
		this.addStream = function(stream, gSmId, gSmHc){
			if(this.hasUnload())return;
			var cookieId = ("gsm_"+(new Date()).getTime()+""+Math.round(Math.random()*1000));
			this.streams.push({cookieId:cookieId ,stream:stream, identifier:gSmId, hitcollector:gSmHc, startTime:(new Date()).getTime(), parameters:gsm_gemius_parameters});
			return cookieId;
		}
		this.updateStreamExt = function(cookieId){
			this.updateStream(cookieId, true);
		}
		this.updateStream = function(cookieId){
			if(this.hasUnload())return;
			var stream, hitcollector, identifier, encoding, lastTime, startTime, currentPackage;
			stream = this.getStream(cookieId);
			identifier = stream.identifier;
			hitcollector = stream.hitcollector;
			parameters = stream.parameters;
			encoding = gSmConfig.ENCODING;
			startTime = stream.startTime;
			currentPackage = stream.stream.getCurrentPackage();
			lastTime = (new Date()).getTime();
			this.writeStream(cookieId, hitcollector, identifier, encoding, startTime, lastTime, currentPackage, parameters);
		}
		this.removeStream = function(cookieId){
			for(var i=0 ; i<this.streams.length ; i++){
				if(this.streams[i].cookieId == cookieId){
					delete this.streams[i];
					this.streams.splice(i, 1);
					return;
				}
			}
		}
		this.getStream = function(cookieId){
			for(var i=0 ; i<this.streams.length ; i++){
				if(this.streams[i].cookieId == cookieId)return this.streams[i];
			}
		}
		this.updateStreams = function(){
			setTimeout("gSmNoUnload.updateStreams()", 500);
			for(var i=0 ; i<gSmNoUnload.streams.length ; i++){
				gSmNoUnload.updateStream(gSmNoUnload.streams[i].cookieId);
			}
		}
		this.writeStream = function(cookieId, hitcollector, identifier, encoding, startTime, lastTime, data, parameters){
			this.createCookie(cookieId,(escape(gSmUtil.sid)+"|"+escape(hitcollector)+"|"+escape(identifier)+"|"+escape(encoding)+"|"+escape(startTime)+"|"+escape(lastTime)+"|"+escape(data)+"|"+escape(parameters)),10);
		}
		this.sendAllStreams = function(){
			var streamsData = this.getAllCookies();
			for(var s in streamsData){
				if((new Date()).getTime() - streamsData[s].lastTime>2000){
					var tdiff = (new Date()).getTime() - streamsData[s].startTime;
					if(tdiff>0 && tdiff<259200000){
						var dataArr = streamsData[s].data.split("|");
						var lastEventArr = dataArr[dataArr.length-1].split(";");
						if(lastEventArr[lastEventArr.length - 1][0] == 0){
							dataArr.splice(dataArr.length-1, 1);
						}
						if(dataArr.length>6){
							dataArr[5] = Number(dataArr[5])+Math.round(tdiff/1000);
							streamsData[s].data = dataArr.join("|");
							this.sendStream(streamsData[s].hitcollector, streamsData[s].identifier, streamsData[s].encoding, streamsData[s].data, streamsData[s].parameters);
						}
					}
					this.eraseCookie(s);
				}
			}
		}
		this.sendStream = function(hitcollector, identifier, encoding, data, parameters){
			if (typeof window.gsm_gemius_images == 'undefined') {
				window.gsm_gemius_images = new Array();
			}
			var gemius_l = window.gsm_gemius_images.length;
			window.gsm_gemius_images[gemius_l] = new Image();
			window.gsm_gemius_images[gemius_l].src = hitcollector+(new Date()).getTime()+'/redot.gif?id='+identifier+'&sargencoding='+encoding+'&sarg='+gsm_gemius_escape(data,1023)+parameters;
			gSmDebug.trace(["final", "sendHit", ["cookie: ",data]]);
		}
		this.getAllCookies = function(){
			var pairs = document.cookie.split(";");
			var cookies = {};
			var params;
			for (var i=0; i<pairs.length; i++){
				var pair = pairs[i].split("=");
				if(pair[0].split("gsm_").length>1){
					params = pair[1].split("|");
					cookies[pair[0]] = {
						sid: unescape(params[0]),
						hitcollector: unescape(params[1]),
						identifier: unescape(params[2]),
						encoding: unescape(params[3]),
						startTime: unescape(params[4]),
						lastTime: unescape(params[5]),
						data: unescape(params[6]),
						parameters: unescape(params[7])
					};
				}
			}
			return cookies;
		}
		this._cookieOldVal = null;
		this.createCookie = function(name,value,days,remove) {
			if(!remove)remove = false;
			setTimeout("gSmNoUnload.createCookieThread('"+name+"','"+value+"',"+days+","+remove+")", 1);
		}
		this.getCookieSlot = function(){
			this.sendAllStreams();
			var streamsData = this.getAllCookies();
			var slots = [];
			for(var i=0 ; i<this.streamsSlots ; i++){
				slots[i]=i;
			}
			for(var s in streamsData){
				var slot = s.split("gsm_c")[1];
				slots[slot] = -1;
			}
			for(var i=0 ; i<slots.length ; i++){
				if(slots[i]>-1)return i;
			}
			return null;
		}
		this.createCookieThread = function(name,value,days,remove) {
			if(!remove){
				if(this.streamsMatch[name]==null){
					var ck = this.getCookieSlot();
					if(ck==null)return;
					this.streamsMatch[name] = "gsm_c"+ck;
				}
				name = this.streamsMatch[name];
			}
			if (days) {
				var date = new Date();
				date.setTime(date.getTime()+(days*24*60*60*1000));
				var expires = "; expires="+date.toGMTString();
			}else{
				var expires = "";
			}
			var newCookieContent = name+"="+value+expires+"; path=/";
			if(newCookieContent == this._cookieOldVal) {
				return;
			}
			document.cookie = newCookieContent;
			this._cookieOldVal = newCookieContent;
		}
		this.readCookie = function(name) {
			var nameEQ = name + "=";
			var ca = document.cookie.split(';');
			for(var i=0;i < ca.length;i++) {
				var c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
			}
			return null;
		}
		this.eraseCookie = function(name) {
			this.createCookie(name,"",-1,true);
		}
		this.init();
	}
}
var gSmStream = function(contentId, player){
	this.contentId = contentId;
	this.contentIdFormated = gSmUtil.limitBytesLength(contentId, gSmConfig.MAX_ID_LENGTH, gSmConfig.ID_RES);
	this.player = player;
	this.closing = false;
	this.init = function(){
		this.duration = null;
		this.time = null;
		this.customPackageString = "";
		this.additionalPackageString = "";
		this.lastPlayTime = null;
		this.lastEvent = "";
		this.lastPlayEndTime = null;
		this.firstTimeStamp = gSmUtil.getTimeSec();
		this.lastTimeStamp = gSmUtil.getTimeSec();
		this.isPlaying = false;
		this.forcedClose = false;
		this.controlBreak = false;
		this.eventString = "";
		this.eventId = "";
		this.infoString = ""
		this.viewId = "";
		this.cookieId = "";
		this.gSmId = "";
		this.gSmHost = "";
		this.treeIdString = "";
		this.realPlaying = false;
	}
	this.init();
	this.newStream = function (duration, customPackage, additionalPackage, gSmId, gSmHc, treeId){
		this.init();
		this.gSmId = (gSmId == undefined || gSmId == null)?gsm_gemius_identifier:gSmId;
		this.gSmHc = (gSmHc == undefined || gSmHc == null)?gsm_gemius_host:(gSmHc+"/_");
		this.cookieId = gSmNoUnload.addStream(this, this.gSmId, this.gSmHc);
		this.duration = (duration>0)?Math.round(duration):-1;
		this.time = 0;
		this.customPackageString = this.formatPackage(customPackage);
		this.additionalPackageString = this.formatPackage(additionalPackage);
		this.treeIdString = this.formatTree(treeId);
		gSmDebug.trace(["final", "newStream", [this.player.playerId, this.contentId, this.duration, this.customPackageString, this.additionalPackageString, this.treeIdString]]);
	}
	this.formatTree = function(arr){
		var out = arr.join(",");
		while(arr.length >= 0 && gSmUtil.getBytesLength(out)>gSmConfig.MAX_TREE_ID_LENGTH){
			arr.pop();
			out = arr.join(",");
		}
		return out;
	}
	this.formatPackage = function(obj){
		var str = "";
		var criterion;
		var category;
		var max_i = (obj.length > gSmConfig.MAX_CRITERIONS)?gSmConfig.MAX_CRITERIONS:obj.length;
		for(var i=0 ; i<max_i ; i++){
			criterion = gSmUtil.limitBytesLength(obj[i]["name"], gSmConfig.MAX_CRITERION_LENGTH, gSmConfig.CRITERION_RES);
			category = gSmUtil.limitBytesLength(obj[i]["value"], gSmConfig.MAX_CATEGORY_LENGTH, gSmConfig.CATEGORY_RES);
			str += ((i==0)?"":";") + criterion + "=" + category;
		}
		return str;
	}
	this.getCurrentPackage = function(){
		var events = this.getEvents(true);
		var viewId = (this.viewId!="")?("#"+this.viewId):("");
		return this.getFormatedData() + "|" + Math.round(this.lastTimeStamp - this.firstTimeStamp)+";"+Math.round(this.lastPlayTime)+";"+Math.round(this.getPlayLength(true))+viewId + events;
	}
	this.closeStream = function(time){
		this.closing = true;
		this.time = time;
		this.lastPlayEndTime = time;
		gSmDebug.trace(["final", "closeStream", [this.player.playerId, this.contentId, Math.round(this.time)]]);
		this.sendStream();
		this.isPlaying = false;
	}
	this.closeStreamForced = function(){
		this.closing = true;
		gSmDebug.trace(["final", "closeStream", [this.player.playerId, this.contentId, Math.round(this.time)]]);
		this.forcedClose = true;
		this.sendStream();
		this.isPlaying = false;
	}
	this.sendStream = function(controlBreak){
		this.controlBreak = (controlBreak == undefined || controlBreak == null)?"":controlBreak;
		if(this.controlBreak == "time" && (this.getCurrEvent()+this.eventString!="")){
			if(this.viewId == "")this.viewId = gemiusStream.newViewId();
		}
		var playLength = this.getPlayLength();
		var currEvent = this.getCurrEvent();
		if(!this.checkLength(currEvent)){
			this.eventString += this.makeCurrEventViewId(currEvent);
			this.sendHit("");
			this.lastPlayTime += playLength;
		}
		if(this.controlBreak == "time")this.realPlaying = false;
	}
	this.sendFirsPlayingEvent = function(){
		this.sendHit("",true);
		this.firsPlayingEvent = true;
	}
	this.event = function(time, eventType){
		this.forcedClose = false;
		this.time = time;

		if(this.lastEvent == eventType) {
			return;
		}
		gSmDebug.trace(["final", "event", [this.player.playerId, this.contentId, Math.round(time), eventType]]);
		switch(eventType){
			case "playing":
				if (this.isPlaying) {
					return;
				}
				if (this.eventString == "") {
					this.firstTimeStamp = gSmUtil.getTimeSec();
				}
				this.lastTimeStamp = gSmUtil.getTimeSec();
				this.lastPlayTime = time;
				if (!this.firsPlayingEvent) {
					this.sendFirsPlayingEvent();
				}
				this.eventId = "p";
				this.realPlaying = true;
				this.isPlaying = true;
				this.viewId = "";
				break;
			case "complete":
				this.eventId = "c";
				this.lastPlayEndTime = time;
				this.sendStream();
				this.isPlaying = false;
				this.viewId = "";
				this.firsPlayingEvent = false;
				break;
			default:
				switch(eventType){
					case "paused":
						this.eventId = "p";
						break;
					case "stopped":
						this.eventId = "s";
						break;
					case "buffering":
						this.eventId = "b";
						break;
					case "seekingStarted":
						this.eventId = "r";
						break;
				}
				if(this.lastPlayTime == null)return;
				this.lastPlayEndTime = time;
				this.controlBreak = "length";
				var currEvent = this.getCurrEvent();
				if(!this.checkLength(currEvent)){
					this.eventString += this.makeCurrEventViewId(currEvent);
				}
				this.isPlaying = false;
				break;
		}
	}
	this.makeCurrEventViewId = function(currEvent){
		return currEvent+((this.viewId!="" && currEvent!="")?("#"+this.viewId):(""));
	}
	this.getPlayLength = function(operaCheck){
		if(operaCheck == undefined || operaCheck == null)operaCheck = false;
		if(this.isPlaying == false) return 0;
		var tCalc, tGet, tGetR;
		tCalc = gSmUtil.getTimeSec() - this.lastTimeStamp;
		tGet = this.lastPlayEndTime - this.lastPlayTime;
		tGetR = Math.round(this.lastPlayEndTime) - Math.round(this.lastPlayTime);
		if(this.forcedClose == true || this.duration==-1 || this.controlBreak != "" || operaCheck == true){
			return tCalc;
		}else if(tGetR==1 || tGetR==0){
			return tGetR;
		}else if(tCalc<=0){
			return tGet;
		}else if(tGet<=0){
			return tCalc;
		}else{
			return Math.min(tCalc, tGet);
		}
	}
	this.getEvents = function(exit){
		exit = (exit == undefined)?false:exit;
		var events = "";
		if(this.controlBreak == "" || this.controlBreak == "length" || exit){
			events = ((this.viewId!="")?"":"^p")+((this.forcedClose || exit || this.closing)?"$q":("$"+this.eventId));
		}else{
			events = (this.realPlaying)?"^p":"";
			if(this.eventId!="p")events = "^"+this.eventId;
		}
		return events;
	}
	this.getCurrEvent = function(){
		var playLength = Math.round(this.getPlayLength());
		if(playLength > 0){
			return "|"+Math.round(this.lastTimeStamp-this.firstTimeStamp)+";"+Math.round(this.lastPlayTime)+";"+playLength+this.getEvents();
		}else{
			return "";
		}
	}
	this.sendHit = function(currEvent, forced){
		if (forced == undefined) {
			forced = false;
		}
		if (this.eventString == "" && currEvent == "" && forced == false) {
			return;
		}
		this.eventString += currEvent;
		if(this.eventId=="c"){
			var parr = this.eventString.split("|");
			var estr = parr[parr.length-1];
			var st = estr.indexOf("$");
			var fstr = estr.substring(0,st)+"$c"+estr.substring(st+2,estr.length);
			parr[parr.length-1] = fstr;
			this.eventString = parr.join("|");
		}
		var outputData = this.getFormatedData(forced);
		this.eventString = "";
		this.firstTimeStamp = gSmUtil.getTimeSec();
		this.lastTimeStamp = gSmUtil.getTimeSec();
		if (typeof window.gsm_gemius_images == 'undefined') {
			window.gsm_gemius_images = new Array();
		}
		var gemius_l = window.gsm_gemius_images.length;
		window.gsm_gemius_images[gemius_l] = new Image();
		window.gsm_gemius_images[gemius_l].src = this.gSmHc+(new Date()).getTime()+'/redot.gif?id='+this.gSmId+'&sargencoding='+gSmConfig.ENCODING+'&sarg='+gsm_gemius_escape(outputData,1023)+gsm_gemius_parameters;
		gSmDebug.trace(["final", "sendHit",["script: "+outputData]]);
		gSmNoUnload.updateStreamExt(this.cookieId);
	}
	this.hasEvent = function(){
		this.forcedClose = true;
		if (this.eventString + this.getCurrEvent() != "") {
			return true;
		}
		return false;
	}
	this.checkLength = function(currEvent){
		if(gSmUtil.getBytesLength(this.getFormatedData()) + currEvent.length + 1 >= (gSmConfig.MAX_LOG_LENGTH + gSmConfig.VIEW_ID_LENGTH)){
			this.sendHit(currEvent);
			return true;
		}
		return false;
	}
	this.getFormatedData = function(forced){
		var out = "";
		var delta = Math.round(gSmUtil.getTimeSec() - this.firstTimeStamp);
		var forcedData = "";
		if(forced){
			forcedData = "|"+Math.round(gSmUtil.getTimeSec() - this.firstTimeStamp)+";"+Math.round(this.lastPlayTime)+";0!f";
		}
		this.infoString = "v="+gSmConfig.VERSION+"|"+this.treeIdString+"|"+this.contentIdFormated+"|"+this.duration+"|"+this.customPackageString+"|"+this.additionalPackageString+"|"+delta+forcedData;
		out = this.infoString+this.eventString;
		return out;
	}
}
var gSmPlayer = function(playerId){
	this.playerId = playerId;
	this.streamsArray = new Array();
	this.newStream = function(contentId, duration, customPackage, additionalPackage, gSmId, gSmHost, treeId){
		var stream = this.getStream(contentId, true);
		stream.newStream(duration, customPackage, additionalPackage, gSmId, gSmHost, treeId);
	}
	this.closeStream = function(contentId, time){
		var stream = this.getStream(contentId);
		if(stream == null)return;
		stream.closeStream(time);
		this.removeStream(contentId);
	}
	this.event = function(contentId, time, eventType){
		var stream = this.getStream(contentId);
		if(stream == null)return;
		stream.event(time, eventType);
	}
	this.getStream = function(contentId, forced){
		forced = (forced)?true:false;
		var stream = null;
		for(var i=0 ; i<this.streamsArray.length ; i++){
			if(this.streamsArray[i].contentId == contentId) stream = this.streamsArray[i];
		}
		if(stream == null && forced){
			stream = new gSmStream(contentId, this);
			this.streamsArray.push(stream);
		}
		return stream;
	}
	this.removeStream = function(contentId){
		for(var i=0 ; i<this.streamsArray.length ; i++){
			if(this.streamsArray[i].contentId == contentId){
				delete this.streamsArray[i];
				this.streamsArray.splice(i,1);
			}
		}
	}
	this.sendAllStreams = function(type){
		for(var i=0 ; i<this.streamsArray.length ; i++){
			this.streamsArray[i].sendStream(type);
		}
	}
	this.checkAllStreams = function(){
		for(var i=0 ; i<this.streamsArray.length ; i++){
			if(this.streamsArray[i].hasEvent())return true;
		}
		return false;
	}
	this.closeAllStreams = function(){
		for(var i=0 ; i<this.streamsArray.length ; i++){
			this.streamsArray[i].closeStreamForced();
		}
	}
}
if(!gSmConfig){
	var gSmConfig = new function(){
		this.VERSION = 6;
		this.MAX_CRITERIONS = 6;
		this.MAX_CRITERION_LENGTH = 16;
		this.MAX_CATEGORY_LENGTH = 64;
		this.MAX_TREE_ID_LENGTH = 64;
		this.MAX_ID_LENGTH = 64;
		this.VIEW_ID_LENGTH = 16;
		this.ID_RES = ["|","*","\n","\t","\r"];
		this.CRITERION_RES = ["|","*","\n","\t","\r",";","=","/","#"];
		this.CATEGORY_RES = ["|","*","\n","\t","\r",";","=","/","#"];
		this.TIMEOUT = 300;
		this.MAX_LOG_LENGTH = 990;
		this.ENCODING = "utf-8";
		this.setEncoding = function(encoding){
			this.ENCODING = encoding;
		}
	}
}
if(!gemiusStream){
	var gemiusStream = new function(){
		this.lastTimeCheck = gSmUtil.getTimeSec();
		this.init = function(){
			this.session = (new Date()).getTime().toString(36)+Math.round(Math.random()*100000000).toString(36)+Math.round(Math.random()*100000000).toString(36);
			this.flashObjectsArray = new Array();
			this.playersArray = new Array();
			if(gSmNoUnload.hasUnload()){
				if (window.addEventListener){
					window.addEventListener('unload',this.onUnload,true);
				}else if(window.attachEvent){
					window.attachEvent('onunload',this.onUnload);
				}
			}
			setTimeout("gemiusStream.timeCheck()", 1000);
		}
		this.newStream = function(playerId, contentId, duration, customPackage, additionalPackage, gSmId, gSmHc, treeId){
			if (playerId == null || contentId == null || playerId==undefined || contentId==undefined) {
				return;
			}
			if (customPackage == null) {
				customPackage = new Array();
			}
			if (additionalPackage == null) {
				additionalPackage = new Array();
			}
			if (treeId == null) {
				treeId = [];
			}
			var player = this.getPlayer(playerId);
			player.newStream(contentId, duration, customPackage, additionalPackage, gSmId, gSmHc, treeId);
		}
		this.closeStream = function(playerId, contentId, time){
			if (playerId == null || contentId == null || playerId==undefined || contentId==undefined) {
				return;
			}
			var player = this.getPlayer(playerId);
			player.closeStream(contentId, time);
		}
		this.event = function(playerId, contentId, time, eventType){
			if (playerId == null || contentId == null || playerId==undefined || contentId==undefined) {
				return;
			}
			var player = this.getPlayer(playerId);
			player.event(contentId, time, eventType);
		}
		this.getPlayer = function(playerId){
			var player = null;
			for (var i=0 ; i<this.playersArray.length ; i++) {
				if(this.playersArray[i].playerId == playerId) player = this.playersArray[i];
			}
			if(player == null){
				player = new gSmPlayer(playerId);
				this.playersArray.push(player);
			}
			return player;
		}
		this.timeCheck = function(){
			setTimeout("gemiusStream.timeCheck()", 1000);
			if (gSmUtil.getTimeSec() - gemiusStream.lastTimeCheck >= gSmConfig.TIMEOUT) {
				gemiusStream.lastTimeCheck = gSmUtil.getTimeSec();
				gSmDebug.trace(["final", "timeCheck",[]]);
				this.sendAllStreams();
			}
		}
		this.sendAllStreams = function(){
			for (var i=0 ; i<this.playersArray.length ; i++) {
				this.playersArray[i].sendAllStreams("time");
			}
		}
		this.checkAllStreams = function(){
			for(var i=0 ; i<this.playersArray.length ; i++){
				if(this.playersArray[i].checkAllStreams())return true;
			}
			return false;
		}
		this.closeAllStreams = function(){
			for(var i=0 ; i<this.playersArray.length ; i++){
				this.playersArray[i].closeAllStreams();
			}
		}
		this.registerFlashObject = function(objectId){
			if(objectId == null) return;
			for(var i=0 ; i<this.flashObjectsArray.length ; i++){
				if(objectId == this.flashObjectsArray[i]) return;
			}
			this.flashObjectsArray.push(objectId);
		}
		this.onUnload = function(){
			if(!gemiusStream.checkAllStreams())return;
			gemiusStream.closeAllStreams();
			var start = (new Date()).getTime();
			while (start+200>(new Date()).getTime());
		}
		this._viewId = 0;
		this.viewId = function(){
			return this._viewId;
		}
		this.newViewId = function(){
			this._viewId++;
			return this._viewId;
		}
		this.init();
	}
}
/*
 *
 * Session to match
 *
 */
function gsm_gemius_sarg_hit(sarg) {
	var gemius_sarg_url = gsm_gemius_host+(new Date()).getTime()+'/redot.gif?l=16&id='+gsm_gemius_identifier+'&sarg='+sarg+gsm_gemius_parameters;
	if (typeof window.gemius_sarg_images == 'undefined') {
		window.gemius_sarg_images = new Array();
	}
	var gemius_l = window.gemius_sarg_images.length;
	if (typeof gemius_sarg_sem == 'undefined') {
		gemius_sarg_sem=0;
	}
	if (gemius_l<=gemius_sarg_sem) {
		window.gemius_sarg_images[gemius_l]=new Image();
		window.gemius_sarg_images[gemius_l].src = gemius_sarg_url;
	}
	gemius_sarg_sem++;
}
function gsm_gemius_generate_STM(){
	var STM = (new Date()).getTime().toString(36)+Math.round(Math.random()*100000000).toString(36)+Math.round(Math.random()*100000000).toString(36);
	gsm_gemius_sarg_hit("SESSION_TO_MATCH="+STM);
	return STM;
}
function gsm_gemius_url(url, STM, id, catArray, enc, additional){
	additional = typeof(additional) != ('undefined'||null) ? additional : "";
	var gemius_url = url + "?SESSION_TO_MATCH=" + STM + "&MATERIAL_IDENTIFIER=" + id.toString();
	for(var i=0; i<catArray.length; ++i){
		gemius_url += "&" + catArray[i][0] + "=" + catArray[i][1];
	}
	gemius_url += "&ENCODING=" + enc + additional;
	return gemius_url;
}
