﻿function fRotateImages() {
    var arrayLinks = document.getElementById("advBanners").getElementsByTagName("div");
    var iCurrentIndex = -1;
    var iNextIndex;
    var iTime = 3000;

    if (arrayLinks.length > 0) {
        //find current
        for (var i = 0; i < arrayLinks.length; i++) {
            if (arrayLinks[i].style.display == "block") {
                iCurrentIndex = i;
            }
        }

        //show new image, hide current
        switch (iCurrentIndex) {
            case -1:
                iNextIndex = 0;
                break;
            case (arrayLinks.length - 1):
                iNextIndex = 0;
                break;

            default:
                iNextIndex = iCurrentIndex + 1;
                break;
        }
        if (iCurrentIndex != -1) {
            arrayLinks[iCurrentIndex].style.display = "none";
        }
        arrayLinks[iNextIndex].style.display = "block";
        //loop this
        setTimeout(fRotateImages, iTime);
    }
}
//change theme
function createMenu() {
    if (document.getElementById) {
        if (document.getElementById("ctl00_fwRoot_fwContent_fwMenu_uxM")) {
            var menu = document.getElementById("ctl00_fwRoot_fwContent_fwMenu_uxM");
            var liList = menu.getElementsByTagName("li");
            for (i = 0; i < liList.length; i++) {
                // markere parent
                if (liList[i].className.indexOf("Current") > -1) {
                    if (liList[i].parentNode.parentNode.tagName == "li") {
                        liList[i].parentNode.parentNode.className = "Current Top";
                    }
                }

                // sjekk for undermeny
                sublist = liList[i].getElementsByTagName("ul");
                if (sublist.length > 0) {
                    if (liList[i].className == "") {
                        liList[i].className = "Parent";
                    }
                    else {
                        liList[i].className += " Parent Top";
                    }
                }
            }
        }
    }
}

function openSubMenu(tagA) {
    var parent = tagA.parentNode;
    var ulList = parent.getElementsByTagName("ul");
    var d = tagA.getElementsByTagName("div");
    if (!ulList || ulList.length <= 0) {
        return;
    }

    for (iUl = 0; iUl < ulList.length; iUl++) {
        var ul = ulList[iUl];

        if (ul.style.display == 'none' || ul.style.display == "") {
            ul.style.display = 'block';
            d[0].className = "expand";
            tagA.className = "active";
        }
        else {
            ul.style.display = 'none';
            d[0].className = "colapse";
            tagA.className = "";
        }
    }
}

function setTopMenu() {
    var topMenu = document.getElementById("TopMenu");
    var liList = topMenu.getElementsByTagName("li");
    if (!liList || liList.length <= 0) {
        return;
    }

    liList[0].className = "first";
    liList[liList.length - 1].className = "last";
}
