/**
 * @author ehandelsbureauet for toolsonline
 * this script is copyrighted and is not allowed to be used in any way without permission
 */
function init(){
    fixPrMenuSpanTagMenu();
    categoryPictureList();
}


function fixPrMenuSpanTagMenu(){
    var tempSpan = document.getElementById('ProductMenu_Table').getElementsByTagName('SPAN');
    for (var i = 0; i < tempSpan.length; i++) {
        if (tempSpan[i].className == "ProductMenu_MenuItemBold") {
            tempSpan[i].parentNode.innerHTML += tempSpan[i].innerHTML;
            tempSpan[i].style.display = "none";
            tempSpan[i].innerHTML = "";
        }
    };
    }


function categoryPictureList(){
    var imgs = {}; // Map img tag from url to img object
    // Find all images in menu, swap their a hrefs title into the place of the image
    var productMenu = document.getElementById("ProductMenu_Table");
    
    var img = productMenu.getElementsByTagName("IMG");
    
    for (var i = 0; i < img.length; i++) {
        var parent = img[i].parentNode; // The a tag
        var title = (parent.tagName == "B" ? parent.parentNode.title : parent.title); // title of a tag, which becomes link text
        var href = (parent.tagName == "B" ? parent.parentNode.href : parent.href)
        if (title) {
            imgs[href] = img[i];
            parent.innerHTML += title;
        }
    }
    // Find product list and move the image into that position
    var a = document.getElementsByTagName("A");
    for (var i = 0; i < a.length; i++) {
        if ((a[i].className == "SubCats_Prodlink")) {
        
            var img = imgs[a[i].href];
            
            if (img) {
                var innerHTML = a[i].innerHTML;
                a[i].innerHTML = "";
                a[i].appendChild(img);
                a[i].innerHTML += innerHTML;
            }
            
        }
    }
    
}
