function getRes () {
	return window.screen.width;
}
var im = {
	hideSky : getRes() < 1024 ? true : false,
	adAdress : 'http://ad.seznam.cz',
	adCok : navigator.cookieEnabled ? 1 : 0,
	adRef : escape(document.referrer.substr(0, document.referrer.indexOf("/", 7)) || document.referrer),
	adLang : navigator.language ? navigator.language.substr(0,2) :((navigator.language != '') ? navigator.systemLanguage.substr(0,2) : ''),
	adCharset : 'iso-8859-2',
	ads : new Object(),
	adsFolder : new Object(),
	cnt : 0,
	replaceFlag : false,
	params : new Array('zoneId','section','collocation','source'),

	
	// ***************************************************
	// vypsani SPANu s unikatnim ID pozice,
	// zjisteni parentID pro danou pozici
	// skyFlag == arguments[4] - urcuje zda se bude pri
	//     nizkem rozliseni schovat sky
	// ***************************************************
	position : function (zoneId, section, collocation, source, skyFlag) {
		if((arguments[4] && this.hideSky != true) || !arguments[4]) {
			x = this.cnt;
			this.ads[x] = new Object();
			for (i in this.params) {
				parValue = eval(this.params[i]);
				if (parValue) this.ads[x][this.params[i]] = parValue;
			}
			document.write('<div id="ad-'+x+'" style="display:none;" class="adDBox"></div>');
			this.cnt += 1;
			
			var thisDiv = this._gE('ad-'+x);
			if (thisDiv) { 
				this.adsFolder['ad-'+x] = new Array();
				this.adsFolder['ad-'+x]['position'] = thisDiv.parentNode.id;
			}
		}
	},
	
	// ***************************************************
	// Nacteni DAT z reklamniho systemu
	// ***************************************************
	loadAds : function () {
		var x=0;
		var qS = new String();
		for (i in this.ads) {
			if (qS.length > 1900) {
				document.write('<scr'+'ipt type="text/javascript" src="'+this.adAdress + "/javascript?mode=generic"+qS+"&amp;cookieEnabled=" + this.adCok + "&amp;referer=" + this.adRef + "&amp;lang=" + this.adLang+"&amp;charset=" + this.adCharset + '"></scr'+'ipt>');
				qS = '';
			}
			for (i in this.params) {
				parValue = this.ads[x][this.params[i]];
				if (parValue) qS += '&amp;'+this.params[i]+'-'+x+'='+parValue;
			}
			x+=1;
		}
		document.write('<scr'+'ipt type="text/javascript" src="'+this.adAdress + "/javascript?mode=generic"+qS+"&amp;cookieEnabled=" + this.adCok + "&amp;referer=" + this.adRef + "&amp;lang=" + this.adLang+"&amp;charset=" + this.adCharset + '"></scr'+'ipt>');
	},
	
	// ***************************************************
	// Vypsani reklam do stranky; dynamicke reklamy 
	// ulozime do uloziste
	// ***************************************************
	setAd : function (id,kod) {
		var adId = 'ad-'+id;
		if (kod.indexOf('<script') == -1) {
			if (this._gE(adId)) {
				if (kod) {
					this._gE(adId).innerHTML = kod;
					if(kod.indexOf('/impress?spotId=') != -1) {
						this._gE(adId).parentNode.className = this._gE(adId).parentNode.className == "" ? 'adFull' : this._gE(adId).parentNode.className + ' adFull';
						this._gE(adId).style.display = 'block';
					}
				}
				if (this.adsFolder[adId]) this.adsFolder[adId]['code'] = null;
			}
		} else {
			if (this.adsFolder[adId]) this.adsFolder[adId]['code'] = kod;
		}
	},
	
	// ***************************************************
	// Pro dynamicke reklamy vypise kod do stranky 
	// do daneho DIVu i ID "${pozice}Box"
	// ***************************************************
	writeAd : function(pozice) {
		for (x in this.adsFolder) {
			if ((this.adsFolder[x]['code'] != null) && (this.adsFolder[x]['position'] == pozice)) {
				//document.write('<div id="'+x+'-box" class="adDBox"></div>');
				document.write('<div id="'+x+'-box" class="adDBox">'+this.adsFolder[x]['code']+'</div>');
				var thisDiv = this._gE(x+'-box');
				if (thisDiv) {
					this.adsFolder[x]['replacePosition'] = pozice+'Box';
					thisDiv.parentNode.id = this.adsFolder[x]['replacePosition'];
					
				}
			}
		}
	},
	
	// ***************************************************
	// Presuneme reklamy, ktere jsme museli vypsat 
	// do stranky, protoze obsahovaly <script>
	// ***************************************************
	placeAds : function () {
		for (x in this.adsFolder) {
			if (this.adsFolder[x]['code'] != null) {
				var kam = this._gE(this.adsFolder[x]['position'])
				kam.innerHTML = ''; 
				kam.className = kam.className == "" ? 'adFull' : kam.className + ' adFull';
				var co = this._gE(this.adsFolder[x]['replacePosition']);
				var scriptFlag	= co.getElementsByTagName('SCRIPT');
				for ( k = 0; k < scriptFlag.length; k++ ) {
					scriptFlag[k].parentNode.removeChild(scriptFlag[k]); 
					k = k - 1;
				}
				kam.appendChild(co);
				co.style.display='block';
			}
		}
	},
	_gE : function (id) {
		return document.getElementById(id);
	}
}


