Attached to my template, that I received from my slicer, there was a javascript file for coloring the menu items. Now I need to convert the template to a Drupal template. The javascript is based on the fact that every menu item has an id, according to the order of the items. In Drupal, the menu items only have classes (menu-341, menu-342 etc.,). I know I can adjust the javascript, so it gets the menu items by class, but it actually isn't possible because then I need to completely upset the whole file, what I try to prevent.
So can I add an ID to all my main menu items, something like 'menu-item-1', 'menu-item-2', etc.? Should I do this in template.tpl.php, or directly change the output in page.tpl.php?
Thanks for help.
EDIT: I'm desperate because I just don't know how to fix this. Is there another way to color my menu items? The script I'm using picks the menu items on their ascending id (custom-menu-item-id-x), and gives them a background, out of an array, wich associates with the 'x' of the ID. Four colors: color 1 for item 1, color 2 for item 2, color 1 for item 5 etc..... Isn't there another way to fix this? Couldn't I let jQuery pick them automatically in the ascending order (first item it encounters gets the first background, second item second background etc.)? Please come up with ideas. I tried everything, in my opinion.
This is my current script:
//Sequence of the background colors from the menu items, from left to right.
var backgrounds = ["blue", "green", "pink", "purple"];
//Gives the menu items a style when hovering over it, in the sequence of the setting in the variable 'backgrounds', on top.
jQuery(document).ready(function MenuColor($){
for (var i = 0; i <= 10 ; i++) {
document.getElementById("custom-menu-item-id-" + (i + 1)).onmouseover = (function(valueOfI){ return function() {
this.style.background = "url('images/" + backgrounds[(valueOfI % backgrounds.length)] + ".jpg')";
}; })(i);
var ActiveLi = $('.active').attr('id');
if("custom-menu-item-id-" + (i + 1) != ActiveLi) {
document.getElementById("custom-menu-item-id-" + (i + 1)).onmouseout = function() {
this.style.background = 'none';
}
}
}
});