/* -------------------------------------------------------
 * konstansok
 * -------------------------------------------------------
 */


/* -------------------------------------------------------
 * boxok
 * -------------------------------------------------------
 */
var BOX_ANIM_TIME = 400;		// ennyi ido az anim
var ANIM_TIMER_SLEEP = 15;		// ennyi msec van ket anim fazis kozt
var NAVIGATION_BAR_HEIGHT = 20; // navigacios csik magassaga
var boxIntervals = new Array();

var boxAnimStructs = new Array();
var animTimerID = null;

function initBoxHeights_static()
{
	for(var i=0; i<boxIds.length; i++)
	{
		var boxId = boxIds[i];
		
		if(boxClosed[boxId])
		{
			setBoxHeight(boxId, 1, 1);
		}
		else
		{
			var boxHeight = boxHeights[boxId];
			var boxContentHeight = getBoxContentHeight(boxId);
			
			
			//debugLog("box: "+boxId+", boxHeight = "+boxHeight+", boxContentHeight = "+boxContentHeight);
			if(boxContentHeight > boxHeight)
				boxHeight = boxContentHeight;
			
			setBoxHeight(boxId, boxHeight, NAVIGATION_BAR_HEIGHT);
		}
	}
}


function setBoxHeight(boxId, height, navHeight)
{
	var hideContent = false;
	var hideNav = false;
	if(height <= 1)
		hideContent = true;
	if(navHeight <= 1)
		hideNav = true;

	var boxContentAndNavObj = $('contentAndNavigation_' + boxId);
	var boxContentContainerObj = $('contentContainer_'+boxId);
	var boxNavObj = $('nav_' + boxId);
	
	boxContentContainerObj.setStyle({height: height+'px'});
	if(boxNavObj)
		boxNavObj.setStyle({height: navHeight+'px'});
	
	if(hideContent && hideNav)
	{
		boxContentAndNavObj.hide();
	}
	else
	{
		boxContentAndNavObj.show();
	}


	/*
	if(hideContent)
	{
		boxContentContainerObj.hide();
	}
	else
	{
		boxContentContainerObj.setStyle({height: height+'px'});
		boxContentContainerObj.show();
	}

	if(hideNav)
	{
		boxNavObj.hide();
	}
	else
	{
		boxNavObj.setStyle({height: navHeight+'px'});
		boxNavObj.show();
	}
	*/
}

function getBoxHeight(boxId)
{
	var boxObj = $('contentContainer_'+boxId);
	if(boxObj)
		return boxObj.getHeight();
	
	return -1;
}

function getBoxContentHeight(boxId)
{
	var boxContentObj = $('boxContent_'+boxId);
	if(boxContentObj)
		return boxContentObj.getHeight();
	
	return -1;
}

function getBoxNavHeight(boxId)
{
	var boxNavObj = $('nav_'+boxId);
	if(boxNavObj)
		return boxNavObj.getHeight();
	
	return 0;
}

// visszaadja az anim struct indexét vagy -1 ha nincs
function findBoxAnimStruct(boxId)
{
	for(var i=0; i<boxAnimStructs.length; i++)
	{
		var struct = boxAnimStructs[i];
		if(struct['boxId'] == boxId)
			return i;
	}
	return -1;
}

function addBoxAnimStruct(boxId, stopHeight, stopNavHeight)
{
	// debugLog("addBoxAnimStruct(): boxId = "+boxId+", stopHeight = "+stopHeight);
	
	// ha volt kivesszuk
	removeBoxAnimStruct(boxId);
	
	var currHeight = getBoxHeight(boxId);
	if(currHeight == stopHeight)
	{
		// nincs mit csinalni
		//debugLog("addBoxAnimStruct(): currHeight = "+currHeight+", cancelled!");
		return;
	}
	
	var currNavHeight = getBoxNavHeight(boxId);
	
	var struct = new Array();
	struct['boxId'] = boxId;
	struct['startHeight'] = currHeight;
	struct['stopHeight'] = stopHeight;
	struct['startNavHeight'] = currNavHeight;
	struct['stopNavHeight'] = stopNavHeight;
	struct['animTime'] = BOX_ANIM_TIME;
	struct['startTime'] = null;
	
	boxAnimStructs.push(struct);
	
	/*
	var currHeight = 0;
	if (isNavigationBarIncluded) {
		currHeight = getBoxContentAndNavigationHeight(boxId);
	} else {
		currHeight = getBoxHeight(boxId);
	}
	if(currHeight == stopHeight)
	{
		// nincs mit csinalni
		// debugLog("addBoxAnimStruct(): currHeight = "+currHeight+", cancelled!");
		return;
	}
	
	var struct = new Array();
	struct['boxId'] = boxId;
	struct['startHeight'] = currHeight;
	struct['stopHeight'] = stopHeight;
	if (isNavigationBarIncluded) {
		var navigationBarHeight = (stopHeight == 0? 0: NAVIGATION_BAR_HEIGHT);
		struct['stopHeight'] += navigationBarHeight;
	}
	struct['animTime'] = BOX_ANIM_TIME;
	struct['startTime'] = null;
	struct['isNavigationBarIncluded'] = isNavigationBarIncluded;
	
	boxAnimStructs.push(struct);
	*/
	
	// debugLog("addBoxAnimStruct(): added!");
}

function removeBoxAnimStruct(boxId)
{
	var index = findBoxAnimStruct(boxId);
	if(index != -1)
	{
		// kivesszuk
		boxAnimStructs.splice(index, 1);
	}
}

function startAnimTimer()
{
	if(animTimerID != null || boxAnimStructs.length == 0)
		return;
	animTimerID = window.setTimeout("doAnimPhase()", ANIM_TIMER_SLEEP);
}

function stopAnimTimer()
{
	// lelojuk
	window.clearTimeout(animTimerID);
	animTimerID = null;
}

function doAnimPhase()
{
	stopAnimTimer();
	
	// feldolgozzuk a dolgokat
	//debugLog("----- start");

	for(var i=0; i<boxAnimStructs.length; i++)
	{
		var struct = boxAnimStructs[i];
		var boxId = struct['boxId'];
		
		var currTime = new Date().getTime();
		var startTime = struct['startTime'];
		if(startTime == null)
		{
			struct['startTime'] = currTime;
			startTime = currTime;
		}
		
		var timeFactor = (currTime - startTime) / struct['animTime'];
		if(timeFactor > 1)
			timeFactor = 1;
		// sinus lassulashoz
		timeFactor = Math.sin(Math.PI/2 * timeFactor);
		if(timeFactor > 1)
			timeFactor = 1;
		
		var currHeight = struct['startHeight'] + Math.round((struct['stopHeight'] - struct['startHeight']) * timeFactor);
		var navHeight = struct['startNavHeight'] + Math.round((struct['stopNavHeight'] - struct['startNavHeight']) * timeFactor);
		
		setBoxHeight(boxId, currHeight, navHeight);
		
		if(timeFactor == 1)
			// vege
			removeBoxAnimStruct(boxId);
	}

	//debugLog("----- stop");
	
	// ha van elem meg indul megint
	startAnimTimer();
}

// az utolso elem also margojat leszedi - ha van navigacio benne
function removeBoxContentLastMargin(boxId)
{
	var boxNavObj = $('nav_' + boxId);
	var boxObj = $('boxContent_'+boxId);
	//if(boxObj && boxNavObj)
	//{
		/*
		var childElements = boxObj.getElementsBySelector( 'p', 'li');
		if(childElements.length > 0)
		{
			var lastElement = childElements[childElements.length - 1];
			lastElement.setStyle({marginBottom: '0px'});
		}
		*/
		$('boxSpacer_'+boxId).remove();
	//}
}


//megjott a box a valasz
function boxXmlArrived(originalRequest)
{
	var newBoxContent = null;
	var boxId = null;
	
	if (originalRequest.responseXML)
	{
		//alert(originalRequest.responseXML);
		var xh = new tXMLHelper(originalRequest.responseXML);
		
		if (!xh.nodeExists('vati')) {
			//alert("there is no <vati> section in the response xml");
		}
		else {			
			//	ok, dolgozzuk fel az xml-t!
			if (xh.nodeExists('boxContent')) {
				newBoxContent = xh.nodeToString('boxContent');
			}
			if(xh.nodeExists('boxId')) {
				boxId = parseInt(xh.nodeToString('boxId'));
			}
		}
	}
	else
	{
		//alert("response came from the server was not an xml response");
	}
	
	if(boxId != null)
	{
		//alert(boxId+", "+newBoxContent);
		var boxObj = $('box_'+boxId);
		if(boxObj)
		{
			var targetBoxHeight = boxHeights[boxId];
			var currBoxHeight = getBoxHeight(boxId);
						
			boxObj.replace(newBoxContent);
			removeBoxContentLastMargin(boxId);
			
			// hogy nyitva/csukva van-e az már lokálisan döl el és nem a letöltött html-böl!
			// de vigyazz, nem csukhato dobozoknal ezek nincsenek!
			var td = $('openbox_' + boxId);
			var img = $('openboximg_' + boxId);
			if(td && img)
			{
				if (!boxClosed[boxId]) {
					img.src = 'site/images/icon_closebox.gif';
					td.removeClassName('openBox');
					td.addClassName('closeBox');
				} else {
					img.src = 'site/images/icon_openbox.gif';
					td.removeClassName('closeBox');
					td.addClassName('openBox');
				}
				
			}
			
			setBoxHeight(boxId, currBoxHeight, NAVIGATION_BAR_HEIGHT);
			
			var boxContentHeight = getBoxContentHeight(boxId);
			
			//debugLog("box: "+boxId+", boxHeight = "+boxHeight+", boxContentHeight = "+boxContentHeight);
			if(boxContentHeight > targetBoxHeight)
				targetBoxHeight = boxContentHeight;
			
			
			addBoxAnimStruct(boxId, targetBoxHeight, NAVIGATION_BAR_HEIGHT);
			startAnimTimer();
		}

		startBoxAutoNavigation(boxId);
	}
}


function getBoxContent(url, boxId)
{
	//alert("getBoxContent to: "+url);
	
	stopBoxAutoNavigation(boxId);
	
	this.ttAjax = new Ajax.Request(url, {
		method: 'get',
		onComplete: boxXmlArrived
	});
}
/*
function openOrCloseBox(boxId) {
	var targetBoxHeight = 1;
	var targetBoxNavHeight = 1; 
	if (boxClosed[boxId]) {
		
		var img = $('openboximg_' + boxId);
		img.src = 'site/images/icon_closebox.gif';

		var td = $('openbox_' + boxId);
		td.removeClassName('openBox');
		td.addClassName('closeBox');
		
		var boxContentAndNavObj = $('contentAndNavigation_' + boxId);
		boxContentAndNavObj.show();
		
		boxClosed[boxId] = false;
		
		var targetBoxHeight = boxHeights[boxId];
		//var currBoxHeight = getBoxHeight(boxId);
		//setBoxHeight(boxId, currBoxHeight, NAVIGATION_BAR_HEIGHT);
		var boxContentHeight = getBoxContentHeight(boxId);
		if(boxContentHeight > targetBoxHeight)
			targetBoxHeight = boxContentHeight;
		
		//targetBoxHeight = getBoxContentHeight(boxId);
		targetBoxNavHeight = NAVIGATION_BAR_HEIGHT;
		startBoxAutoNavigation(boxId);
		
	} else {
		
		var img = $('openboximg_' + boxId);
		img.src = 'site/images/icon_openbox.gif';
		
		var td = $('openbox_' + boxId);
		td.removeClassName('closeBox');
		td.addClassName('openBox');
		
		boxClosed[boxId] = true;
		stopBoxAutoNavigation(boxId);
	}
	addBoxAnimStruct(boxId, targetBoxHeight, targetBoxNavHeight);
	startAnimTimer();
}
*/

function startAllBoxesAutoNavigation() {
	
	for (var i = 0; i < boxIds.length; i++) {
		if (boxAutoNext[boxIds[i]] != null) {
			startBoxAutoNavigation(boxIds[i]);
		}
	}

}

function startBoxAutoNavigation(boxId)
{
	stopBoxAutoNavigation(boxId);
	
	if (boxAutoNext[boxId]) {
		boxIntervals[boxId] = window.setTimeout("autoNextBox(" + boxId + ")", boxAutoNextTime[boxId] * 1000);
	}
}

function stopBoxAutoNavigation(boxId)
{
	clearTimeout(boxIntervals[boxId]);	
}

function autoNextBox(boxId) {
	if (! boxClosed[boxId]) {
		getBoxContent(boxAutoNext[boxId]);
	}
}

function autoNext() {
	
	for(var i=0; i<boxIds.length; i++)
	{
		var boxId = boxIds[i];
		var qqq = boxAutoNext[boxId];
		if(qqq)
		{
			boxIntervals[boxId] = window.setTimeout("autoNextBox(" + boxId + ")", boxAutoNextTime[boxId] * 1000);
		}
	}

	/*
	for (var boxId in boxAutoNext) {
		boxIntervals[boxId] = window.setTimeout("autoNextBox(" + boxId + ")", boxAutoNextTime[boxId] * 1000);
	}
	*/
}



/* -------------------------------------------------------
 * menuk
 * -------------------------------------------------------
 */


function setActiveLeftMenuColor(id) {
	var objDiv = getElementWithId('leftMenu_'+id);
	var objP = getElementWithId('leftMenuP_'+id);
	
	if (objDiv != null && objP != null) {
		objDiv.setStyle({backgroundColor: '#a3b6bd'});
		objP.setStyle({color: '#003c4a'});
	}
}

// bal menu roll over esemeny
function leftMenuRollOverEvent(id) {
	if (id == deepestLeftActiveMenuId) {
		return;
	}
	
	var objDiv = getElementWithId('leftMenu_'+id);
	var objP = getElementWithId('leftMenuP_'+id);
	
	if (objDiv != null && objP != null) {
		objDiv.setStyle({backgroundColor: '#a3b6bd'});
		objP.setStyle({color: '#003c4a'});
	}
}

// bal menu roll out esemeny
function leftMenuRollOutEvent(id) {
	if (id == deepestLeftActiveMenuId) {
		return;
	}		
	
	var objDiv = getElementWithId('leftMenu_'+id);
	var objP = getElementWithId('leftMenuP_'+id);
	
	if (objDiv != null && objP != null) {
	
		var menuItem = balMenu.findMenu(id);
		if (menuItem != null) {
			objP.setStyle({color: '#003c4a'});
			switch (menuItem.level) {
				case 1:					
					objDiv.setStyle({backgroundColor: '#e5e6e5'});
					break;
				case 2:
					objDiv.setStyle({backgroundColor: '#eeefee'});
					break;
				case 3:
					objDiv.setStyle({backgroundColor: '#f4f4f5'});
					break;
				case 4:
					objDiv.setStyle({backgroundColor: '#ffffff'});
					break;
			}
		}		
	}	
}

/* topmenuvel kapcsolatos var-k */
// kesobbiekben jol johet, ha true-ra rakjuk akkor minden menu kozepre lesz
// igazitva, ha false akkor a ket szelso menu jobbra ill balra fog tapadni
var allMenuAlignCenter = true;
// almenu eltolasa x-n
var submenuOffsetX = 0;
// almenu eltolasa y-n
var submenuOffsetY = 32;

/* ---------------------------- */

var l1ActiveMenu = null;
var l1ActiveMenuId = -1;
var visibleMenuCount = null;



var hideTimerIDs = new Array();
for(var i=0; i<visibleMenuCount; i++)
{
	var id = topMenu.menuItemIds[i];
	hideTimerIDs[id] = -1;
}

var displayedSubmenusOfMenuId = null;
var showSubmenusOfMenuIdAfterHide = null;


function l2RollOverEvent(id) {
	$('topmenu_submenu_td_'+id).setStyle({backgroundColor: '#d1d3d4'});
}


function l2RollOutEvent(id) {
	$('topmenu_submenu_td_'+id).setStyle({backgroundColor: '#e6e7e8'});	
}


function menuIsActive(menuId)
{
	var menu = topMenu.findMenu(menuId);
	if(menu != null)
	{
		if(menu.level == 1)
		{
			//alert("level1 menu active: "+menu);
			l1ActiveMenu = menu;
		}
		if(menu.level == 2)
		{
			//alert("level2 menu active: "+menu);
			l1ActiveMenu = menu.parent;
		}
		l1ActiveMenuId = l1ActiveMenu.id;
		showMenuSubmenus(l1ActiveMenuId);
	}
}


function l1MenuItemMouseEnter(id)
{
	var menu = topMenu.findMenu(id);
	if(menu == null)
		return;
	
	$('topmenuitem_span_'+id).setStyle({fontWeight: 'bold'});
	
	if(!menu.hasChildren())
		return;
	
	activeSubmenu = true;
	showMenuSubmenus(id);
}

function l1MenuItemMouseLeave(id)
{
	// aktiv menunek nincs leave-je
	if(l1ActiveMenuId == id)
		return;
	
	var menu = topMenu.findMenu(id);
	if(menu == null)
		return;
	if(!menu.hasChildren()) {
		$('topmenuitem_span_'+id).setStyle({fontWeight: 'normal'});
		return;
	}
	
	hideMenuSubmenus(id);
	
}


function showMenuSubmenus(id)
{
	if(id == null)
		return;
	
	//alert("show: "+id+", displayed: "+displayedSubmenusOfMenuId);
	//$('topmenuitem_span_'+id).setStyle({fontWeight: 'bold'});
	
	_shutdownHideTimer(id);	
	
	if(displayedSubmenusOfMenuId == id)
		// nincs dolgunk
		return;
	
	// azonnal kikapcs ami kint van
	hideMenuSubmenus(displayedSubmenusOfMenuId, true);
	
	// bekapcs a mostani
	$('topMenuSubmenuLevel2_'+id).setStyle({display: 'block'});
	
	// megnezi, hogy milyen szeles az elso szintu menuje
	var level1MenuWidth = $('topmenulabel_td_'+id).getWidth();
		
	var menu = topMenu.findMenu(id);
		
	var longestLabelWidth = 0;
	// megnezi hogy melyik a leghosszabb menu label
	for (var i = 0; i < menu.childrenIds.length; i++) {
		$('topmenu_submenu_'+menu.childrenIds[i]).setStyle({whiteSpace: 'nowrap'});
		var currentLabelWidth = $('topmenu_submenu_'+menu.childrenIds[i]).getWidth();
		
		longestLabelWidth = (longestLabelWidth > currentLabelWidth) ? longestLabelWidth : currentLabelWidth;
		
		$('topmenu_submenu_'+menu.childrenIds[i]).setStyle({whiteSpace: 'normal'});		
	}
	
	// azert adunk hozza 16-t, mert az almenu padding-left 16px
	longestLabelWidth += 16;
	
	// ha rovidebb, mint a elso szintu menu szelesseg, akkor kinyomjuk akkorara
	if (longestLabelWidth < level1MenuWidth)
		longestLabelWidth = level1MenuWidth;
	
	// ha nagyobb, mint a max szelesseg, akkor kisebbre nyomjuk
	if (longestLabelWidth > topMenuMaxSubmenuWidth)
		var newWidth = topMenuMaxSubmenuWidth;
	else
		var newWidth =  longestLabelWidth;
	
	$('topMenuSubmenuLevel2Table_'+id).setStyle({width: newWidth+'px'});
	
	var menuOffset = $('topmenulabel_td_'+id).cumulativeOffset();
	var menuWidth = $('topmenulabel_td_'+id).getWidth();
		
	var xoffset = menuOffset[0] + submenuOffsetX;
	var yoffset = menuOffset[1] + submenuOffsetY;
		
	var menuContainerOffset = $('topMenuTableId').cumulativeOffset();
	
	// ki kell szamolni, hogy kilog e, ha igen, akkor a menu jobb oldalahoz kell igazitani a submenu jobb oldalat
	if (menuContainerOffset[0] + topMenuWidth < xoffset + newWidth) {				
		xoffset -= newWidth - menuWidth + submenuOffsetX;
	}
	$('topMenuSubmenuLevel2_'+id).setStyle({display: 'block'});
	$('topMenuSubmenuLevel2_'+id).setStyle({position: 'absolute', left: xoffset+'px', top: yoffset+'px', zIndex:'1'});
	
	// most mar ez latszik
	displayedSubmenusOfMenuId = id;
	
}

function hideMenuSubmenus(id, doNotDelay)
{
	if(id == null)
		return;
	
	_shutdownHideTimer(id);

	if(displayedSubmenusOfMenuId != id)
		// ez nincs kint, nincs dolgunk
		return;
	
	if(doNotDelay)
	{
		showSubmenusOfMenuIdAfterHide = null;
		doHideMenuSubmenus(id);
		activeSubmenu = false;
		return;
	}
	
	if(showSubmenusOfMenuIdAfterHide == null && id != l1ActiveMenuId && l1ActiveMenu != null)
		showSubmenusOfMenuIdAfterHide = l1ActiveMenuId;
	
	hideTimerIDs[id] = window.setTimeout("doHideMenuSubmenus("+id+")", 500);
	
}


function doHideMenuSubmenus(id)
{
	hideTimerIDs[id] = -1;
	
	$('topmenuitem_span_'+id).setStyle({fontWeight: 'normal'});
	
	$('topMenuSubmenuLevel2_'+id).setStyle({display: 'none'});
	displayedSubmenusOfMenuId = null;
	
	if(showSubmenusOfMenuIdAfterHide != null)
	{
		showMenuSubmenus(showSubmenusOfMenuIdAfterHide);
		showSubmenusOfMenuIdAfterHide = null;
	}
	activeSubmenu = false;
}

function _shutdownHideTimer(id)
{
	if(hideTimerIDs[id] != -1)
	{
		// lelojuk a hide timert!
		window.clearTimeout(hideTimerIDs[id]);
	}
	hideTimerIDs[id] = -1;
}


function alignTopMenu() {
			
	var sumWidth = 0;
	var sumWidthMenuOnly = 0;
	var cutMenuFromHere = -1;
	// menu max szelesseg
	var fullWidth = topMenuWidth;
	// ebbe rakjuk a kirajzolando menuk szelessegeit
	var menusWidth = new Array();
	
	for(var i=0; i<topMenu.menuItemIds.length && cutMenuFromHere == -1; i++)
	{
		var id = topMenu.menuItemIds[i];
		
		// ideiglenesen boldra allitjuk es ugy szamolunk vele
		$('topmenuitem_span_'+id).setStyle({fontWeight: 'bold'});
		
		// ha minden menu kozepre van igazitva akkor mindket oldalon szamoljuk a margot, kulonben csak 1-re
		// a vegehez hozza kell adni 2-t, mert ff-ben kulonben ugralnak a szeparalok es a menu labelek
		if (allMenuAlignCenter)
			var menuWidthWithMargin = $('topmenuitem_span_'+id).getWidth() + 2 * topMenuMinMarginWidth + 2;			
		else
			var menuWidthWithMargin = $('topmenuitem_span_'+id).getWidth() + topMenuMinMarginWidth + 2;
			
		// a menu cimke szelessege
		var menuWidthOnly = $('topmenuitem_span_'+id).getWidth();
		
		if(sumWidth + menuWidthWithMargin > fullWidth) {
			// gaz van, ez mar nem fer ki
			cutMenuFromHere = i;
			// ha nem minden menu kozepre igazitott, akkor az utolso menutol ami meg
			// latszik elvesszuk a jobb terkozet es ujra szamoljuk a maradek helyet
			if (allMenuAlignCenter) {
				menusWidth[menusWidth.length - 1] -= topMenuMinMarginWidth; 
				sumWidth -= topMenuMinMarginWidth ;
			}
		} else {
			if (allMenuAlignCenter) {
				sumWidth += menuWidthWithMargin;
			} else {
				menuWidthWithMargin += topMenuMinMarginWidth;
				sumWidth += menuWidthWithMargin;
			}
			
			sumWidthMenuOnly += menuWidthOnly;
			menusWidth.push(menuWidthWithMargin - 2);
		}
		
		// visszarakjuk normalba
		$('topmenuitem_span_'+id).setStyle({fontWeight: 'normal'});
	}
	
	//kell vagni?
	var menuCount = topMenu.menuItemIds.length;
	
	if(cutMenuFromHere != -1)
	{
		var firstCut = true;
		// a levagando elottitol nezzuk, mert az elvalasztot azzal az id-vel talaljuk meg
		for(var i=cutMenuFromHere - 1; i<topMenu.menuItemIds.length; i++)
		{
			var id = topMenu.menuItemIds[i];
			// az elsonel csak az elvalasztot szedjuk ki, a menut nem
			if (firstCut) {
				$('topmenuseparator_td_'+id).remove();				
				firstCut = false;
			} else {
				$('topmenulabel_td_'+id).remove();
				$('topmenuseparator_td_'+id).remove();				
			}
		}
		
		menuCount = cutMenuFromHere;
	}
	visibleMenuCount = menuCount;
	
	
	// ennyi felesleges hely van
	var restWidth = topMenuWidth - sumWidth;
	// ekkora lesz az uj margo
	var newMarginWidth = Math.floor(restWidth / visibleMenuCount);
	
	// belojuk az uj td mereteket
	for (var i = 0; i < visibleMenuCount; i++) {
		var id = topMenu.menuItemIds[i];
		var newTdWidth = menusWidth[i] + newMarginWidth;
		
		if (allMenuAlignCenter) {
			// ha mindenki kozepre
			$('topmenulabel_td_'+id).setStyle({width: newTdWidth});
			$('topmenuitem_p_'+id).setStyle({textAlign: 'center'});
		} else {
			// ha nem mindenki kozepre, akkor az elso balra, az utolso jobbra tobbi kozepre lesz igazitva
			if (i == 0) {
				$('topmenulabel_td_'+id).setStyle({width: newTdWidth - Math.floor(newMarginWidth)});
				$('topmenuitem_p_'+id).setStyle({textAlign: 'left'});
			} else if (i == visibleMenuCount - 1) {
				$('topmenulabel_td_'+id).setStyle({width: newTdWidth - Math.floor(newMarginWidth)});
				$('topmenuitem_p_'+id).setStyle({textAlign: 'right'});
			} else {
				$('topmenulabel_td_'+id).setStyle({width: newTdWidth});
				$('topmenuitem_p_'+id).setStyle({textAlign: 'center'});
			}
		}
		
	}
	
}

/* -----------------------------
 * menu cimke 
 * -----------------------------
 */
function setMenuLabel() {
	
	var menuLabelObj = getElementWithId('menuLabel');
	if(menuLabelObj == null)
		return;
	
	if (activeMenuLabel != '') {
		//menuLabelObj.setStyle({display: 'block'});
		menuLabelObj.innerHTML = activeMenuLabel;
	} else {
		var divs = document.getElementsByTagName('div');
		var divsLen = divs.length;
		var i = 0;
		var found = false;
		for (i = 0; i < divsLen; i++) {
			// ha hirek tipus van
			if (Element.hasClassName(divs[i], 'articleType_1')) {
				found = true;
				break;
			}
		}
		
		if (found) {			
			//menuLabelObj.setStyle({display: 'block'});
			menuLabelObj.innerHTML = newsTitle;
		} else {
			menuLabelObj.setStyle({display: 'none'});
		}
	}
}



 /* -------------------------------------------------------
  * handlerek
  * -------------------------------------------------------
  */

function pageResized()
{
}

function pageLoaded()
{	
} 
