//Variable definitions var subcategories = new Array(); var req_processing = false; //Adding in_array method to an Array object Array.prototype.in_array = function ( obj ) { var len = this.length; for ( var x = 0 ; x <= len ; x++ ) { if ( this[x] == obj ) return true; } return false; } /* * Function to fetch submenu data and display it * Params: * id - category id */ function get_subcategory(id) { //Checking if script is interacting with server if(req_processing == false) { var elem_id = id; //Checking if data has been fetched previously if(subcategories[id] == "" || typeof subcategories[id] == "undefined") { //Enabling processing mode req_processing = true; //Processing request new Ajax.Request("http://reklamawww.sstore.pl/menu_server.php", { method: "POST", parameters: {category_id: '"'+id+'"'}, onSuccess: function(response) { response = eval(response.responseText); if(response != false) { var categories = response; var categories_html = new Array(); if(typeof categories == "object" || typeof categories == "Array") { //Creating content objects subcategories[id] = new Array(); for(i in categories) { add_elem(categories[i], elem_id); } } } //Disabling processing mode req_processing = false; }, onError: function(){req_processing = false;} }); } } } /* * Function to create elements to be appended to submenu * Params: * data - Array[link, text] * id - element id */ function add_elem(data, id) { var div_main = document.createElement("div"); div_main.id = data['id']; div_main.className = "submenuKontener"; /*if(div_main.addEventListener) { div_main.addEventListener("mouseover", function(){return get_subcategory(data['id']);}, false); div_main.addEventListener("mouseout", function(){return hide_submenu(data['id']);},false); } else if(div_main.attachEvent) { div_main.attachEvent("onmoseover", function(){return get_subcategory(data['id']);}); div_main.attachEvent("onmouseout", function(){return hide_submenu(data['id']);}); } else*/ { div_main.onmouseover = (function(id){return function(){get_subcategory(id);}})(data['id']); } var content = document.createElement("p"); content.innerHTML = ""; var a = document.createElement("a"); a.href = data['link']; a.innerHTML = data['text']; var div = document.createElement("div"); div.id = "category_"+data['id']+"_submenu"; content.appendChild(a); div_main.appendChild(content); div_main.appendChild(div); //Sending prepared content array to global subcategories array if(subcategories[id].indexOf(div_main) == -1) { subcategories[id].push(div_main); //Appending objects to div and array $("category_"+id+"_submenu").appendChild(div_main); $("category_"+id+"_submenu").className = "submenu"; } else div_main = null; var parent_zindex = $("category_"+id+"_submenu").parentNode.style.zIndex; $("category_"+id+"_submenu").style.zIndex = (parent_zindex+1); return; } /* * Function to hide submenu * Params: * id - element id */ function hide_submenu(id) { $("category_"+id+"_submenu").style.display = "none"; } function hide_tree(tree) { tree = tree.split("_"); for(i=tree.length-1; i>=0; i--) { var output = ""; for(j=0; j<=i; j++) { var separator = (output == "" ? "" : "_"); output = output+separator+tree[j]; } hide_submenu(output); } }