

function include() {
	var head = document.getElementsByTagName('head').item(0);
	var d = new Date();
	for(var i=0;i<arguments.length;i++) {
	    var js = document.createElement('script');
	    js.setAttribute('language', 'javascript');
	    js.setAttribute('type', 'text/javascript');
	    js.setAttribute('src', '/js/'+arguments[i]+"?"+parseInt(d.getTime()) );
	    head.appendChild(js);
	}
    return false;
}

function addEventSlip(obj, evType, fn, useCapture) {
	if (obj.addEventListener) {
		obj.addEventListener(evType,fn,useCapture);
		return true;
	} else if(obj.attachEvent){
		return obj.attachEvent("on"+evType,fn);
	} else {
		return false;
	}
}

function xgetElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if (node == null) node = document;
	if (tag == null) tag = '*';
	var elems = node.getElementsByTagName(tag);
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	var i = 0;
	for (var j = 0; j < elems.length; j++) {
		if ( pattern.test(elems[j].className) ) {
			classElements[i++] = elems[j];
		}
	}
	return classElements;
}

function xgetFirstElementByClass(searchClass,node,tag) {
	if (node == null) node = document;
	if (tag == null) tag = '*';
	var elems = xgetElementsByClass(searchClass,node,tag);
	if (elems.length > 0) return elems[0];
	return null;
}



function h1modif (str) {
	var h1 = document.getElementById('h1');
	h1.innerHTML = str;
}
function toInt(n) {
	n = n.toString();
	return n.replace(/[^0-9.,]/ig,'') * 1;
}


/**********************************************************/

/*** SPEC expandable ***/

var expTimer = null;
var expandable = null;
var expandable_DL = null;
function expandableInit() {
	expandable = xgetFirstElementByClass('expandable');
	if (!expandable) return;
	expandable_DL = expandable.getElementsByTagName("dl");
	if (!expandable_DL) return;
	// active beállítás a # alapján
	var loc = document.location+"";
	var id = loc.substring(loc.lastIndexOf('#')+1);
	if (loc.lastIndexOf('#') == -1) { id = 0; }
	var dl_active = xgetElementsByClass('active',expandable, 'dl');
	// ha nincs active:
	if (!dl_active.length) {
		var dl = expandable.getElementsByTagName('dl');
		if(dl[id]) {
			dl[id].className = "active "+dl[id].className;
		}
	}
	var dt = expandable.getElementsByTagName("dt");
	for(var j = 0; j < dt.length; j++) {
		actuationAttributeInit( dt[j].parentNode );
		dt[j].onclick = function() {
			var pDL = parentDL(this.parentNode.parentNode.parentNode);
			if (this.parentNode.getAttribute('aim') > 0) {
				this.parentNode.setAttribute('aim', 0);
				this.parentNode.className = this.parentNode.className.replace(/active/ig,'');
				if (pDL) {
					pDL.setAttribute('max', parseInt(pDL.getAttribute('aim'))-parseInt(this.parentNode.getAttribute('max')))
					pDL.setAttribute('aim', pDL.getAttribute('max'));
				} else {
					// a max érték kapja meg az eredeti értéket:
					this.parentNode.setAttribute('max', this.parentNode.className.substring(this.parentNode.className.indexOf('height')+6));
				
				}
			} else {
				this.parentNode.className += ' active';
				this.parentNode.setAttribute('aim', this.parentNode.getAttribute('max'));
				// a szülő növelése:
				if (pDL) {
					// ha több van a pDL-ben, akkor az eredeti értéket kell kapnia a max-nak (ha egy van, akkor egy felesleges utasítás csupán)
					pDL.setAttribute('aim', pDL.className.substring(pDL.className.indexOf('height')+6));
					pDL.setAttribute('max', parseInt(pDL.getAttribute('aim'))+parseInt(this.parentNode.getAttribute('max')));
					pDL.setAttribute('aim', pDL.getAttribute('max'));
				}
			}
			// a többi becsukása:
			for(var k = 0; k < expandable_DL.length; k++) {
				if(expandable_DL[k] != this.parentNode && expandable_DL[k] != pDL) {
					expandable_DL[k].setAttribute('aim', 0);
					expandable_DL[k].className = expandable_DL[k].className.replace(/active/ig,'');
					expandable_DL[k].setAttribute('max', expandable_DL[k].className.substring(expandable_DL[k].className.indexOf('height')+6));
				}
			}
			if (!expTimer) expTimer  = setInterval("expandableTimer()", 5);
			return false;
		}
	}
	expTimer  = setInterval("expandableTimer()", 5);
}
addEventSlip(window, 'load', expandableInit);

function expandableTimer() {
	var l = false;
	for(var j = 0; j < expandable_DL.length; j++) {
		if( actuation(expandable_DL[j], expandable_DL[j].getElementsByTagName("dd").item(0)) ) {
			l = true;
		}
	}
	if (!l) {clearInterval(expTimer); expTimer = null; }
}

/** Aloldal: menü */



// mozgatás(mozgató elem, mozgatott elem)
// visszatérés: volt-e mozgás
function actuation(_parent, _target) {
	// az a magasság, ameddig maximálisan nőhet:
	var max = _parent.getAttribute('max');
	// az a magasság, ami a cél: (0 vagy max)
	var aim = _parent.getAttribute('aim');
	// ha a cél megegyik az aktuális magassággal, akkor kilépünk:
	if (aim == _target.offsetHeight) return false;
	// sebesség
	var s = Math.round(Math.abs(_target.offsetHeight-aim)/5)+1;
	// magasság:
	var h = _target.offsetHeight+ ((_target.offsetHeight > aim)?-s:s);
	h = Math.min(max, Math.max(0,h));
	_target.style.height = h+'px';
	
	// átlátszóság:
	if(is_ie) {
		_target.style.filter = 'alpha(opacity='+(h/max)*100+')';
	} else {
		_target.style.opacity = (h/max);
	}
	// ellenőrzés:
	//_target.innerHTML = 'max: '+max+', aim: '+aim+', height: '+_target.offsetHeight;
	return true;
}

// A max és aim attributumok beállítása a height és a active osztály segítségével:
function actuationAttributeInit(item) {
	if (item.className.indexOf('height') != -1) {
		item.setAttribute('max', item.className.substring(item.className.indexOf('height')+6));
	} else {
		item.setAttribute('max', 100);
	}
	if (item.className.indexOf('active') != -1) {
		item.setAttribute('aim', item.getAttribute('max') );
	} else {
		item.setAttribute('aim', 0);
	}
}

// visszaadja, az őt tartalmazó expandable node-t.
function parentDL(item) {
	if (item == document.body) return null;
	if (item.tagName == "DL") return item;
	return parentDL(item.parentNode);
}