The first idea is possible, but random means random, so there is always the possibility of a repeat of one color on two links unless you make the code fairly complex, I'll probably look into that. But here's a solution that will minimize the chance of a repeat, while maintaining randomness:
Code:
<script type="text/javascript">
(function(){
//Define array of colors
colorize.mycolors = ['red', 'blue', 'green', 'yellow', 'black', 'orange', 'purple', 'pink', 'brown'];
//comment out the below line if you want the same initial colors each time the page loads
colorize.mycolors.sort(function(){return 0.5 - Math.random();});
function colorize(e, el, i){
e = e || window.event;
el.style.color = e.type === 'mouseover'? colorize.mycolors[i] : '';
}
colorize.set = function(anc, i){
anc.onmouseover = anc.onmouseout = function(e){colorize(e, anc, i);};
};
colorize.setup = function(){
var anc = document.getElementById('menu').getElementsByTagName('a'), i = anc.length - 1;
for (i ; i > -1; --i){
colorize.set(anc[i], i);
}
//comment out the below line if you want the same colors each time for each link
setInterval(function(){colorize.mycolors.sort(function(){return 0.5 - Math.random();});}, 3000);
};
onload = colorize.setup;
})();
</script>
Notice the comments in the code for ways you may change the outcome.
Bookmarks