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(7, 'Russian', 0, '
'));
pages_tree.push(new Array(266, 'about_us', 7, '
'));
pages_tree.push(new Array(269, 'services', 7, '
'));
pages_tree.push(new Array(272, 'contact', 7, '
'));
pages_tree.push(new Array(273, 'faq', 7, '
'));
pages_tree.push(new Array(274, 'our_advantages', 7, '
'));
pages_tree.push(new Array(279, 'download', 7, '
'));
pages_tree.push(new Array(280, 'job', 7, '
'));
pages_tree.push(new Array(267, 'history', 266, 'История'));
pages_tree.push(new Array(268, 'experience', 266, 'Опыт'));
pages_tree.push(new Array(270, 'translations', 269, 'Переводы'));
pages_tree.push(new Array(271, 'subtitling', 269, 'Субтитрирование'));
pages_tree.push(new Array(275, 'human_resources', 274, 'Переводчики'));
pages_tree.push(new Array(276, 'software', 274, 'Софт'));
pages_tree.push(new Array(277, 'ISO_certification', 274, 'ISO 9001:2000'));
}
/**
*@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("
");
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("");
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);
}