﻿var tabLinks = new Array();
var contentDivs = new Array();
var stepDivs = new Array();
var child = new Array();
var currentTab = new Object();

function getCurrentTab() {
    for (var i in contentDivs) {
        var n = eval('contentDivs.' + i);
        if (eval('contentDivs.' + i).className == "tabContent") {
            currentTab = contentDivs[i];
        }
    }
}

function slideshow() {
    getCurrentTab();
    child = document.getElementById(currentTab.id).childNodes;
    if (stepDivs.length < 1) {
        for (var i = 0; i < child.length; i++) {
            if (child[i].nodeName == "DIV") {
                //stepDivs = new Array();
                stepDivs.push(child[i]);
            }
        }
    }
    else {
        stepDivs = new Array();
        for (var i = 0; i < child.length; i++) {
            if (child[i].nodeName == "DIV") {
                stepDivs.push(child[i]);
            }
        }
    }
    showslide();
}

function showslide() {
    for (var i = 0; i < stepDivs.length; i++) {
        var test = stepDivs[i];
        if (test == stepDivs[0]) {
            stepDivs[i].className = 'selected';
            var start = document.getElementById("btnPrevious");
            start.className = 'hide';
            var end = document.getElementById("btnNext");
            end.className = 'btn show';
        }
        else {
            stepDivs[i].className = 'tabContent hide';
        }
    }
}

function shownextslide() {
    var q = stepDivs.length - 2;

    var start = document.getElementById("btnPrevious");
    start.className = 'btn show';

    for (var i = 0; i < stepDivs.length; i++) {
        var test = stepDivs[i];
        if (test.className == "selected" && i < q) {
            var p = i + 1;
            stepDivs[p].className = 'selected';
            stepDivs[i].className = 'tabContent hide';
            i++;
        }
        else if (test.className == "selected" && i == q) {
            var p = i + 1;
            stepDivs[p].className = 'selected';
            stepDivs[i].className = 'tabContent hide';
            var end = document.getElementById("btnNext");
            end.className = 'hide';
        }
    }
}

function showpreviousslide() {
    var q = 1;

    var end = document.getElementById("btnNext");
    end.className = 'btn show';

    for (var i = 0; i < stepDivs.length; i++) {
        var test = stepDivs[i];
        if (test.className == "selected" && i > q) {
            var p = i - 1;
            stepDivs[p].className = 'selected';
            stepDivs[i].className = 'tabContent hide';
            i++;
        }
        else if (test.className == "selected" && i == q) {
            var p = i - 1;
            stepDivs[p].className = 'selected';
            stepDivs[i].className = 'tabContent hide';
            var end = document.getElementById("btnPrevious");
            end.className = 'hide';
        }
    }
}
    function init() {
    var tabListItems = document.getElementById('tabs').childNodes;
    for (var i = 0; i < tabListItems.length; i++) {
        if (tabListItems[i].nodeName == "LI") {
            var tabLink = getFirstChildWithTagName(tabListItems[i], 'A');
            var id = getHash(tabLink.getAttribute('href'));
            tabLinks[id] = tabLink;
            contentDivs[id] = document.getElementById(id);
        }
    }

    var i = 0;

    for (var id in tabLinks) {
        tabLinks[id].onclick = showTab;
        tabLinks[id].onfocus = function() {
            this.blur()
        };
        if (i == 0) tabLinks[id].className = 'selected';
        i++;
    }

    var i = 0;

    for (var id in contentDivs) {
        if (i != 0) contentDivs[id].className = 'tabContent hide';
        i++;
    }

    detectBrowser();
    slideshow();
}

function showTab() {
    var selectedId = getHash(this.getAttribute('href'));

    for (var id in contentDivs) {
        if (id == selectedId) {
            tabLinks[id].className = 'selected';
            contentDivs[id].className = 'tabContent';
        }
        else {
            tabLinks[id].className = '';
            contentDivs[id].className = 'tabContent hide';
        }
    }
    slideshow();
    return false;
}

function getFirstChildWithTagName(element, tagName) {
    for (var i = 0; i < element.childNodes.length; i++) {
        if (element.childNodes[i].nodeName == tagName) return element.childNodes[i];
    }
}

function getHash(url) {
    var hashPos = url.lastIndexOf('#');
    return url.substring(hashPos + 1);
}


function detectBrowser() {
    var browser = navigator.appName;
    var b_version = navigator.appVersion;
    var user_version = navigator.userAgent.toLowerCase();
    if (browser == "Microsoft Internet Explorer") {
        for (var id in contentDivs) {
            if (id == "IExplorer") {
                tabLinks[id].className = 'selected';
                contentDivs[id].className = 'tabContent';
            }
            else {
                tabLinks[id].className = '';
                contentDivs[id].className = 'tabContent hide';
            }
        }
    }
    else if (browser == "Netscape") {
        if (user_version.indexOf("firefox") + 1) {
            for (var id in contentDivs) {
                if (id == "firefox") {
                    tabLinks[id].className = 'selected';
                    contentDivs[id].className = 'tabContent';
                }
                else {
                    tabLinks[id].className = '';
                    contentDivs[id].className = 'tabContent hide';
                }
            }
        }
        else if (user_version.indexOf("chrome") + 1) {
            for (var id in contentDivs) {
                if (id == "chrome") {
                    tabLinks[id].className = 'selected';
                    contentDivs[id].className = 'tabContent';
                }
                else {
                    tabLinks[id].className = '';
                    contentDivs[id].className = 'tabContent hide';
                }
            }
        }
        else if (user_version.indexOf("safari") + 1) {
            for (var id in contentDivs) {
                if (id == "Safari") {
                    tabLinks[id].className = 'selected';
                    contentDivs[id].className = 'tabContent';
                }
                else {
                    tabLinks[id].className = '';
                    contentDivs[id].className = 'tabContent hide';
                }
            }
        }
    }
    else if (browser == "Opera") {
        for (var id in contentDivs) {
            if (id == "Opera") {
                tabLinks[id].className = 'selected';
                contentDivs[id].className = 'tabContent';
            }
            else {
                tabLinks[id].className = '';
                contentDivs[id].className = 'tabContent hide';
            }
        }
    }
}