﻿

/*************** start of top navigation guides JS code *************/
// this is an dynamic image.onload function that will
// automatically resize the tab element to the size of it's tab image





function setTabImageWidth() {
    this.tabEm.style.width = this.width + 'px';
    resizeTabs();
    return true;
}


function resizeTabs() {
    if (timer == false) {
        timer = true;
        setTimeout("resizeTabs2()", 500);
    }
}

function resizeTabs2() {

    windowWidth = (f_clientWidth() - 30);
    totalTabs = mast_total_channels;
    tabsWidth = 0;
    tabsWidths = new Array();
    for (i = totalTabs; 0 < i; i--) {
        document.getElementById('CatTab_' + i).style.display = 'block';
        tabsWidths[i] = getElementWidth('CatTab_' + i)+2;
        tabsWidth += tabsWidths[i];
    }

   // document.getElementById('WWidth').value = windowWidth;
   // document.getElementById('Ttabs').value = tabsWidth;

    tabsWidth += getElementWidth('CatTab_all') + 2;
    
    for (i = totalTabs; 0 < i; i--) {
        if (windowWidth <= tabsWidth && tabsWidth > 800 && document.getElementById('CatTab_' + i).className != 'channelTab on') {
            // If mast too wide, hide the tab unless its currently highlighted
            tabsWidth = (tabsWidth - tabsWidths[i]);
            document.getElementById('CatTab_' + i).style.display = 'none';
        }
    }


    
    document.getElementById('catlist').style.width = (tabsWidth + 10) + 'px';
    timer = false;
}


function f_clientWidth() {
    return f_filterResults(
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function SetupTabSizes() {
    for (i = mast_total_channels; 0 < i; i--) {
        document.getElementById('CatTab_' + i).style.width = getElementWidth('CatTab_' + i);
    }
}

function getElementWidth(Elem) {
    if (document.getElementById) {
        var elem = document.getElementById(Elem);
    } else if
   (document.all)
    {
    var elem = document.all[Elem];
}


var prefix = null;
var xPos = parseInt(elem.style.width.replace('px',''));

if (xPos == 0 || isNaN(xPos)) {
    if ('undefined' != typeof (elem.offsetWidth)) {
        prefix = ' element.style.offsetWidth';
        xPos = parseInt(elem.offsetWidth);
    }
    else if ('undefined' != typeof (elem.style.pixelWidth)) {
        prefix = ' element.style.pixelWidth';
        xPos = parseInt(elem.style.pixelWidth);
    } 
}
return  xPos;
               } 


/*************** end of top navigation guides JS code *************/

