// Advent 2011 JavaScript Library
// copyright 2005-2011 Bernhard Barkow + Helga Allmer, creativeeyes.at
// we know this code won't win a beauty contest...

function getElem(s) { return document.getElementById(s); }

String.prototype.trim = function () { return this.replace(/^\s+|\s+$/g, ""); }; 

Object.prototype.extend = function(destination, source) {
	for (var property in source)
		destination[property] = source[property];
	return destination;
}

function removeClass(o,c) {	var re=new RegExp("(s*|\\b)"+c+"(\\b|$)"); o.className = o.className.replace(re,''); }
function addClass(o,c) { var re=new RegExp("(^|\\b)"+c+"(\\b|$)"), b=!re.test(o.className); if(b) o.className += " "+c; return b; }

CEJU = function() {};

CEJU.Cookie = function(s) {
	this.name = s;
	
	this.get = function(s) {
		var c, t=this.name+"=", ca=document.cookie.split(';'), i;
		for(i=0; i<ca.length; i++) {
			c=ca[i].trim();
			if(c.indexOf(t) == 0) return c.substring(t.length,c.length);
		} return null;
	};
	this.set = function(v) {
		document.cookie = this.name+"="+v+"; expires="+(new Date(thisYear+1,5,1)).toGMTString()+"; path=/";
	};
	this.reset = function(b) {
		this.set(""); if (b) location.reload();
	};
};

CEJU.viewportSize = function() {
	var d=document, b=d.body, e=d.documentElement, x, y;
	if (window.outerHeight) { x = window.outerWidth; y = window.outerHeight; } // !IE
	else if (e && e.clientHeight) { x = e.clientWidth; y = e.clientHeight; } // IE6 Strict
	else if (b) { x = b.clientWidth; y = b.clientHeight; } // other IEs
	return [x, y];
}
 
function init() {
	advCookie = new CEJU.Cookie(advCk);
	var o, i, tmpO=advCookie.get(), w, db=document.body, bs;
	for(i=0; i<advDay; i++) { o=getElem('winLink'+i); if(o!=null) {
			o.imgN=i; o.onclick=function(){ showDay(this) }; 
			if (miFn[i]) o.thmbPic=thmbImgDir+miFn[i];
		} }
	initA();
	//arrangeCalWindows();
	for (i=0; i<24; i++) openedPics[i]=0;
	if(tmpO) { tmpO=tmpO.split(','); for(i=0; i<tmpO.length; i++) if(tmpO[i]!=0) openedPics[i]=1; }
	bbMM_preloadImages();
	md=getElem("mainDiv");
	Object.extend(md, new CEJU.opacitor(dtOp, ziDt));
	Object.extend(md, new CEJU.mainArea(getElem("mainImg"), getElem("mainDiv2"), getElem("bg"), null));
	md.shadow = getElem("calBG");
	var sbl=getElem("sbLeft");
	Object.extend(sbl, new CEJU.pulsor(dtPulse0, dtPulse1, sbl.offsetWidth, dtOp));
	sbl.startPulse();
	/*if (mt = getElem("medTimer")) {
		Object.extend(mt, new CEJU.blocker(t0Medit*1000, 640, getElem("bar"), getElem("blockArea"))); 
		Object.extend(mt.bar, new CEJU.opacitor(2.5*dtOp, ziDt)); 
		if (mt.bar.note = getElem("medNote")) Object.extend(mt.bar.note, new CEJU.opacitor(1.5*dtOp, ziDt));
		mt.flash = function() { this.bar.flash(); this.bar.note.flash(); }
		md.pBar = mt;
	}*/
	setVisID('ctrl',true);
	initKeywords();
	// font size correction:
	w=getElem("h1link").offsetWidth;	// pfui!!!
	bs=(window.getComputedStyle ? window.getComputedStyle(db,"") : db.currentStyle);
	if (w>163) db.style.fontSize=Math.round(parseInt(bs.fontSize)*163/w)+"px";

	if (window.opera) { history.navigationMode='compatible'; }
	window.onbeforeunload = function() { return (lang=="en" ? "Back to your daily routine?" : "Zurück in die Alltagshektik?"); }
	//window.onresize = windowResized;
}
function initA(n) {
	var i,d=document,o=d.getElementsByTagName('A'), x, a;
	for (i=o.length-1; i>=0; i--) {
		a = o[i];
		if (a.className == 'nojs') {
			x = d.createTextNode(a.firstChild.nodeValue);
			a.parentNode.replaceChild(x, a);
		} else if (a.className == 'popupLink') {	// prepare the info areas for fading
			x = a.firstChild;
			Object.extend(x, new CEJU.opacitor(dtOp, ziDt));
			x.hideOp();
			x.style.display = "block";
			a.onmouseover = function() { this.firstChild.startFade(this.firstChild, dOp, null); };
			a.onmouseout = function() { this.firstChild.startFade(this.firstChild, -dOp, null); };
		}
	}
}

function initKeywords() {
	var i,k=kwAr.length/2,tmp=Array(); for (i=0; i<k; i++) { tmp[i] = i; }
	for (i=0; i<k; i++) { kwRem[i] = tmp.splice(Math.floor(Math.random()*tmp.length), 1); } //.999*
	if (kwRem[k-1] == curKW/2) kwRem.reverse();
	for(i=0; i<2; i++) {
		kwFields[i]=getElem('lightDescr'+(i+1));
		Object.extend(kwFields[i], new CEJU.opacitor(dtOp, ziDt));
		kwFields[i].setOp(0);
		kwFields[i].clearInt();
	}
	kwFields[1].setVis(true);
	fadeKeywords();
}
function fadeKeywords() {
	var t; if(kwPhase==1 || kwPhase==3) t=dtKW; else t=dtKWF;
	if(kwFields[0].intID==0 && kwFields[1].intID==0) {
		if(kwPhase==0) { switchKeywords(); kwFields[0].startFade(kwFields[0], dOpKW, null); }
		else if(kwPhase==2) { kwFields[0].startFade(kwFields[0],-dOpKWC, null); kwFields[1].startFade(kwFields[1], dOpKWC, null); }
		else if(kwPhase==4) kwFields[1].startFade(kwFields[1],-dOpKW, null);
		if (kwPhase++ > 4) kwPhase=0;
	}
	window.setTimeout(fadeKeywords, t);
}
function switchKeywords() {
	getElem("keywords").style.left = Math.round(Math.random()*90)+"%";
	if(kwRem.length <= 0) initKeywords();
	curKW = 2*kwRem.pop()+1;
	for(var i=0; i<2; i++) kwFields[i].firstChild.nodeValue=kwAr[curKW++ % kwAr.length];
}

function cleanup() {
	kwFields[0].clearInt(); kwFields[1].clearInt();
	if(md.pBar) md.pBar.deactivate();
}
function checkMedit(o) {
	if(o.pBar) if(o.pBar.active) { o.pBar.flash(); return false; }
	return true;
}

function resetCal() { advCookie.reset(true); };
function storeCk(i) {
	if (openedPics[i] != 1) { openedPics[i] = 1; advCookie.set(openedPics.toString()); }
}

function showDay(o) {
	if (md != null && md.mainImg != null) {
		storeCk(o.imgN);
		o.className=o.className.replace(/[\s]?closed\b/,"");
		md.initView(o);
		if (md.mainImg.src.indexOf(miFn[o.imgN])>0) md.startZoomIn();
		else { md.mainImg.onload=function() {md.startZoomIn()}; md.mainImg.src=imgDir+miFn[o.imgN]; }
		md.show();
		md.setCaption(imgCaptions[o.imgN]);
	}
}

CEJU.mainArea = function(mi, ta, bg, ca) {
	this.mainImg = mi;
	this.textPage = ta;
	this.bg = bg;
	this.caption = ca;
	this.miWmin=miWmin;
	this.miHmin=miHmin;
	this.miW=this.miWmin;
	this.miH=this.miHmin;
	this.miX=miX;
	this.miY=miY;
	this.miXMax=0;
	this.w0=0;
	this.h0=0;
	this.w1=miW1;
	this.h1=miH1;
	this.imgN = 0;
	this.pBar = null;
	this.shadow = null;

	this.init = function() {
		Object.extend(this.mainImg, new CEJU.opacitor(dtOp, ziDt));
		this.mainImg.setOp(1.);
		if (this.textPage) {
			Object.extend(this.textPage, new CEJU.opacitor(dtOp, ziDt));
			//this.textPage.setVisD(false);
			this.textPage.setOp(1.);
		}
		if (this.bg) {
			Object.extend(this.bg, new CEJU.opacitor(dtOp, ziDt));
			this.bg.maxOp = .93;
			this.bg.hideOp();
		}
		if (this.caption) {
			Object.extend(this.caption, new CEJU.opacitor(dtOp, ziDt));
			this.caption.setVis(false);
		}
	};
	
	this.hide = function() {
		this.setVis(false); 
		if (this.bg) this.bg.setVis(false);
		this.mainImg.setVisD(true); this.mainImg.setVis(true); this.mainImg.setOp(1.);
		if (this.textPage) this.textPage.setVis(false);	//{ this.textPage.setVisD(false); this.textPage.hideOp(); }
		if (this.shadow) removeClass(this.shadow, "noShadow");
	};
	this.show = function() {
		this.setVis(true);
		if (this.textPage) this.textPage.setVis(true);
	};
	this.initView = function(o) {
		this.imgN = o.imgN;
		this.setCaption();
		this.sx0 = BB_findX(o)+.5*o.offsetWidth;
		this.sy0 = BB_findY(o)+.5*o.offsetHeight;
		this.imgN = o.imgN;
		this.sz=0;
	};
	this.setCaption = function() { if (this.caption) this.caption.firstChild.nodeValue = imgCaptions[this.imgN]; };
	
	this.startZoomIn = function() {
		this.calcImgPos();
		this.setCaptionPos();
		if (this.shadow) addClass(this.shadow, "noShadow");
		this.startAnim(this.zoomIn, this.ziDt, this.ziDs);
		if (this.bg) this.bg.setVis(true);
		if (this.textPage) {
			loadContent(this.imgN+1,lang);	// load text after img
			this.textPage.setOp(1.);
		}
	};
	
	this.calcImgPos = function() {
		// calculate final image size:
		this.miW = this.mainImg.width+2;  if(this.miW<100 && this.miWmin>0) this.miW=this.miWmin;
		this.miH = this.mainImg.height+2; if(this.miH<100 && this.miHmin>0) this.miH=this.miHmin;
		// now calculate the origin:
		var d=document, b=d.body, e=d.documentElement, x, y;
		if (window.innerHeight) { x = window.innerWidth; y = window.innerHeight; } // !IE
		else if (e && e.clientHeight) { x = e.clientWidth; y = e.clientHeight; } // IE6 Strict
		else if (b) { x = b.clientWidth; y = b.clientHeight; } // other IEs
		this.miX = (x - this.miW)/2+100; if(this.miX<0) this.miX=100;
		this.miY = (y - this.miH)/2; if(this.miY<0) this.miY=0;
		this.style.left = this.miX+"px";
		this.style.top  = this.miY+"px";
		this.miXMax = x;
	};
	this.setCaptionPos = function() {
		if (this.caption) {
			var o = this.caption.style;
			o.top = (this.miY+this.miH)+"px"; o.right = this.miX+"px";
		}
	};
	
	this.mapZoomIn  = function(s) { return (1.-Math.cos(s*3.141))*.5; }
	this.mapZoomOut = function(s) { return Math.pow(s,3.); }
	
	this.zoomUpdateHandler = function(sz) {
		if (this.bg) { if(sz<.9) this.bg.setOp(1.5*sz*this.bg.maxOp); };
		if (this.textPage) {
			var dx = (this.miX-214) - this.sx0, tmpA = this.sx0, tmpC = tmpA*dx;
			var bb = -2*tmpA - Math.sqrt(4*tmpA*tmpA-tmpC);
			var aa = dx - bb;
			var xPos = aa*sz*sz + bb*sz + this.sx0;
			this.textPage.setSize(this.offsetWidth*186./this.mainImg.width, this.offsetHeight, xPos, this.offsetTop, 1);
			if (sz>.99) {
				var ll = getElem("rlinks");
				setVis(ll, true);
				ll.style.left = xPos+"px";
				ll.style.top  = (this.offsetTop + this.offsetHeight)+"px";
			}
		};
	};
	this.zoomInDoneHandler = function() {
		if (this.pBar) this.pBar.activate();
	};
	
	this.hidePic = function() {
		if (!checkMedit(this)) return;
		if(false && this.textPage && this.textPage.style.display == "none") {	// swap
			this.miW=this.w1; this.miH=this.h1;	//target size
			if (this.caption) this.caption.setVis(false);
			this.mainImg.startFade(this.mainImg, -dOpImg, .2);
			this.textPage.hideOp();
			this.textPage.setVisD(true);
			this.textPage.startFade(this.textPage, dOpImg, null);
			this.startAnim(this.zoomChange, this.ziDt, this.ziDs);
			setVisID("rlinks", true);
			setVisID("rbtns", (this.textPage.offsetHeight > this.offsetHeight));
		} else {	// hide
			this.miW=0; this.miH=0;	//target size
			this.startAnim(this.zoomIn, this.ziDt, zoDs);
			if (this.caption) this.caption.setVis(false);
			setVisID("rlinks", false);
			setVisID("rbtns", false);
		}
	};

	this.init();
}
CEJU.opacitor = function(dtOp, ziDt) {
	this.bbOp = 1;
	this.ziID = 0;
	this.intID = 0;
	this.dtOp = dtOp;
	this.ziDt = ziDt;
	this.ziDs = ziDs;
	
	this.setVis = function(b) { this.style.visibility=(b ? "visible" : "hidden"); };
	this.setVisD = function(b) { this.style.display=(b ? "block" : "none"); };
	this.hideOp = function() { this.setOp(0); this.setVis(false); };
	
	this.setOp = function(op) {	// returns true on error
		if (this.style.opacity != null) this.style.opacity = op;
		else if (this.filters != null) { this.style.filter='progid:DXImageTransform.Microsoft.Alpha(opacity='+(op*100)+')'; }
		else if (this.style.MozOpacity != null) this.style.MozOpacity = op;	//Math.min(op,.999);	// Mozilla bug
		else if (this.style.KhtmlOpacity != null) this.style.KhtmlOpacity = op;
		else return true;
		this.bbOp=op;
		return false;
	};
	this.changeOp = function(that, d, opf) {
		var b=false, opf1, tmpOp, c;
		if(typeof (that.bbOp) == "undefined") that.bbOp=.05;
		tmpOp = that.bbOp+d;
		if (opf==null) opf1 = (d>0 ? 1. : .05); else opf1=opf;
		if ((d>0 && tmpOp>=opf1) || (d<0 && tmpOp<opf1)) { tmpOp=opf1; b=true; }
		c=that.setOp(tmpOp);
		if (b || c) {
			that.clearInt(); if(d<0 && opf==null) that.setVis(false);
		}
	};
	this.clearInt = function() { if (this.intID) window.clearInterval(this.intID); this.intID=0; };

	this.startAnim = function() {
		var a = this.startAnim.arguments, l = a.length;
		this.clearInt();
		if (l==3) this.intID = window.setInterval(a[0], a[1], this, a[2]);
		else if (l==4) this.intID = window.setInterval(a[0], a[1], this, a[2], a[3]);
		else if (l==2) this.intID = window.setInterval(a[0], a[1], this);
		else this.intID = window.setInterval(a[0], this.ziDt, this);
	};

	this.zoomIn = function(that, ds) {
		var sz=that.sz+ds, sz2, sz3, b=false,
		x0 = that.sx0, y0 = that.sy0, w0 = that.w0, h0 = that.h0,
		h = that.miH, w = that.miW, dx = that.miX-x0, dy = that.miY-y0;
		if(ds > 0 && sz >= 1.) { sz=1.; b=true; }
		else if(ds < 0 && sz <= 0.) { sz=0.; b=true; }
		if(ds>0) sz2=that.mapZoomIn(sz); else sz2=that.mapZoomOut(sz);

		var tmpA = x0-that.miXMax, tmpC = tmpA*dx;
		var bb = -2*tmpA+Math.sqrt(4*tmpA*tmpA-tmpC);
		var aa = dx - bb;
		var xPos = aa*sz2*sz2 + bb*sz2 + x0;
		
		if(ds>0) that.setSize(w0+sz2*(w-w0), h0+sz2*(h-h0), xPos, y0+dy*sz2, 0);//x0+dx*sz2*sz2
		else {
			sz3 = Math.pow(sz2,.7);
			that.setSize(sz2*w0, sz2*h0, x0+dx*sz3, y0+dy*sz3, 0);
		}
		that.sz=sz;
		if (that.zoomUpdateHandler) that.zoomUpdateHandler(sz);
		if (!b) { /*that.ziID = window.setTimeout(that.zoomIn, ziDt, that, ds);*/ }
		else {that.clearInt();
			that.w0=w; that.h0=h;
			if (ds<0) that.hide();
			else {
				if (that.caption) that.caption.setVis(true);
				if (that.zoomInDoneHandler) that.zoomInDoneHandler();
			};
		}
	};
	this.zoomChange = function(that, ds) {
		var sz=that.sz+ds, sz2, b=false, w, h;
		if(ds > 0 && sz >= 1.) { sz=1.; b=true; }
		else if(ds < 0 && sz <= 0.) { sz=0.; b=true; }
		if(ds>0) sz2=that.mapZoomIn(sz); else sz2=that.mapZoomOut(sz);
		w=that.w0+sz2*(that.miW-that.w0);
		h=that.h0+sz2*(that.miH-that.h0);
		if(ds>0) that.setSize(w, h, that.offsetLeft+(that.offsetWidth-w)/2, that.offsetTop+(that.offsetHeight-h)/2, 0);
		that.sz=sz;
		if (!b) { /*that.ziID = window.setTimeout(that.zoomChange, ziDt, that, ds);*/ }
		else { that.clearInt(); that.w0=that.miW; that.h0=that.miH; }
	};
	this.setSize = function() {	//w, h, x, y, b
		var a=this.setSize.arguments, o=this.style, s="px";
		o.width=a[0]+s;
		o.height=a[1]+s;
		o.left=a[2]+s;
		o.top=a[3]+s;
		o.borderWidth=a[4]+s;
	};
	
	this.startFade = function(that, d, of) {
		that.clearInt(); if(d>0) that.setVis(true);
		that.startAnim(that.changeOp, that.dtOp, d, of);
	};
	
	this.flash = function() {
		this.setVis(true); this.setOp(1.); this.startFade(this, -dOpFlash, null);
	}
}

CEJU.blocker = function(t0, w, bar, area) {
	this.t0 = t0;
	this.w = w;
	this.dt = Math.max(10, Math.floor(t0/w));
	this.t = 0.;
	this.bar = bar;
	this.area = area;
	this.active = false;
	this.time0 = 0.;
	this.firstView = true;
	
	this.activate = function() {
		if (!this.firstView) return;
		this.firstView = false;
		this.active = true;
		this.area.style.display = "block";
		this.time0 = new Date();
		var that = this;
		this.area.onclick = function(e) { that.flash(); return false; };
		this.intID = window.setInterval(this.adjust, this.dt, this);
	};
	this.deactivate = function() { if(this.intID) window.clearInterval(this.intID); this.active = false; this.area.style.display = "none"; };
	
	this.adjust = function(that) {
		var p = 100. * (1. - (new Date().valueOf() - that.time0) / that.t0);	// use real time instead of increments
		if (p < 0) p = 0;
		that.bar.style.width = p+"%";
		if (p<=0) that.deactivate();
	};
}

CEJU.pulsor = function(dt, t1, w, dtAnim) {
	this.t1 = t1;
	this.dt = dt;
	this.w = w;
	this.dtAnim = dtAnim;
	this.intID =0;
	this.t = 0;
	
	this.startPulse = function() {
		this.intID = window.setInterval(this.pulse, this.dtAnim, this);
	};
	this.stopPulse = function() {
		if (this.intID) window.clearInterval(this.intID); this.intID=0;
	};
	this.pulse = function(that) {
		that.t += that.dtAnim;
		if (that.t > that.t1) that.t = 0;//approx. periodic
		var x = 1.; if (that.t < that.dt) x -= Math.pow(Math.sin((that.t-that.dt)*(Math.PI)/that.dt), 4.);
		that.setWidth(that.w*x);
	};
	this.setWidth = function(w) {
		this.style.width = w+"px";
	};
}

function setVis(o,b) { o.style.visibility=(b ? "visible" : "hidden"); }
function setVisID(s,b) { var o=getElem(s); if (o!=null) setVis(o,b); }

function bbMM_preloadImages() { //v3.1
  var d=document, i, j; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    j=d.MM_p.length; for(i=miFn.length-1; i>=0; i--)
    	if (miFn[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=imgDir+miFn[i];}}
}

function BB_findX(o) {
	var x=0; if(o.offsetParent) { while (o.offsetParent) { x+=o.offsetLeft; o=o.offsetParent; }
  } else if (o.x) x+=o.x; return x;
}
function BB_findY(o) {
	var y=0; if(o.offsetParent) { while (o.offsetParent) { y+=o.offsetTop; o=o.offsetParent; }
  } else if (o.y) y+=o.y; return y;
}

function printContent(e) {
	var evt = e || window.event;
	if (bCanPrint) print();
	else location.href = sPrintPage+"d="+(md.imgN+1);
	if (!stopEvtBubbling(evt)) return false;
}

function openExt() { location.href = sNoJSPage+"d="+(md.imgN+1); }

function switchLang(e) {
	var evt = e || window.event, o=getElem("btnLang"), lang=o.firstChild.nodeValue;
	loadContent(md.imgN+1, lang);
	lang = (lang=="en" ? "de" : "en");
	o.firstChild.nodeValue = lang;
	if (!stopEvtBubbling(evt)) return false;
}

function getEvtSrc(e) { return e.target || e.srcElement; }
function stopEvtBubbling(e) {
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	return true;
	if (e.returnValue) {
		e.returnValue = false;
	} else if (e.preventDefault) {
		e.preventDefault();
	} else {
		return false;
	}
	return true;
}

// XML
function loadContent(d,l) {
	makeRequest("dcontent11.php?y="+thisYear+"&d="+d+(l ? "&lang="+l : ""));
}

function getHTTPObj() {
	var req = false;
	if (window.XMLHttpRequest && !(window.ActiveXObject)) {
		try { req = new XMLHttpRequest(); }
		catch(e) { req = false; }
	} else if(window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
					req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
					req = false;
			}
		}
	}
	return req;
}

function makeRequest(u) {
	if(httpReq) {
		//if(reqActive) 
		httpReq.abort();
		httpReq.onreadystatechange = processReqChange;
		httpReq.open("GET", u, true);
		httpReq.send(null);
		reqActive=true;
	}
}

function processReqChange() {
	if (httpReq.readyState == 4) { // "loaded"
		reqActive = false;
		if (httpReq.status == 200) {	// "OK"
			md.textPage.innerHTML = httpReq.responseText;
			//BB_resetScrollingO(md.textPage);
			configureLinks(md.textPage);
		}
	}
}

function configureLinks(o) {
	var a=o.getElementsByTagName('A'), n=a.length, i;
	for (i=0; i<n; i++) {
		a[i].onmouseup=function(e) { var evt = e || window.event; if (!stopEvtBubbling(evt)) return false; }
	}
}

// the calendar window class
function CalWindow(o) {
	this.elem = null;
	this.xMin = 0;
	this.yMin = 0;
	this.xMax = 0;
	this.yMax = 0;

	this.init = function(o) {
		this.elem = o;
		this.xMin = .5*this.elem.offsetWidth;
		this.yMin = .5*this.elem.offsetHeight;
		this.initBounds();
	};
	this.initBounds = function() {
		this.xMax = this.elem.offsetParent.offsetWidth - .5*this.elem.offsetWidth;
		this.yMax = this.elem.offsetParent.offsetHeight - .5*this.elem.offsetHeight;	
	}
	this.getX = function() { return this.elem.offsetLeft + .5*this.elem.offsetWidth; }
	this.getY = function() { return this.elem.offsetTop + .5*this.elem.offsetHeight; }
	this.getR = function() { return .5*(this.elem.offsetWidth + this.elem.offsetHeight);	} // simple approx.
	
	this.restrictPos = function(x, y) { return [Math.min(Math.max(x,this.xMin),this.xMax), Math.min(Math.max(y,this.yMin),this.yMax)]; }
	this.setPos = function(x,y) {
		var p=this.restrictPos(x, y);
		this.elem.style.left = (p[0] - .5*this.elem.offsetWidth) +"px";
		this.elem.style.top  = (p[1] - .5*this.elem.offsetHeight)+"px";
	}
	this.translateXY = function(dx,dy) { this.setPos(this.getX()+dx, this.getY()+dy); }
	
	this.distanceToC = function(o) {
		var dx = this.getX() - o.getX(), dy = this.getY() - o.getY();
		return Math.sqrt(dx*dx+dy*dy);
	}
	this.distanceTo = function(o) { return (this.distanceToC(o) - o.getR() - this.getR()); }
	this.touchedBy = function(o) { return (this.distanceTo(o) < 0); }
	
	this.keepOff = function(o, d) {	// object, distance
		var rc = this.distanceToC(o), r = rc - o.getR() - this.getR(), dr, dx, dy;
		if (r >= d) return;
		else {
			if (Math.abs(rc)<1.) rc = 1.;
			dr = d-r;
			dx = (this.getX() - o.getX())/rc; dy = (this.getY() - o.getY())/rc;
			this.translateXY(.5*dr*dx, .5*dr*dy);
			o.translateXY(-.5*dr*dx, -.5*dr*dy);
		}
	}
	
	this.distF1 = function(x) { return 2.*x*x*x - 3.*x*x + x; }
	this.pushFrom = function(xm,ym) {
		var x=this.getX(), y=this.getY(),
			dx = x-xm, dy=y-ym, dxx=Math.abs(1.25*dx/this.xMax), dyy=Math.abs(1.25*dy/this.yMax),
			fx = this.distF1(dxx) * (-dx),
			fy = this.distF1(dyy) * (-dy),
			sf = -1.;
		this.translateXY(sf*fx, sf*fy);
	}
	
	this.init(o);
}

function moveWindows(e) {
	var ev=e || window.event, c=getElem("cal"),
		x=ev.clientX - c.offsetLeft, y=ev.clientY - c.offsetTop,	// mouse pos.
		a=document.calWindows, na=document.calWindows.length, o, k, l;
	for(k=0; k<na; k++) {
		o=a[k];
		o.pushFrom(x,y);
		for (l=0; l<na; l++) o.keepOff(a[l], 0);// l=k+1??
	}
}

function windowResized() {}

// global variables:
var ziID=0, ziDt=40, ziDs=.05, zoDs=-.07, dOp=.08, dtOp=40, dOpKW=.05, dOpKWC=.05, dOpImg=.15, dtKW=1500, dtKWF=500, dOpFlash=.03, dtPulse0=250, dtPulse1=2500,
bg=null, md=null, md2=null, miCaption=null,
miWmin=600, miHmin=600, miW=miWmin, miH=miHmin, miX=100, miY=100, miW1 = 500, miH1 = 500,
miFn=Array(),
kwAr=Array(), kwRem=Array(), kwFields=Array(),
openedPics=Array(),
curKW=0, kwPhase=0,
imgDir="img11/", thmbImgDir="img11/thmb/", advDay=0, thisYear=2011,
lang="en", bCanPrint=false, sNoJSPage="pgnojs11.php?i=1&", sPrintPage="pgnojs11.php?pr=1&i=1&",
advCookie, t0Medit = 2, mt,
httpReq = getHTTPObj(), reqActive=false;

