﻿
/* 
 *
 *  Tabbing functionality
 *
 */
 
// preload tab images: 
l_professional_profile_on = new Image();
l_professional_profile_on.src = "/FCWSite/Img/subnav/professional_profile_on.gif";
l_professional_profile = new Image();
l_professional_profile.src = "/FCWSite/Img/subnav/professional_profile.gif";

l_publications_on = new Image();
l_publications_on.src = "/FCWSite/Img/subnav/publications_on.gif";
l_publications = new Image();
l_publications.src = "/FCWSite/Img/subnav/publications.gif";

l_prior_experience_on = new Image();
l_prior_experience_on.src = "/FCWSite/Img/subnav/prior_experience_on.gif";
l_prior_experience = new Image();
l_prior_experience.src = "/FCWSite/Img/subnav/prior_experience.gif";

l_project_experience_on = new Image();
l_project_experience_on.src = "/FCWSite/Img/subnav/project_experience_on.gif";
l_project_experience = new Image();
l_project_experience.src = "/FCWSite/Img/subnav/project_experience.gif";

l_professional_affiliations_on = new Image();
l_professional_affiliations_on.src = "/FCWSite/Img/subnav/professional_affiliations_on.gif";
l_professional_affiliations = new Image();
l_professional_affiliations.src = "/FCWSite/Img/subnav/professional_affiliations.gif";

l_overview_on = new Image();
l_overview_on.src = "/FCWSite/Img/subnav/overview_on.gif";
l_overview = new Image();
l_overview.src = "/FCWSite/Img/subnav/overview.gif";

l_professionals_on = new Image();
l_professionals_on.src = "/FCWSite/Img/subnav/professionals_on.gif";
l_professionals = new Image();
l_professionals.src = "/FCWSite/Img/subnav/professionals.gif";

l_sample_projects_on = new Image();
l_sample_projects_on.src = "/FCWSite/Img/subnav/sample_projects_on.gif";
l_sample_projects = new Image();
l_sample_projects.src = "/FCWSite/Img/subnav/sample_projects.gif";

l_news_on = new Image();
l_news_on.src = "/FCWSite/Img/subnav/news_on.gif";
l_news = new Image();
l_news.src = "/FCWSite/Img/subnav/news.gif";

l_sales_on = new Image();
l_sales_on.src = "/FCWSite/Img/subnav/sales_on.gif";
l_sales = new Image();
l_sales.src = "/FCWSite/Img/subnav/sales.gif";

l_product_support_on = new Image();
l_product_support_on.src = "/FCWSite/Img/subnav/product_support_on.gif";
l_product_support = new Image();
l_product_support.src = "/FCWSite/Img/subnav/product_support.gif";

/* end preload */

// end preload

function tab (uniqueID, domAreaID, domImageID) {
    this.id = uniqueID;
    
    this.area = hub$(domAreaID);
    this.turnedOn = false;
    if (this.area && this.area.style.display!='none')
	    this.turnedOn = true;
	
    this.image = hub$(domImageID);
    this.title = '';
    if (this.image)
        this.title = this.image.alt;
    
    this.click=function(e) {
	    /* do RSH stuff */
	    this.turnOn();
        
        /* tab event handler */
        if (this.ontabclick)
            this.ontabclick();
    }
    this.turnOn=function() {
	    this.area.style.display='block';        
	    this.image.src=this.image.src.replace(/.gif/,"_on.gif");
	    this.turnedOn=true;
    }
    this.turnOff=function() {
	    this.area.style.display='none';
	    this.image.src=this.image.src.replace(/_on.gif/,".gif");
	    this.turnedOn=false;
    }
    this.mouseOver=function() {
	    if (!this.turnedOn)
		    this.image.src=this.image.src.replace(/.gif/,"_on.gif");
    }
    this.mouseOut=function() {
	    if (!this.turnedOn)
		    this.image.src=this.image.src.replace(/_on.gif/,".gif");
    }
}
function tabList () {
    this.tabs = new Array();
    this.tabHash = new Object();
	
    this.addTab = function(tab) {
        var tabID = tab.id;
	    var tabIndex = this.tabs.push(tab);
	    this.tabHash[tabID] = tabIndex;
	    return tab;
    }
    this.getTab = function(tabID) {
	    var tabIndex=this.tabHash[tabID];
	    if (tabIndex) 
		    return this.tabs[tabIndex - 1];
	    else 
		    return null; /* alert('Error: tab id does not exist (' + tabID + ')'); */
    }
    this.reset = function() { 
	    for(var i = 0; i < this.tabs.length; i++) 
	        this.tabs[i].turnOff(); 
    } 
    this.click = function(tabID) {
	    var tab=this.getTab(tabID);
	    if (tab) { 
	        this.reset(); 
	        tab.click();
	    }
    }
    this.mouseOver = function(tabID) {
	    var target=this.getTab(tabID);
	    if (target) target.mouseOver();
    }
    this.mouseOut = function(tabID) {
	    var target=this.getTab(tabID);
	    if (target) target.mouseOut();
    }
}

/* Init our tabList: */
window.tabs = new tabList();

// Hold our page title:
window.originalTitle = document.title;

function initialize() {
    // initialize the DHTML History framework
    dhtmlHistory.initialize();

    // subscribe to DHTML history change events
    dhtmlHistory.addListener(changeTabs);
        
    // if this is the first time we have
    // loaded the page...
    if (dhtmlHistory.isFirstLoad()) { 
        
        /* Reset our bookmarked page */
        var currentLocale=dhtmlHistory.getCurrentLocation();  
        currentLocale = currentLocale.split(',');
        if (currentLocale[0] != '')
            tabClick(currentLocale[0]);
    } 
}		

function changeTabs(newLocation, historyData) {
    newLocation = newLocation.split(',');
    if (newLocation) {
        var tab = tabs.getTab(newLocation[0]);
        if (tab) {
            tabs.click(newLocation[0]);
            document.title = historyData;
            
            // Hack for contacts 'tab'
            var contacts = hub$('contactsTab');
            if (contacts) {
                contacts.style.display='none';
            }
        }
        else  // This could be a jump link:
        {
            for (var i = 0; i < window.tabs.length; i++) {
                if (window.tabs[i].turnedOn)
                    document.title = window.tabs[i].title  + " | " + window.originalTitle;
            }
        }
    }
}
// This should be called from the onclick event of the tab:
function tabClick(tabID) {
    if (tabID != '') {
        var tab = tabs.getTab(tabID);
        if (tab) {
            changeTabs(tabID, tab.title + " | " + window.originalTitle);
            dhtmlHistory.add(tabID, document.title);
        }
    }
    return true;
}

/* 
 * Utilities
 *
 */
 
function hub$(element) {
    if (arguments.length > 1) {
        var elements = [];
        for (var i = 0; i < arguments.length; i++)
            elements.push(hub$(arguments[i]));
        return elements;
    }
    var domItem;
    if (document.getElementById)
        domItem = document.getElementById(element);
    else if (document.all)
        domItem = document.all[element];
    return domItem;
}
function addEventListener(element, event, func, flag) {
    if (element.addEventListener) 
        element.addEventListener(event, func, flag);
    else if (element.attachEvent) 
        element.attachEvent("on"+event, func);
} 
function getTarget(e) {
    var targ;
    if (!e) var e = window.event;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) // defeat Safari bug
	    targ = targ.parentNode;
    return targ;
}
