var subMenus = new Object();
var activeSubMenu;
var speed1 = 3;
var speed2 = 20;

function unformatNumber(num) {
	return num.replace(/([^0-9\.\-])/g, '') * 1;
}

function SubMenu( element, menuId ) {
	this.element = element;
	this.menuId = menuId;
	this.currentHeight = this.maxHeight = element.offsetHeight;
	this.state = 0;
	this.activate = function() {
		activeSubMenu = this;
		this.element.style.display = "block";
		this.currentHeight = this.maxHeight;
		this.element.style.height = this.maxHeight + "px";
	};
	this.show = function() {
		this.state = 1;
		this.showing();
	}	
	this.showing = function() {
		if ( this.state == 2 )
			return;
		this.element.style.display = "block";
		this.currentHeight += speed1 + Math.sin(this.currentHeight / this.maxHeight * Math.PI) * speed2;
		if ( this.currentHeight >= this.maxHeight )
			this.currentHeight = this.maxHeight;
		this.element.style.height = this.currentHeight + "px";
		if ( this.currentHeight < this.maxHeight )
			setTimeout("subMenus['" + this.menuId + "'].showing()", 30 );
		else
			this.state = 0;
	};
	this.close = function() {
		this.state = 2;
		this.closing();
	}	
	this.closing = function() {
		if ( this.state == 1 )
			return;
		if ( activeSubMenu == this )
			return;
		this.currentHeight -= speed1 + Math.sin(this.currentHeight / this.maxHeight * Math.PI) * speed2;
		if ( this.currentHeight <= 0 )
			this.currentHeight = 0;
		this.element.style.height = this.currentHeight + "px";
		if ( this.currentHeight > 0 )
			setTimeout("subMenus['" + this.menuId + "'].closing()", 30 );
		else
		{
			this.element.style.display = "none";
			this.state = 0;
		}
	}
	this.hide = function() {
		if ( activeSubMenu == this )
			return;
		this.element.style.display = "none";
		this.currentHeight = 0;
		this.element.style.height = this.currentHeight + "px";
	};
}

function activateMenu(id) {
	subMenus[id].activate();
}

function hideAllSubMenus() {
	for (var menuId in subMenus) {
		subMenus[menuId].close();
	}
}

function initializeSubMenus(menuPrefix, subMenuPrefix) {
	var i = 1;
	var subMenuId = subMenuPrefix + i;
	var menuId = menuPrefix + i;
    var element = document.getElementById(subMenuId);
	while ( element != null ) {
		var subMenu = new SubMenu(element, menuId);
		subMenus[menuId] = subMenu;
		element = document.getElementById(menuPrefix + i);
		if ( element != null ) {
			element.onclick = function() { hideAllSubMenus(); subMenus[this.id].show(); };
			subMenus[menuId].hide();
		}
		++i;
		subMenuId = subMenuPrefix + i;
		menuId = menuPrefix + i;
		element = document.getElementById(subMenuId);
	}
}

/************************************* expand Div  **********************************************/

function expandHide(id) {
	
	obj = document.getElementById(id);
	hbut = document.getElementById("h"+id);
	icon = document.getElementById("p"+id)
	
	obj.style.display="none";
	
	hbut.innerHTML = "Bővebben";
	hbut.style.position="relative";
	hbut.style.width="100px";
	hbut.style.height="18px";
	hbut.style.left="452px";
	hbut.style.paddingLeft="25px";
	hbut.style.paddingTop="3px";
	hbut.style.marginBottom="0px";
	hbut.style.backgroundImage="url(pics/more.png)";
	hbut.style.backgroundRepeat="no-repeat";
	
	
	icon.style.display="block";
	icon.style.position="relative";
	icon.style.cssFloat="left";
	icon.style.styleFloat="left";
	icon.style.top="4px";
	icon.style.width="12px";
	icon.style.height="12px";
	icon.style.marginRight="4px";
	icon.style.backgroundImage="url(pics/dropdownmax.png)";
	icon.style.backgroundRepeat="no-repeat";
}

function expandDiv(id) {
	obj = document.getElementById(id);
	hbut = document.getElementById("h"+id);
	but = document.getElementById("cl"+id);
	icon = document.getElementById("p"+id)

	if (obj.style.display == "none") {
		obj.style.display = "block";
		hbut.innerHTML = "Bővebben"
		but.innerHTML = "Kattintson a szöveg bezárásához"
		but.style.marginLeft = "0px";
		icon.style.backgroundImage="url(pics/dropdownmin.png)";
	} else {
		obj.style.display = "none";
		hbut.innerHTML = "Bővebben"
		but.innerHTML = "Kattintson a szöveg kinyitásért"
		but.style.marginLeft = "30px";
		icon.style.backgroundImage="url(pics/dropdownmax.png)";
	}
}


