function GetElem(_id) {
	var e = document.getElementById(_id);
	if (e == null) {
		//alert("bad id '" + _id +"'");
		return null;
	} else
		return e;
}

function InArray(_item, _array) {
    var i = 0, f = -1;
    
    for (i = 0; i < _array.length; i++)
        if (_item == _array[i]) {
            f = i;
            break;
        }
        
    return f;
}

function AddClass(_el, _cl) {
	if (_el != null)
		_el.className += " " + _cl;
}

function RemoveClass(_el, _cl) {
	if (_el == null) return;
	var ta = _el.className.split(' ');
	var idx = InArray(_cl, ta);
	if (idx != -1) { 
		ta.splice(idx, 1);
		_el.className = ta.join(' ');
	}
}

function MenuSwitcher(_id, _class, _h) {
	this.el = null;
	if (!(this.el = GetElem(_id))) {
		alert("MenuSwitcher: bad id '" + _id + "'");
		return;
	}
	
	if (_h != undefined)
		this.hideSelf = _h
	else 
		this.hideSelf = false;
	this.el.className = this.el.className + " menu_switcher";

	this.classActive = _class;
	this.buts = new Array();
	this.boxes = new Array();

	this.AddPair = function (_but, _box) {
		var but = box = null;
		if (!(but = GetElem(_but))) return;
		if (!(box = GetElem(_box))) return;

		var ta = but.className.split(' ');
		if (InArray(this.classActive, ta) == -1)		
			box.style.display = "none";

		but.ref = this;
		but.onclick = function () {
			var idx = -1;
			var ta = null;
			//alert(this.ref.hideSelf);
			for (var i = 0; i < this.ref.buts.length; i++) {
				if ((this.ref.buts[i] != this) || (this.ref.hideSelf && (this.ref.boxes[i].style.display == "block"))) {
					this.ref.boxes[i].style.display = "none";
					RemoveClass(this.ref.buts[i], this.ref.classActive);
				} else {
					this.ref.boxes[i].style.display = "block";
					this.className += " " + this.ref.classActive;
				}
			}
		}
		
		this.buts.push(but);
		this.boxes.push(box);
	}	
}

/**
 * _w - wrap
 * _t - title
 * _c - content 
 */ 
function Vyjizdec (_w, _t, _c, _t2) {
	/*if (SJEL.ie) {
		this.w = SJEL.$(_w);
		SJEL.RemoveClass(this.w, "nojs");
		var ms = new MenuSwitcher(_w, 'opened', true);
		ms.AddPair(_t, _c);
		return;
	}*/
	this.w = SJEL.$(_w);
	this.t = SJEL.$(_t);
	this.c = SJEL.$(_c);
	this.t2 = null;
	if (_t2 != undefined)
		this.t2 = SJEL.$(_t2);
	if (!this.w || !this.t || !this.c)
		return;
	
	var cc = this.c;
    this.mo = new SJEL.Morph();
    this.ch = 0;
    this.o = false;  // otevreny
    
	SJEL.RemoveClass(this.w, "nojs");
	
	this.Close = function () {
		this.mo.Init(this.c, {opacity: 0.0}, 180);
		this.mo.OnMorphFinished(function(){SJEL.SStyle(cc, {display: "none"});});
		this.mo.Morph();
		this.o = false;
		RemoveClass(this.w, "opened");
	}
	
	this.t.ref = this;
	this.t.onclick = function () {
		if (!this.ref.o) {
			SJEL.SStyle(this.ref.c, {display: "block", opacity: 0.0, overflow: "hidden"});
			this.ref.mo.Init(this.ref.c, {opacity: 1.0}, 180);
			this.ref.mo.OnMorphFinished(function(){});
			this.ref.mo.Morph();
			this.ref.o = true;
			AddClass(this.ref.w, "opened");
		} else
			this.ref.Close();
	}
	
	if (this.t2 != null) {
		this.t2.ref = this;
		this.t2.onclick = function () {
			if (this.ref.o)
				this.ref.Close();
		}
	}
}