__ITContext = function(config){
	if (!window.__itcba) window.__itcba = [];
	var id=config.id =window.__itcba.length;
	if (!window.__itcuid) {
		var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
		var uid = "";
		for(x=0;x<64;x++){
			var i = Math.floor(Math.random() * 62);
			uid += chars.charAt(i);
		}
		window.__itcuid = uid;
		var oldOnload = function(){};
		if (window.onload)
			oldOnload = window.onload;
		var newOnload = function(){
			__ITContext.load();
			oldOnload();
		}
		window.onload = newOnload;
	}
	var pos = config.pos = parseInt(config.pos) || 1;
	window.__itcba[id] = new __ItcLoader(config);
}
__ITContext.load = function(id){
	var c = [];
	for(var id in window.__itcba){
		c[c.length] = window.__itcba[id].getConfig();
	}
	var uri = window.__itcba[0].getUri()+'&p='+c.join(';');
	var aj = document.createElement('script');
	aj.setAttribute('type', 'text/javascript');
	aj.setAttribute('src', 'http://context.hotline.ua/out/banner/?'+uri);
	aj.setAttribute('charset', 'utf-8');
	document.getElementsByTagName('head')[0].appendChild(aj);
}
__ITContext.get = function(id){
	return window.__itcba[id];
};
function __ItcLoader(config){
	var config = config || {};
	this.site = config.site || 1;
	this.tags = config.tags || '';
	this.cssClass = config.cssClass || '';
	this.id = config.id || 0;
	this.num = config.num || 3;
	this.pos = config.pos || 1;
	this.divid = 'itcontext_';

	this.getConfig = function(){
		return this.num+','+this.pos+','+this.id;
	};
	this.getUri = function(){
		var rnd = Math.round(Math.random()*1000000);
		return encodeURI('t='+this.tags+'&s='+this.site+'&u='+window.__itcuid+'&rnd='+rnd);
	};
	this.stripslashes = function(str) {
		str=str.replace(/\\'/g,'\'');
		str=str.replace(/\\"/g,'"');
		str=str.replace(/\\0/g,'\0');
		str=str.replace(/\\\\/g,'\\');
		return str;
	};
	this.load = function(res){
		if (res.lenght == 0){
			return;
		}
		this.div.innerHTML = this.stripslashes(res);
		this.setClass('itc_context');
		if (this.cssClass.length > 0)
			this.setClass(this.cssClass);

		this.div.style.display = '';
		return this;
	};

	this.setClass = function(cssClass) {
		if (cssClass.length > 0)
			this.div.className += (this.div.className.length > 0 ? ' ' : '') + cssClass;

		return this;
	};

	this.divid += this.id;
	document.write('<div id="'+this.divid+'" style="display:none"></div>');
	this.div = document.getElementById(this.divid);
}