function js_tab($strJsTab, $strTab)
{
    // Find Selected Item
    var $objJsTab = document.getElementById($strJsTab);
    if ( $objJsTab.hasChildNodes() )
    {
        var $nlChildren = $objJsTab.childNodes;
        for ( var $n = 0; $n < $nlChildren.length; $n++ )
        {
            if ( typeof($nlChildren[$n].className) != "undefined")
            {
                if ( $nlChildren[$n].className == "nav" )
                {
                    if ( $nlChildren[$n].hasChildNodes() )
                    {
                        var $nlNavItems = $nlChildren[$n].childNodes;
                        for ( var $x = 0; $x < $nlNavItems.length; $x ++ )
                        {
                            if ( typeof($nlNavItems[$x].className) != "undefined")
                            {
                                if ( $nlNavItems[$x].className == "js_tab_s" )
                                {
                                    $nlNavItems[$x].className = "js_tab_x";
                                    break;
                                }
                            }
                        }
                    }
                }

                if ( $nlChildren[$n].className == "js_tab_s" )
                {
                    $nlChildren[$n].className = "js_tab_x";
                    break;
                }
            }
        }

        // Select the new Nav Bar Item
        var $objNav = document.getElementById($strTab + '_tab');
        $objNav.className = "js_tab_s";

        // Select the new Content Div
        var $objDiv = document.getElementById($strTab);
        $objDiv.className = "js_tab_s";
    }
}

function js_tab_tour($strJsTab, $strTab)
{
    js_tab($strJsTab, $strTab);
    var $objMainDiv = document.getElementById("main");
    $objMainDiv.style.backgroundImage = "url(/img/default/clubtour-hole" + $strTab + ".jpg)";
}

// Load the current tab
function js_tab_load_hash()
{
    if ( window.location.hash.length >= 1 )
    {
        var $strHash = window.location.hash.slice(1);
        var $aJsTabs = getElementsByClass("js_tab");
        if ( $aJsTabs.length == 1 )
        {
            js_tab($aJsTabs[0].id, $strHash);
        }
    }
}
if (window.attachEvent) {window.attachEvent('onload', js_tab_load_hash);}
else if (window.addEventListener) {window.addEventListener('load', js_tab_load_hash, false);}
else {document.addEventListener('load', js_tab_load_hash, false);} 

function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if ( node == null )
        node = document;
    if ( tag == null )
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++) {
        if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}
function pinchWidth()
{
    var $nEffectiveWidth = effectiveWindowSize(900, 622);
    if ( $nEffectiveWidth < 900 )
    {
        var $nPinch = 900 - $nEffectiveWidth + 10;
        $nPinch = $nPinch < 260 ? $nPinch : 260;
        var $objLogoImg = document.getElementById("logoimg");
        //alert("Your window was " + $nEffectiveWidth + "px wide, so I'm going to pinch the site by " + $nPinch + "px.");
        $objLogoImg.style.marginRight = $nPinch + "px";

    }
}

function effectiveWindowSize($nWidth, $nHeight)
{
    var $nPageHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
    var $nPageWidth = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;

    var $nScrollBar = 25;

    var $fXBar = false;
    var $fYBar = false;

    var $nX = $nPageWidth;
    var $nY = $nPageHeight;
    if ( $nPageHeight < $nHeight )
    {
        $nX = $nPageWidth - $nScrollBar;
    }
    if ( $nX < $nWidth )
    {
        $nY = $nPageHeight - $nScrollBar;
        if ( $nY < $nHeight )
        {
            $nX = $nPageWidth - $nScrollBar;
        }
    }

    //alert($nPageWidth + "px wide window\n" + $nX + "px wide content\n\n" + $nPageHeight + "px high window\n" + $nY + "px high content");

    return $nX;
}

window.onload = pinchWidth;

