function mainMenuClick(nodeID, nodePath)
{
	var menuID = 'secondMenu'+nodeID;
	showCloseBlock(nodeID);
	showSecondMenuBlock(menuID);
	requestShowSecondMenu(nodeID);
	
	hideThirdMenuBlock();
	
	requestContent(nodePath);
	requestGallery(nodePath);

}

function secondMenuClick(nodeID, nodePath)
{
	hideThirdMenuBlock();

	requestThirdMenu(nodePath);

	requestContent(nodePath);
	requestGallery(nodePath);
	
}

function secondMenuClickNews(nodeID, nodeParentPath, nodePath)
{
	hideThirdMenuBlock();

	requestContent(nodePath);
	requestGallery(nodeParentPath);
}

function thirdMenuClick(nodeID, nodePath)
{
	requestContent3(nodePath);
	requestGallery(nodePath);
	
	markThirdMenuSelected(nodeID);
	sIFR_init_thirdMenu();
}

function closeButtonClick(nodeID, menuID)
{
	hideSecondMenuBlock(menuID);
	hideCloseBlock(nodeID);
	requestHideSecondMenu(nodeID);
	hideThirdMenuBlock();
}

//******************************************************//
//TOP CENTER (CONTENT) BLOCK FUNCTIONS
//******************************************************//
var requestContentObj;
function requestContent(nodePath)
{
	try
	{
		requestContentObj = new XMLHttpRequest();
	}
	catch(microsoft)
	{
		try
		{
			requestContentObj = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(teinemicrosoft)
		{
			requestContentObj = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	var url = "http://www.kinar.ee/ajax_content_block.php?nodepath=/"+nodePath;
	requestContentObj.open("GET", url, true);
	requestContentObj.onreadystatechange = updateContent;
	requestContentObj.send(null);
}
function updateContent()
{
	if(requestContentObj.readyState == 4 && requestContentObj.status == 200)
	{
		var responsetext = requestContentObj.responseText;
		topCenterBlockObj = document.getElementById('top_center_block');
		emptyNode(topCenterBlockObj);
		topCenterBlockObj.innerHTML = responsetext;
		sIFR_init_contentBlock();
		
		var contentFolderLevel = document.getElementById('contentFolderLevel');
		if (contentFolderLevel)
		{	
			if (contentFolderLevel.value==3)
			{
				var contentFolderParent = document.getElementById('contentFolderParent');
				if (contentFolderParent)
				{
					currentFolderParent=contentFolderParent.value;
				}
				
				var parentFolderIDobj = document.getElementById('parentFolderID');
				if (parentFolderIDobj)
				{
					currentThirdMenu = parentFolderIDobj.value;
					parentFolderIDobj.value = currentFolderParent;
				}
				var pathForThirdobj = document.getElementById('path'+currentFolderParent);
				if (pathForThirdobj)
				{
					nodePath = pathForThirdobj.value;
					requestThirdMenu(nodePath);
				}
				
			}
		}
		
		
		
		markMainMenuSelected();
		markSecondMenuSelected();
		
		sIFR_init_bottomMenu();
		
	}
}
var requestContent3Obj;
function requestContent3(nodePath)
{
	try
	{
		requestContent3Obj = new XMLHttpRequest();
	}
	catch(microsoft)
	{
		try
		{
			requestContent3Obj = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(teinemicrosoft)
		{
			requestContent3Obj = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	var url = "http://www.kinar.ee/ajax_content_block.php?nodepath=/"+nodePath;
	requestContent3Obj.open("GET", url, true);
	requestContent3Obj.onreadystatechange = updateContent3;
	requestContent3Obj.send(null);
}
function updateContent3()
{
	if(requestContent3Obj.readyState == 4 && requestContent3Obj.status == 200)
	{
		var responsetext = requestContent3Obj.responseText;
		topCenterBlockObj = document.getElementById('top_center_block');
		emptyNode(topCenterBlockObj);
		topCenterBlockObj.innerHTML = responsetext;
		sIFR_init_contentBlock();
	}
}
//******************************************************//
//GALLERY BLOCK BLOCK FUNCTIONS
//******************************************************//
var requestGalleryObj;
function requestGallery(nodePath)
{
	try
	{
		requestGalleryObj = new XMLHttpRequest();
	}
	catch(microsoft)
	{
		try
		{
			requestGalleryObj = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(teinemicrosoft)
		{
			requestGalleryObj = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	var url = "http://www.kinar.ee/ajax_gallery_block.php?nodepath=/"+nodePath;
	requestGalleryObj.open("GET", url, true);
	requestGalleryObj.onreadystatechange = updateGallery;
	requestGalleryObj.send(null);
}

function updateGallery()
{
	if(requestGalleryObj.readyState == 4 && requestGalleryObj.status == 200)
	{
		var responsetext = requestGalleryObj.responseText;
		var galleryBlockObj = document.getElementById('gallery_block');
		emptyNode(galleryBlockObj);
		galleryBlockObj.innerHTML = responsetext;
		
		contentIsEmpty = document.getElementById('content_is_empty');
		if (contentIsEmpty)
		{
			if (contentIsEmpty.value==1)
			{
				changeGalleryPictureByID('gallery_image_block');
			}
		}
	}
}

//******************************************************//
//SECOND LEVEL MENU BLOCK FUNCTIONS
//******************************************************//
function showSecondMenuBlock(menuID)
{
	if(document.getElementById)
	{
		var menuBlockObj = document.getElementById(menuID);
		if (menuBlockObj)
		{
			menuBlockObj.style.display = 'block';
		}
	}
}
var requestShowSecondMenuObj;
function requestShowSecondMenu(nodeID)
{
	try
	{
		requestShowSecondMenuObj = new XMLHttpRequest();
	}
	catch(microsoft)
	{
		try
		{
			requestShowSecondMenuObj = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(teinemicrosoft)
		{
			requestShowSecondMenuObj = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	var url = "http://www.kinar.ee/ajax_secondmenu_block_show.php?nodeID="+nodeID;
	requestShowSecondMenuObj.open("GET", url, true);
	requestShowSecondMenuObj.send(null);
}
//******************************************************//
//HIDE SECOND LEVEL MENU BLOCK WITH AJAX
//******************************************************//
function hideSecondMenuBlock(menuID)
{
	if(document.getElementById)
	{
		var menuBlockObj = document.getElementById(menuID);
		if (menuBlockObj)
		{
			menuBlockObj.style.display = 'none';
		}
		var closeBlockObj = document.getElementById(menuID);
		if (closeBlockObj)
		{
			menuBlockObj.style.display = 'none';
		}
	}
}
function hideCloseBlock(nodeID)
{
	if(document.getElementById)
	{

		var closeBlockObj = document.getElementById("closeButton"+nodeID);
		if (closeBlockObj)
		{
			closeBlockObj.style.display = 'none';
		}
	}
}
function showCloseBlock(nodeID)
{
	if(document.getElementById)
	{

		var closeBlockObj = document.getElementById("closeButton"+nodeID);
		if (closeBlockObj)
		{
			closeBlockObj.style.display = 'block';
		}
	}
}
var requestHideSecondMenuObj;
function requestHideSecondMenu(nodeID)
{
	try
	{
		requestHideSecondMenuObj = new XMLHttpRequest();
	}
	catch(microsoft)
	{
		try
		{
			requestHideSecondMenuObj = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(teinemicrosoft)
		{
			requestHideSecondMenuObj = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	var url = "http://www.kinar.ee/ajax_secondmenu_block_hide.php?nodeID="+nodeID;
	requestHideSecondMenuObj.open("GET", url, true);
	requestHideSecondMenuObj.send(null);
}

//******************************************************//
//THIRD MENU BLOCK FUNCTIONS
//******************************************************//
var requestThirdMenuObj;
function requestThirdMenu(nodePath)
{
	try
	{
		requestThirdMenuObj = new XMLHttpRequest();
	}
	catch(microsoft)
	{
		try
		{
			requestThirdMenuObj = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(teinemicrosoft)
		{
			requestThirdMenuObj = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	var url = "http://www.kinar.ee/ajax_thirdmenu_block.php?nodepath=/"+nodePath;
	requestThirdMenuObj.open("GET", url, true);
	requestThirdMenuObj.onreadystatechange = updateThirdMenu;
	requestThirdMenuObj.send(null);
}
function updateThirdMenu()
{
	if(requestThirdMenuObj.readyState == 4 && requestThirdMenuObj.status == 200)
	{
		var responsetext = requestThirdMenuObj.responseText;
		topLeftBlockObj = document.getElementById('top_left_block');
		emptyNode(topLeftBlockObj);
		topLeftBlockObj.innerHTML = responsetext;
		
		showThirdMenuBlock();
		if (window.currentThirdMenu)
		{
			markThirdMenuSelected(currentThirdMenu);
		}
		sIFR_init_thirdMenu();
	}
}
function hideThirdMenuBlock()
{
	var menuID = 'third_menu_block';
	if(document.getElementById)
	{
		var menuBlockObj = document.getElementById(menuID);
		if (menuBlockObj)
		{
			menuBlockObj.style.display = 'none';
		}
	}
}
function showThirdMenuBlock(menuID)
{
	var menuID = 'third_menu_block';
	if(document.getElementById)
	{
		var menuBlockObj = document.getElementById(menuID);
		if (menuBlockObj)
		{
			menuBlockObj.style.display = 'block';
		}
	}
}

//******************************************************//
//******************************************************//

function markMainMenuSelected()
{
	
	var parentFolderIDobj = document.getElementById('parentFolderID');
	if (parentFolderIDobj)
	{
		currentMainMenu=parentFolderIDobj.value;
	}
	else
	{
		currentMainMenu = '0';
	}

	//mark main menu
	var MainMenuBlockObj = document.getElementById('main_menu_block');
	if (MainMenuBlockObj.hasChildNodes())
	{
		var children = MainMenuBlockObj.childNodes;
		for (var i = 0; i < children.length; i++) 
		{
			if (children[i].id==currentMainMenu)
			{
				children[i].className = 'bottom_menu_item_blue';
			}
			else
			{
				children[i].className = 'bottom_menu_item';
			}
		}
	}
}

function markSecondMenuSelected()
{
	var parentFolderIDobj = document.getElementById('parentFolderID');
	if (parentFolderIDobj)
	{
		currentSecondMenu=parentFolderIDobj.value;
	}
	else
	{
		currentSecondMenu = '0';
	}
	var MainMenuBlockObj = document.getElementById('main_menu_block');
	if (MainMenuBlockObj.hasChildNodes())
	{
		var children = MainMenuBlockObj.childNodes;
		//for each second menu block look for selected nodes
		for (var i = 0; i < children.length; i++) 
		{
			var secondMenuBlockObj = document.getElementById('secondMenu'+children[i].id);
			if (secondMenuBlockObj)
			{
				//look inside this second menu block for selected node
				if (secondMenuBlockObj.hasChildNodes())
				{
					var secondChildren = secondMenuBlockObj.childNodes;
					for (var x = 0; x < secondChildren.length; x++) 
					{
						if (secondChildren[x].id==currentSecondMenu)
						{
							secondChildren[x].className = 'bottom_menu_item_blue';
							currentMainMenu = children[i].id;
						}
						else if (secondChildren[x].className == 'bottom_menu_item_blue sIFR-replaced' || secondChildren[x].className == 'bottom_menu_item_blue')
						{
							secondChildren[x].className = 'bottom_menu_item';
						}
					}
				}
			}
		}
	}
	if (parentFolderIDobj)
	{
		parentFolderIDobj.value = currentMainMenu;
	}
	markMainMenuSelected();

}

function markThirdMenuSelected(currentThirdMenu)
{
	//mark Third menu
	var thirdMenuBlockObj = document.getElementById('third_menu_block');
	if (thirdMenuBlockObj.hasChildNodes())
	{
		var children = thirdMenuBlockObj.childNodes;
		for (var i = 0; i < children.length; i++) 
		{
			if (children[i].id==currentThirdMenu)
			{
				children[i].className = 'third_menu_item_blue';
			}
			else
			{
				children[i].className = 'third_menu_item';
			}
		}
	}
}

function emptyNode(obj)
{
	while(obj.firstChild)
	{
		obj.removeChild(obj.firstChild);
	}
}
