/**
 * @author ehandelsbureauet
 */

function call(){ // this function is called right before page has finished load
categoryPictureList();
}


function systemCategories(){
    if (window.location.pathname.match(new RegExp('^/shop/news'))) {
       document.write('Nyheder');
    }
	if (window.location.pathname.match(new RegExp('^/shop/specialoffer'))) {
       document.write('Tilbud');
    }
	if (window.location.pathname.match(new RegExp('^/shop/search'))) {
       document.write('S&oslash;geresultater');
    }
}


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;
            }
            
        }
    }
    
}


