﻿//browser detection
var strUserAgent = navigator.userAgent.toLowerCase();
var isIE = strUserAgent.indexOf("msie") > -1;
var isNS6 = strUserAgent.indexOf("netscape6") > -1;
var isNS4 = !isIE && !isNS6 && parseFloat(navigator.appVersion) < 5;

/*
Tab Control
*/
function tabcontrol(tabholder, contentholder) {

    this.tabholder = tabholder;
    this.contentholder = contentholder;
    this.currenttab;
    this.tabs = new Array();

    // Iterate through adding any current tabs
    var lilist = tabholder.getElementsByTagName("LI");
    for (var i = 0; i < lilist.length; i++) {
        var otab = lilist[i];
        if (isIE) {
            otab.attachEvent("onclick", this.switchtab);
        }
        else {
            otab.addEventListener("click", this.switchtab, false);
        }
        // Get the content
        var ocontent = contentholder.getElementsByTagName("UL")[i];
        var ctab = new tab(otab, ocontent, this, "list");
        this.tabs.push(ctab);
        // Set the first sub menu as the current one
        if (i == 0) {
            this.currenttab = ctab;
        }
    }
}

tabcontrol.prototype.switchtab = switchtab;

function switchtab(e) {

    // get the src object
    var o;
    var ie_var = "srcElement";
    var moz_var = "target";
    // target for Moz, et al. - srcElement for IE
    e[moz_var] ? o = e[moz_var] : o = e[ie_var];

    // If the object isn't a link get the link
    while (o.tagName != "LI") {
        o = o.parentNode;
    }

    if (o.tab != o.tab.tabcontrol.currenttab) {
        o.tab.show();
    }

}

/*
Tabs
*/
function tab(otab, ocontent, tabcontrol, otype) {
    // Set the controls
    this.tabcontrol = tabcontrol;
    this.tab = otab;
    this.content = ocontent;
    this.type = otype;
    // Assign the tab to the element
    otab.tab = this;
}

tab.prototype.show = function() {
    // show the selected tab
    var tabli = this.tab;
    tabli.className = "current";
    this.content.className = "portfolio";
    // Hide the current tab
    this.tabcontrol.currenttab.hide();
    // Set the current tab
    this.tabcontrol.currenttab = this;
};

tab.prototype.hide = function() {
    // show the selected tab
    var tabli = this.tab;
    tabli.className = "portfolio";
    this.content.className = "hidden";
};

