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(1, 'English', 0, 'English')); pages_tree.push(new Array(78, 'about_us', 1, '')); pages_tree.push(new Array(79, 'services', 1, '')); pages_tree.push(new Array(80, 'our_advantages', 1, '')); pages_tree.push(new Array(81, 'faq', 1, '')); pages_tree.push(new Array(82, 'download', 1, '')); pages_tree.push(new Array(83, 'job', 1, '')); pages_tree.push(new Array(84, 'contact', 1, '')); pages_tree.push(new Array(236, 'human_resources', 80, 'Translators')); pages_tree.push(new Array(234, 'software', 80, 'Software')); pages_tree.push(new Array(235, 'ISO_certification', 80, 'ISO 9001:2000')); pages_tree.push(new Array(117, 'history', 78, 'History')); pages_tree.push(new Array(118, 'experience', 78, 'Experience')); pages_tree.push(new Array(218, 'translations', 79, 'Translations')); pages_tree.push(new Array(219, 'subtitling', 79, 'Subtitling')); pages_tree.push(new Array(278, 'freelancers', 83, 'Freelancers')); } /** *@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); }