pages_tree = new Array(); // global pages tree array bunch_tree = new Array(); // global bounch of pages ids STD_WIDTH = 93; // std width of menu item (see CSS file width + padding) STD_HEIGHT = 23; // std height of menu item (see CSS file height + padding) isOver = false; // boolean flag for onMouseOver TIMER_INT = null; // interval timer id SITE_URL = 'http://www.serious.ro'; // default root of site TIMER_PERIOD = 600; // miliseconds interval to hide one branch /** *@params void *@return void *@description function allocate and initialize a complete array of arrays of properties for all menu items */ function populate() { pages_tree.push(new Array(2, 'Romanian', 0, '')); pages_tree.push(new Array(17, 'about_us', 2, '')); pages_tree.push(new Array(18, 'services', 2, '')); pages_tree.push(new Array(19, 'our_advantages', 2, '')); pages_tree.push(new Array(20, 'faq', 2, '')); pages_tree.push(new Array(21, 'download', 2, '')); pages_tree.push(new Array(22, 'job', 2, '')); pages_tree.push(new Array(23, 'contact', 2, '')); pages_tree.push(new Array(24, 'history', 17, 'Istoric')); pages_tree.push(new Array(27, 'experience', 17, 'Experienţă')); pages_tree.push(new Array(28, 'translations', 18, 'Traduceri')); pages_tree.push(new Array(29, 'subtitling', 18, 'Subtitrări')); pages_tree.push(new Array(32, 'human_resources', 19, 'Traducători')); pages_tree.push(new Array(33, 'software', 19, 'Software')); pages_tree.push(new Array(34, 'ISO_certification', 19, 'Sistem ISO 9001')); pages_tree.push(new Array(40, 'freelancers', 22, 'Colaboratori')); pages_tree.push(new Array(109, 'articles', 21, 'Articole')); pages_tree.push(new Array(305, 'faq', 21, 'Întrebări frecvente')); pages_tree.push(new Array(306, 'interpreting', 18, 'Interpretariat')); } /** *@params int branch root id *@return str path until root site *@description recursive function to return path between site root and branch root */ function findParents(intParentId) { if (intParentId == 0) { return ""; } var k = 0; while (k < pages_tree.length) { if (pages_tree[k][0] == intParentId) { return findParents(pages_tree[k][2]) + "/" + pages_tree[k][1]; break; } k++; } } /** *@params int item parent id, str parent path name *@return void *@description recursive function to draw child items of parent item */ function drawDivs(intParent, strParentName) { var k = 0; while (k < pages_tree.length) { if (pages_tree[k][2] == intParent) { document.write("
" + pages_tree[k][3] + "
"); drawDivs(pages_tree[k][0], strParentName + "/" + pages_tree[k][1]); } k++; } } /** *@params str branch root optional *@return void *@description function draw full menu or branch menu if optional argument */ function menu() { document.open(); if (arguments.length) { strRootName = arguments[0]; } else { strRootName = pages_tree[0][1]; } for (i = 0; i < pages_tree.length; i++) { if (pages_tree[i][1] == strRootName) { strParentName = SITE_URL + findParents(pages_tree[i][2]); document.write("
" + pages_tree[i][3] + "
"); drawDivs(pages_tree[i][0], strParentName + "/" + pages_tree[i][1]); break; } } document.close(); } /** *@params item DIV object *@return void *@description function display childs of current item and fill next element into the visible items ids array, also hide childs of brother items for the current item */ function showChild(objElement) { strName = objElement.getAttribute("id"); intId = parseInt(strName.substr(1, strName.length)); isOver = true; // check if pop needed - last item not current, parent or childs childsArr = new Array(); for (i = 0; i < pages_tree.length; i++) { if (pages_tree[i][2] == intId) { childsArr.push(pages_tree[i][0]); } } boolTest = false; if (bunch_tree.length > 0) { for (j = 0; j < (bunch_tree[bunch_tree.length - 1]).length; j++) { if (bunch_tree[bunch_tree.length - 1][j] == intId) { boolTest = true; break; } for (i = 0; i < childsArr.length; i++) { if (childsArr[i] == bunch_tree[bunch_tree.length - 1][j]) { boolTest = true; break; } } } if (!boolTest) { arrCollect = bunch_tree.pop(); try { for (i = 0; i < arrCollect.length; i++) { objItem = document.getElementById("e" + arrCollect[i]); objItem.style.top = 0; objItem.style.left = 0; objItem.style.visibility = "hidden"; } } catch (e) { } } } // push new try { intTopCss = parseInt((objElement.style.top).substr(0, objElement.style.top.length-2)); intLeftCss = parseInt((objElement.style.left).substr(0, objElement.style.left.length-2)); } catch (e) { } if (!isNaN(intTopCss) && !isNaN(intLeftCss)) { intTop = intTopCss + STD_HEIGHT; // childs bottom-displace intLeft = intLeftCss; // + STD_WIDTH; // childs left-displace } else { intTop = objElement.offsetTop; intLeft = objElement.offsetLeft; intTop += STD_HEIGHT; // top-down root menu // intLeft += STD_WIDTH; // left-right root menu } bunch_tree.push(new Array()); for (i = 0; i < pages_tree.length; i++) { objItem = document.getElementById("e" + pages_tree[i][0]); if (pages_tree[i][2] == intId) { objItem.style.top = intTop; objItem.style.left = intLeft; //-- begin store visible arr in a bunch here in order to hide later if (objItem.style.visibility != "visible") { (bunch_tree[bunch_tree.length - 1]).push(pages_tree[i][0]); } //-- end store objItem.style.visibility = "visible"; // intTop += STD_HEIGHT; // top-down branches menu intLeft += STD_WIDTH; // left-right branches menu } } if ((bunch_tree[bunch_tree.length - 1]).length == 0) { bunch_tree.pop(); } } /** *@params item DIV object *@return void *@description function set status of global boolean flag for onMouseOver */ function hideChild(objElement) { isOver = false; } /** *@params void *@return void *@description function hide unhided childs of branch root item and unfill next element into the visible items ids array */ function collect() { arrCollect = new Array(); if (!isOver) { arrCollect = bunch_tree.pop(); try { for (i = 0; i < arrCollect.length; i++) { objItem = document.getElementById("e" + arrCollect[i]); objItem.style.top = 0; objItem.style.left = 0; objItem.style.visibility = "hidden"; } } catch (e) { } } } populate(); if (!TIMER_INT) { TIMER_INT = setInterval("collect()", TIMER_PERIOD); }